Executing script when re-establishing connection fails?

How to customize and extend your OpenVPN installation.

Moderators: TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech

Post Reply
nils.toedtmann
OpenVpn Newbie
Posts: 2
Joined: Wed May 23, 2012 1:37 pm

Executing script when re-establishing connection fails?

Post by nils.toedtmann » Wed May 23, 2012 1:43 pm

Hi, we are running OpenVPN and are very happy with it.

We wonder whether there is a possibility to tell a openvpn client this:
When the VPN connection times out ("Inactivity timeout") and cannot be re-established within X minutes, the execute script Y
Background: We have a 3G-router which like to lose its 3G-connection and is too dumb to re-establish it by itself. We have a script on the openvpn client which can reboot the 3G-router, and that works nicely. Now we only need to trigger it when the connection is lost.

User avatar
janjust
Forum Team
Posts: 2703
Joined: Fri Aug 20, 2010 2:57 pm
Location: Amsterdam
Contact:

Re: Executing script when re-establishing connection fails?

Post by janjust » Wed May 23, 2012 2:20 pm

wouldn't it be easier to do this in a wrapper script *around* openvpn e.g.

Code: Select all

while true
do
  openvpn --config <blah>
  if [ $? -ne 0 ]
  then
    reboot_3g_router
  else
    break
  fi
done
?

Alternatively you could try running a 'down' script, but this script is run just before openvpn quits, so the effect would be the same.

nils.toedtmann
OpenVpn Newbie
Posts: 2
Joined: Wed May 23, 2012 1:37 pm

Re: Executing script when re-establishing connection fails?

Post by nils.toedtmann » Thu May 24, 2012 1:43 pm

Hi Jan, thank you for the quick response.

Doesn't opnvpn usully try to re-establish a dead tunnel ("--ping-restart") instead of exiting? Works very reliable here! Is the " --up-restart" script triggered when this happens?

In order for an external wrapper to work i probably needed to configure the tunnel in "one-shot" mode ("--ping-exit"?), correct?

User avatar
janjust
Forum Team
Posts: 2703
Joined: Fri Aug 20, 2010 2:57 pm
Location: Amsterdam
Contact:

Re: Executing script when re-establishing connection fails?

Post by janjust » Fri May 25, 2012 8:01 am

'--ping-restart' will cause openvpn to automatically reconnect if the "other end" of the connection drops out; however, if the client itself decides to abort/stop then there is no automatic restart. This does not happen often but I've read posts from others who experience this problem.

As for the 'one-shot method' : yes, you'd have to use '--ping-exit'

Post Reply