From cb8b2671847ff3595728d724bb8774f831d299c7 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Thu, 5 Feb 2026 09:03:17 +0100 Subject: [PATCH 1/7] Implement logging for OpenVPN with configurable level Add logging functionality with configurable log level for OpenVPN. --- qbittorrent/rootfs/usr/local/sbin/vpn | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/qbittorrent/rootfs/usr/local/sbin/vpn b/qbittorrent/rootfs/usr/local/sbin/vpn index 2d2bd6290..ed8b29f4a 100755 --- a/qbittorrent/rootfs/usr/local/sbin/vpn +++ b/qbittorrent/rootfs/usr/local/sbin/vpn @@ -8,6 +8,7 @@ config["MySelf"]="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BA declare -a dns_servers_ipv4=() declare -a dns_servers_ipv6=() +LOG_LEVEL="$(bashio::config "log_level")" _parse_config() { local -n config_ref="$1" @@ -346,12 +347,20 @@ _openvpn_up() { echo "${config["MySelf"]} openvpn postdown" >> ${config["PostDownScript"]} chmod 755 ${config["PostDownScript"]} + # Define logging + LOG_PATH="/dev/null" + if [[ "$LOG_LEVEL" == "debug" ]]; then + bashio::log.warning "Starting openvpn in debug mode" + bashio::log.warning "------------------------------" + LOG_PATH="/proc/1/fd/1" + fi + # Start OpenVPN in the background _cmd "/usr/sbin/openvpn \ --config "${config["ConfigFile"]}" \ --client \ --daemon \ - --log /dev/null \ + --log "$LOG_PATH" \ --script-security 2 \ --auth-user-pass "${OPENVPN_STATE_DIR}/credentials.conf" \ --auth-retry none \ From 9cd110f4b9843022bdc2c65d348ac736231468ca Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Thu, 5 Feb 2026 09:17:47 +0100 Subject: [PATCH 2/7] lower case --- qbittorrent/rootfs/usr/local/sbin/vpn | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/qbittorrent/rootfs/usr/local/sbin/vpn b/qbittorrent/rootfs/usr/local/sbin/vpn index ed8b29f4a..bf20d4684 100755 --- a/qbittorrent/rootfs/usr/local/sbin/vpn +++ b/qbittorrent/rootfs/usr/local/sbin/vpn @@ -8,7 +8,7 @@ config["MySelf"]="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BA declare -a dns_servers_ipv4=() declare -a dns_servers_ipv6=() -LOG_LEVEL="$(bashio::config "log_level")" +log_level="$(bashio::config "log_level")" _parse_config() { local -n config_ref="$1" @@ -348,11 +348,11 @@ _openvpn_up() { chmod 755 ${config["PostDownScript"]} # Define logging - LOG_PATH="/dev/null" - if [[ "$LOG_LEVEL" == "debug" ]]; then + log_path="/dev/null" + if [[ "$log_level" == "debug" ]]; then bashio::log.warning "Starting openvpn in debug mode" bashio::log.warning "------------------------------" - LOG_PATH="/proc/1/fd/1" + log_path="/proc/1/fd/1" fi # Start OpenVPN in the background @@ -360,7 +360,7 @@ _openvpn_up() { --config "${config["ConfigFile"]}" \ --client \ --daemon \ - --log "$LOG_PATH" \ + --log "$log_path" \ --script-security 2 \ --auth-user-pass "${OPENVPN_STATE_DIR}/credentials.conf" \ --auth-retry none \ From 97615a1fade0c846125d7e4d1df1a6813e1f6e1c Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Thu, 5 Feb 2026 09:21:27 +0100 Subject: [PATCH 3/7] Add log level configuration and debug option --- qbittorrent/rootfs/usr/local/sbin/vpn | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qbittorrent/rootfs/usr/local/sbin/vpn b/qbittorrent/rootfs/usr/local/sbin/vpn index bf20d4684..b560587c0 100755 --- a/qbittorrent/rootfs/usr/local/sbin/vpn +++ b/qbittorrent/rootfs/usr/local/sbin/vpn @@ -8,7 +8,9 @@ config["MySelf"]="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BA declare -a dns_servers_ipv4=() declare -a dns_servers_ipv6=() + log_level="$(bashio::config "log_level")" +[[ "$log_level" == "debug" ]] && set -x _parse_config() { local -n config_ref="$1" From c01005d63a89f89860b124a693239f9389079b67 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Thu, 5 Feb 2026 09:22:55 +0100 Subject: [PATCH 4/7] Debug message Simplified debug logging setup for OpenVPN. --- qbittorrent/rootfs/usr/local/sbin/vpn | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/qbittorrent/rootfs/usr/local/sbin/vpn b/qbittorrent/rootfs/usr/local/sbin/vpn index b560587c0..4f81d9fff 100755 --- a/qbittorrent/rootfs/usr/local/sbin/vpn +++ b/qbittorrent/rootfs/usr/local/sbin/vpn @@ -11,6 +11,7 @@ declare -a dns_servers_ipv6=() log_level="$(bashio::config "log_level")" [[ "$log_level" == "debug" ]] && set -x +[[ "$log_level" == "debug" ]] && bashio::log.warning "--- Debug mode is active ---" _parse_config() { local -n config_ref="$1" @@ -351,11 +352,7 @@ _openvpn_up() { # Define logging log_path="/dev/null" - if [[ "$log_level" == "debug" ]]; then - bashio::log.warning "Starting openvpn in debug mode" - bashio::log.warning "------------------------------" - log_path="/proc/1/fd/1" - fi + [[ "$log_level" == "debug" ]] && log_path="/proc/1/fd/1" # Start OpenVPN in the background _cmd "/usr/sbin/openvpn \ From 1365ed148b2388bde02d16aeca73ed5b4a001d93 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Thu, 5 Feb 2026 09:26:35 +0100 Subject: [PATCH 5/7] Update vpn --- qbittorrent/rootfs/usr/local/sbin/vpn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qbittorrent/rootfs/usr/local/sbin/vpn b/qbittorrent/rootfs/usr/local/sbin/vpn index 4f81d9fff..62a9574a9 100755 --- a/qbittorrent/rootfs/usr/local/sbin/vpn +++ b/qbittorrent/rootfs/usr/local/sbin/vpn @@ -10,8 +10,8 @@ declare -a dns_servers_ipv4=() declare -a dns_servers_ipv6=() log_level="$(bashio::config "log_level")" -[[ "$log_level" == "debug" ]] && set -x [[ "$log_level" == "debug" ]] && bashio::log.warning "--- Debug mode is active ---" +[[ "$log_level" == "debug" ]] && set -x _parse_config() { local -n config_ref="$1" From 4f750ad75679578445aafb8c3fb5adbf03055bfa Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Thu, 5 Feb 2026 10:28:34 +0100 Subject: [PATCH 6/7] Propose to stop addon if openvpn script fails for logs clarity --- .../rootfs/etc/cont-init.d/93-openvpn.sh | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/qbittorrent/rootfs/etc/cont-init.d/93-openvpn.sh b/qbittorrent/rootfs/etc/cont-init.d/93-openvpn.sh index b82afb701..9f4016a4d 100755 --- a/qbittorrent/rootfs/etc/cont-init.d/93-openvpn.sh +++ b/qbittorrent/rootfs/etc/cont-init.d/93-openvpn.sh @@ -18,7 +18,8 @@ fi if ! bashio::config.true 'openvpn_enabled'; then bashio::exit.ok 'OpenVPN is disabled.' elif bashio::config.true 'wireguard_enabled'; then - bashio::exit.nok 'OpenVPN and WireGuard cannot be enabled simultaneously. Disable one of them.' + bashio::log.fatal 'OpenVPN and WireGuard cannot be enabled simultaneously. Disable one of them.' + bashio::addon.stop fi mkdir -p "${OPENVPN_STATE_DIR}" @@ -31,12 +32,14 @@ bashio::log.info "----------------------------" if bashio::config.has_value "openvpn_username"; then openvpn_username=$(bashio::config 'openvpn_username') else - bashio::exit.nok "Openvpn is enabled, but openvpn_username option is empty! Exiting" + bashio::log.fatal "Openvpn is enabled, but openvpn_username option is empty! Exiting" + bashio::addon.stop fi if bashio::config.has_value "openvpn_password"; then openvpn_password=$(bashio::config 'openvpn_password') else - bashio::exit.nok "Openvpn is enabled, but openvpn_password option is empty! Exiting" + bashio::log.fatal "Openvpn is enabled, but openvpn_password option is empty! Exiting" + bashio::addon.stop fi echo -e "${openvpn_username}\n${openvpn_password}" > "${OPENVPN_STATE_DIR}/credentials.conf" @@ -50,7 +53,8 @@ if [[ -z "${openvpn_config}" ]]; then bashio::log.info 'openvpn_config option left empty. Attempting automatic selection.' mapfile -t configs < <(find /config/openvpn -maxdepth 1 \( -type f -name '*.conf' -o -name '*.ovpn' \) -print) if [ "${#configs[@]}" -eq 0 ]; then - bashio::exit.nok 'OpenVPN is enabled but no .conf or .ovpn file was found in /config/openvpn.' + bashio::log.fatal 'OpenVPN is enabled but no .conf or .ovpn file was found in /config/openvpn.' + bashio::addon.stop elif [ "${#configs[@]}" -eq 1 ]; then openvpn_config="${configs[0]}" bashio::log.info "OpenVPN configuration not specified. Using ${openvpn_config##*/}." @@ -58,17 +62,20 @@ if [[ -z "${openvpn_config}" ]]; then openvpn_config='/config/openvpn/config.conf' bashio::log.info 'Using default OpenVPN configuration config.conf.' else - bashio::exit.nok "Multiple OpenVPN configuration files detected. Please set the 'openvpn_config' option." + bashio::log.fatal "Multiple OpenVPN configuration files detected. Please set the 'openvpn_config' option." + bashio::addon.stop fi elif bashio::fs.file_exists "/config/openvpn/${openvpn_config}"; then openvpn_config="/config/openvpn/${openvpn_config}" else - bashio::exit.nok "OpenVPN configuration '/config/openvpn/${openvpn_config}' not found." + bashio::log.fatal "OpenVPN configuration '/config/openvpn/${openvpn_config}' not found." + bashio::addon.stop fi interface_name="$(sed -n "/^dev tun/p" "${openvpn_config}" | awk -F' ' '{print $2}')" if [[ -z "${interface_name}" ]]; then - bashio::exit.nok "OpenVPN configuration '${openvpn_config}' misses device directive." + bashio::log.fatal "OpenVPN configuration '${openvpn_config}' misses device directive." + bashio::addon.stop elif [[ ${interface_name} = "tun" ]]; then interface_name='tun0' elif [[ ${interface_name} = "tap" ]]; then From 7d45a36ee6d5fe551eb11b3f274d8154756b7e92 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Thu, 5 Feb 2026 10:29:27 +0100 Subject: [PATCH 7/7] Stop addon if exit nok --- qbittorrent/rootfs/etc/cont-init.d/94-wireguard.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/qbittorrent/rootfs/etc/cont-init.d/94-wireguard.sh b/qbittorrent/rootfs/etc/cont-init.d/94-wireguard.sh index 3afa12619..bc622068a 100755 --- a/qbittorrent/rootfs/etc/cont-init.d/94-wireguard.sh +++ b/qbittorrent/rootfs/etc/cont-init.d/94-wireguard.sh @@ -16,7 +16,8 @@ fi if ! bashio::config.true 'wireguard_enabled'; then bashio::exit.ok 'WireGuard is disabled.' elif bashio::config.true 'openvpn_enabled'; then - bashio::exit.nok 'OpenVPN and WireGuard cannot be enabled simultaneously. Disable one of them.' + bashio::log.fatal 'OpenVPN and WireGuard cannot be enabled simultaneously. Disable one of them.' + bashio::addon.stop fi mkdir -p "${WIREGUARD_STATE_DIR}" @@ -33,7 +34,8 @@ if [[ -z "${wireguard_config}" ]]; then bashio::log.info 'wireguard_config option left empty. Attempting automatic selection.' mapfile -t configs < <(find /config/wireguard -maxdepth 1 -type f -name '*.conf' -print) if [ "${#configs[@]}" -eq 0 ]; then - bashio::exit.nok 'WireGuard is enabled but no .conf file was found in /config/wireguard.' + bashio::log.fatal 'WireGuard is enabled but no .conf file was found in /config/wireguard.' + bashio::addon.stop elif [ "${#configs[@]}" -eq 1 ]; then wireguard_config="${configs[0]}" bashio::log.info "WireGuard configuration not specified. Using ${wireguard_config##*/}." @@ -41,12 +43,14 @@ if [[ -z "${wireguard_config}" ]]; then wireguard_config='/config/wireguard/config.conf' bashio::log.info 'Using default WireGuard configuration config.conf.' else - bashio::exit.nok "Multiple WireGuard configuration files detected. Please set the 'wireguard_config' option." + bashio::log.fatal "Multiple WireGuard configuration files detected. Please set the 'wireguard_config' option." + bashio::addon.stop fi elif bashio::fs.file_exists "/config/wireguard/${wireguard_config}"; then wireguard_config="/config/wireguard/${wireguard_config}" else - bashio::exit.nok "WireGuard configuration '/config/wireguard/${wireguard_config}' not found." + bashio::log.fatal "WireGuard configuration '/config/wireguard/${wireguard_config}' not found." + bashio::addon.stop fi interface_name="$(basename "${wireguard_config}" .conf)"