I have a docker container in a LUbuntu 15.10 host.
This container is using the openvpn client to connect to a VPN.ac account.
This is the script I'm running to restart the vpn connection if it's down:
#! /bin/bash
while true
do
sleep 60s
ps -ef | grep -v grep | grep "/usr/sbin/openvpn --cd /etc/openvpn --config /etc/openvpn/default.conf --redirect-gateway"
if [ $? -eq 1 ] ; then
sv restart openvpn
fi
done
The problem is that if the internet connection goes down, when it comes back up the script says it's unable to resolve the vpn server hostname and I have to restart the container.
Is there a better way to do this?
BTW the reason I'm grepping for the whole command statement is that I have another container acting as VPN server and if I just do "grep openvpn" then it does find the other service too.
Thanks.
P.S - Please see below the content of the OpenVPN config file.
remote nl1.vpn.ac 50000 udp
dev tun
tls-client
persist-tun
persist-key
nobind
pull
redirect-gateway def1
route-delay 3
auth-user-pass pw
keepalive 10 60
verb 3
explicit-exit-notify 2
remote-cert-tls server
setenv CLIENT_CERT 0
key-direction 1
cipher AES-256-CBC
auth SHA512
<ca>
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
</ca>
<tls-auth>
#
# 2048 bit OpenVPN static key
#
-----BEGIN OpenVPN Static key V1-----
-----END OpenVPN Static key V1-----
</tls-auth>
script-security 2
up update-resolv-conf.sh
down update-resolv-conf.sh
resolv-retry
directive somewhere?