overhaul cont-init vpn scripts

This commit is contained in:
litinoveweedle
2026-01-27 12:15:16 +01:00
parent b001f1ebca
commit 80f7efb013
2 changed files with 17 additions and 15 deletions

View File

@@ -129,7 +129,6 @@ schema:
keyfile: str keyfile: str
localdisks: str? localdisks: str?
networkdisks: str? networkdisks: str?
openvpn_alt_mode: bool?
openvpn_config: match(^\w+\.(ovpn|conf)$)? openvpn_config: match(^\w+\.(ovpn|conf)$)?
openvpn_enabled: bool? openvpn_enabled: bool?
openvpn_password: str? openvpn_password: str?

View File

@@ -322,26 +322,26 @@ _openvpn_up() {
bashio::log.warning "Qbittorrent bittorrent client shall be set to use the VPN interface ${config["Interface"]} only." bashio::log.warning "Qbittorrent bittorrent client shall be set to use the VPN interface ${config["Interface"]} only."
# Register this script as OpenVPN up/down handlers to manage routing # Register this script as OpenVPN up/down handlers to manage routing
echo "${config["MySelf"]} openvpn postup" > ${config["PostUpScript"]} echo '#!/bin/bash' > ${config["PostUpScript"]}
echo "${config["MySelf"]} openvpn postup" >> ${config["PostUpScript"]}
chmod 755 ${config["PostUpScript"]} chmod 755 ${config["PostUpScript"]}
echo "${config["MySelf"]} openvpn postdown" > ${config["PostDownScript"]} echo '#!/bin/bash' > ${config["PostDownScript"]}
echo "${config["MySelf"]} openvpn postdown" >> ${config["PostDownScript"]}
chmod 755 ${config["PostDownScript"]} chmod 755 ${config["PostDownScript"]}
# Start OpenVPN in the background # Start OpenVPN in the background
# (maybe use setsid instead of nohup to detach completely?) _cmd "/usr/sbin/openvpn
nohup /usr/sbin/openvpn \
--config "${config["ConfigFile"]}" \ --config "${config["ConfigFile"]}" \
--script-security 2 \ --script-security 2 --daemon --log /dev/null \
--auth-user-pass "${OPENVPN_STATE_DIR}/credentials.conf" \
--auth-retry none \
--up ${config["PostUpScript"]} \ --up ${config["PostUpScript"]} \
--up_delay 5 \
--down ${config["PostDownScript"]} \ --down ${config["PostDownScript"]} \
--down-delay 5 \
--up-restart \
--route-nopull \ --route-nopull \
--pull-filter ignore "route" \ --route-noexec" || return 1
--pull-filter ignore "redirect-gateway" \
--pull-filter ignore "dhcp-option DNS" \
--pull-filter ignore "route-ipv6" \
--pull-filter ignore "redirect-gateway ipv6" \
--pull-filter ignore "dhcp-option DNS6" \
&
} }
_openvpn_down() { _openvpn_down() {
@@ -383,8 +383,11 @@ openvpn() {
if [ "${mode}" = "up" ]; then if [ "${mode}" = "up" ]; then
# register up and down scripts # register up and down scripts
bashio::log.info "Starting OpenVPN on interface ${config["Interface"]}..." bashio::log.info "Starting OpenVPN on interface ${config["Interface"]}..."
_openvpn_up if _openvpn_up; then
bashio::exit.ok 'OpenVPN started.' bashio::exit.ok 'OpenVPN started.'
fi
bashio::log.error 'OpenVPN failed to establish connection.'
_openvpn_down
elif [ "${mode}" = "down" ]; then elif [ "${mode}" = "down" ]; then
bashio::log.info "Stopping OpenVPN on interface ${config["Interface"]}..." bashio::log.info "Stopping OpenVPN on interface ${config["Interface"]}..."
_openvpn_down _openvpn_down