Skip to content

Commit

Permalink
Update app/openvpn.sh with better openvpn failure detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Fullaxx committed Dec 8, 2020
1 parent a39e56e commit eac7dc2
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions app/openvpn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,30 @@ bail()
OVPNSLEEPTIME=${OVPNSLEEPTIME:-6}
CONFIGFILE="/rtorrent/config/${OVPNCFG}"

rm -f /var/log/openvpn/openvpn.log

if [ ! -r ${CONFIGFILE} ]; then bail "${CONFIGFILE} not available!"; fi
openvpn --config ${CONFIGFILE} --daemon --script-security 2 \
--log /var/log/openvpn/openvpn.log --up /app/up.sh --down /app/down.sh

OVPID=`pgrep openvpn`
echo "Sleeping ${OVPNSLEEPTIME}s while we wait for openvpn to settle ..."
sleep ${OVPNSLEEPTIME}

if grep -q 'ERROR: Cannot open TUN/TAP dev /dev/net/tun' /var/log/openvpn/openvpn.log; then
tail -n 2 /var/log/openvpn/openvpn.log
bail "Could not enable TUN device! Validate docker run options: --cap-add=NET_ADMIN --device /dev/net/tun"
fi

if grep -q 'Exiting due to fatal error' /var/log/openvpn/openvpn.log; then
tail -n 10 /var/log/openvpn/openvpn.log
bail "openvpn is not running!"
fi

OVPID=`ps aux | grep -w openvpn | grep ${CONFIGFILE} | awk '{print $2}'`
if [ x"${OVPID}" == "x" ]; then
tail -n 10 /var/log/openvpn/openvpn.log
bail "openvpn is not running!"
fi

echo "Sleeping ${OVPNSLEEPTIME}s while we wait for openvpn to settle ..."
sleep ${OVPNSLEEPTIME}
# Only necessary when we have a non-root user
# chmod 0644 /var/log/openvpn/openvpn.log

0 comments on commit eac7dc2

Please sign in to comment.