Update vpnmon.sh

This commit is contained in:
2022-05-22 12:12:51 -05:00
parent 192346fdec
commit 0cc03a290b

View File

@@ -5,7 +5,8 @@ source /opt/idssys/defaults/colors.inc
source /opt/idssys/defaults/default.inc
source /opt/idssys/vpnmon/system.inc
logfile=/opt/idssys/vpnmon/logfile
touch $logfile
START(){
@@ -28,9 +29,15 @@ START(){
/usr/sbin/service unifi-poller start
fi
rm -f /opt/idssys/vpnmon/vpn.stop
echo "$(date) - VPN started" >> $logfile
}
STOP(){
touch /opt/idssys/vpnmon/vpn.stop
if [ "${SYSTEM}" = "unifipoller" ]; then
/usr/sbin/service unifi-poller stop
fi
@@ -38,9 +45,17 @@ STOP(){
sudo bash -c 'echo "d myVPN" > /var/run/xl2tpd/l2tp-control'
/usr/sbin/ipsec down L2TP-PSK
echo "$(date) - VPN stopped" >> $logfile
}
CHECK(){
if [ ! -f /opt/idssys/vpnmon/vpn.stop ]; then
touch /opt/idssys/vpnmon/vpn.stop
checked=false
cc=0
until [ "${checked}" = "" ]; do
@@ -49,14 +64,37 @@ CHECK(){
if [ ${#OUT} -ne 0 ]; then
checked=""
elif [ ${cc} -eq 10 ]; then
if [ -f /opt/idssys/vpnmon/vpn.fail ]; then
echo "$(date) - VPN Failure #2 - stopping for 5mins" >> $logfile
touch /opt/idssys/vpnmon/vpn.fail2
rm -f /opt/idssys/vpnmon/vpn.fail
STOP
sleep 5s
sleep 5m
START
exit 1
elif [ -f /opt/idssys/vpnmon/vpn.fail2 ]; then
echo "$(date) - VPN Failure #3 - Shutting down VPN system until repaired" >> $logfile
STOP
exit 1
else
echo "$(date) - VPN Failure #1 - stopping for 1min" >> $logfile
touch /opt/idssys/vpnmon/vpn.fail
STOP
sleep 1m
START
exit 1
fi
fi
((cc=${cc}+1))
sleep 1s
done
rm -f /opt/idssys/vpnmon/vpn.stop
else
echo "VPN system is stopped and must be restarted manually"
fi
}
case ${1} in