What's new

VPN Failover script

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Yes and No :) ,
the answer is clear but it doesn´t solve my problem, because every instance of the VPNFailoverscript would be killed by the command.

I was hoping, it would be possible to have a specific command for each instance of the vpnfailoverscript, which can be used in a openvpnX-down event.
e.g. I use the VPNfailoverscript e.g. for VPN1 to force to reconnect if the speed drops down - works. But what happens if I decide to manually turn off the vpn1 connection? In that case the vpnfailoverscript would reestablish the connection wouldn´t it ? So a manual turn off is not possible - right??
If you specify the VPN Client instance, then the 'reset' request should only apply to the target VPN client rather than ALL of them.

As shown here, the VPN trigger-event pair should cleanly terminate its monitoring.
(VPN_Failover.sh will gracefully self-terminate if its semaphore control file does not exist - i.e. the 'reset' command simply deletes the file)

vpnclientX-up

Code:
VPN_ID=${dev:4:1}

Say "Requesting VPN Failover monitor with 2 min delay....."
/jffs/scripts/VPN_Failover.sh "$VPN_ID" "delay=120" "ignore=2,3,4,5" "verbose" "interval=1200" &

vpnclientX-route-pre-down

Code:
VPN_ID=${dev:4:1}

MOUNT="/tmp"

VPNFAILOVER="/tmp/vpnclient"$VPN_ID"-VPNFailover"

# Also rely on the VPN_Failover.sh to test for the existence of the VPNFailover semaphore BEFORE it attempts a restart!
if [ -z "$(grep "NOKILL" $VPNFAILOVER)" ];then
    PID=$(cat $VPNFAILOVER)
    [ "$PID" != "NOKILL" ] && kill $PID
    rm $VPNFAILOVER
    logger -st "($(basename $0))" $$ "VPN Failover Monitor self-destruct requested....." $VPNFAILOVER "RC="$?
fi

By the way : Did you find an explanation or a solution for the error I described earlier (#67) ?

Perhaps try v1.24 hosted on my Github 'dev' branch
 
Last edited:
If you specify the VPN Client instance, then the 'reset' request should only apply to the target VPN client rather than ALL of them.

As shown here, the VPN trigger-event pair should cleanly terminate its monitoring.
(VPN_Failover.sh will gracefully self-terminate if its semaphore control file does not exist - i.e. the 'reset' command simply deletes the file)

vpnclientX-up

Code:
VPN_ID=${dev:4:1}

Say "Requesting VPN Failover monitor with 2 min delay....."
/jffs/scripts/VPN_Failover.sh "$VPN_ID" "delay=120" "ignore=2,3,4,5" "verbose" "interval=1200" &

vpnclientX-route-pre-down

Code:
VPN_ID=${dev:4:1}

MOUNT="/tmp"

VPNFAILOVER="/tmp/vpnclient"$VPN_ID"-VPNFailover"

# Also rely on the VPN_Failover.sh to test for the existence of the VPNFailover semaphore BEFORE it attempts a restart!
if [ -z "$(grep "NOKILL" $VPNFAILOVER)" ];then
    PID=$(cat $VPNFAILOVER)
    [ "$PID" != "NOKILL" ] && kill $PID
    rm $VPNFAILOVER
    logger -st "($(basename $0))" $$ "VPN Failover Monitor self-destruct requested....." $VPNFAILOVER "RC="$?
fi



Perhaps try v1.24 hosted on my Github 'dev' branch
Thanks a lot again for your support. I will test it.
One further question regarding your code.
Is VPN_ID=${dev:4:1} universal usable for all vpnclients (1-5) or does I have to change it for each client (e.g. vpn2 =VPN_ID=${dev:4:2} ???)
Sorry I am not a programmer :).......
 
Is VPN_ID=${dev:4:1} universal usable for all vpnclients (1-5) or does I have to change it for each client (e.g. vpn2 =VPN_ID=${dev:4:2} ???)
The code is universal and can simply be cloned as-is using copy'n'pasted into any vpnclientX* trigger-event script.

'dev' is an OpenVPN Environmental Variable that is exposed/passed to the scripts during execution and contains the actual physical interface name used by the current VPN Client /Server instance

e.g. 'tun11' for VPN Client 1, or 'tun15' for VPN Client 5 etc.

so the script(s) can always identify ($VPN_ID) which unique VPN Client has invoked it.
 
The code is universal and can simply be cloned as-is using copy'n'pasted into any vpnclientX* trigger-event script.

'dev' is an OpenVPN Environmental Variable that is exposed/passed to the scripts during execution and contains the actual physical interface name used by the current VPN Client /Server instance

e.g. 'tun11' for VPN Client 1, or 'tun15' for VPN Client 5 etc.

so the script(s) can always identify ($VPN_ID) which unique VPN Client has invoked it.
Thanks a lot.
I have made the changes. I will test.
With the 1.24er Version I don't get the error.
Thanks again.
 

Similar threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!

Members online

Top