scripts/secours/check-vpn-from-ovh
Michel Blockelet 4b01f6acf3 [check-vpn-from-ovh] Meilleure logique
Ignore-this: c8801b67230ec5f1c9da4d746a3913c0
vpn en route ne signifie pas toujours que komaz.adm ping bien (surtout quand
les deux tunnels sont lances), on va voir si ca arrange les choses

darcs-hash:20120412065733-ddb99-382fc5e1858c7d57795406628413affb9f43a990.gz
2012-04-12 08:57:33 +02:00

60 lines
1.6 KiB
Bash

#!/bin/bash
vpn_is_running () {
local pid_file
pid_file=/var/run/openvpn.$1.pid
if [ -f $pid_file ] && [ -d /proc/$(< $pid_file) ]
then return 0
else return 1
fi
}
vpn_start () {
vpn_is_running $1 && exit 0
# On n'envoie un mail que toutes les 5 minutes
if ! [ -f /tmp/vpn_mail_sent ] || [ $((`date +%s` - `stat -c %X /tmp/vpn_mail_sent`)) -gt 300 ]
then
touch /tmp/vpn_mail_sent
# On utilise restart pour être sûr de ne pas avec de VPN qui traîne
if /etc/init.d/openvpn restart $1
then
echo "Lancement du vpn $(hostname)<->$1 reussi "'!'
exit 0
else
echo "Echec de lancement du vpn $(hostname)<->$1 "'!'
exit 1
fi
else
/etc/init.d/openvpn restart $1 &> /dev/null
fi
}
if vpn_is_running komaz && fping -q komaz.adm.crans.org; then
# Le vpn vers komaz est actif, tout va bien
exit 0
fi
if fping -q komaz.crans.org; then
# Si on peut atteindre komaz, on repasse par komaz
if vpn_is_running freebox
then
if ! [ -f /tmp/vpn_mail_sent ] || [ $((`date +%s` - `stat -c %X /tmp/vpn_mail_sent`)) -gt 300 ]
then
/etc/init.d/openvpn stop freebox
else
/etc/init.d/openvpn stop freebox &> /dev/null
fi
fi
vpn_start komaz
fi
if vpn_is_running freebox && fping -q komaz.adm.crans.org; then
# On ne peut pas atteindre komaz et on passe par la freebox, c'est
# normal
exit 0
fi
if fping -q freebox.crans.org; then
# On tente de passer par la freebox
vpn_start freebox
fi