I have written a script that checks if my remote (over openVPN connection) is still alive, available.
If I can't see any of the remove servers, reboot!
This works fine on a TP-Link TL-WR1043N/ND v2 running EDE Reboot SNAPSHOT r3979-226e194 / LuCI Master (git-17.109.24760-2eda14b) self compiled firmware
a self compiled firmware for my WRT1200AC, 3200ACM and 1900ACS same snapshot and actually 100% same settings however this also works, but after the 3rd reboot these linksys WRT routers boot from the alternative partition!
Why would rebooting 3 times using this script cause the alternative partition to be booted?
When I manually reboot 3 times it doesn't happen!
here's the script:
#!/bin/sh /etc/rc.common
#Sometimes routers for whatever reason need a reboot. This script is being used in combination with an openVPN and thus we implement the logic: "the moment routers/servers on
#other physical locations which are only accessible over the oVPN connection are not there anymore, then something must be wrong. Since we don't know what, we reboot and let the
#local router reinitialize"
START=92 #after oVPN(90) and ebtables (91)
#Domain Servers, all must be accessible at all times
ANDHOSTS='172.22.56.2 172.22.64.2 172.22.67.2'
BOOTDELAY=120 # Time to give all services to boot before we start probing
LOOPDELAY=180 # Time to delay between probes
PROBECOUNT=2 # Number of probes per PING
NRLOOPSTOREBOOT=3 # How many loops we have to go through with a broken Hosts before we actually reboot, NRLOOPSTOREBOOT * LOOPDELAY = Offline time for any server before reboot.
LOOPMAX=3 # Amount of retries each round of probes
FILE="/etc/monitorNetworkLog"
boot()
{
echo "$(date +"%d-%m-%Y-%T") - System Up" >> $FILE
echo "ProcessID: $$" >> $FILE
sleep $BOOTDELAY
LOOPCOUNT=0
while :
do
DOREBOOT=0
for myHost in $ANDHOSTS
do
count=$(ping -c $PROBECOUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
if [ $count -eq 0 ];
then
# at least one HOST is down and declared as AND, so reboot
echo "$(date +"%d-%m-%Y-%T") - $myHost is down" >> $FILE
DOREBOOT=1
fi
done
if [ $DOREBOOT -eq 0 ];
then
echo "$(date +"%d-%m-%Y-%T") - All VPN connections OK!" >> $FILE
LOOPCOUNT=0
sleep $LOOPDELAY
else
LOOPCOUNT=`expr $LOOPCOUNT + 1`
echo "$(date +"%d-%m-%Y-%T") - System Down: $LOOPCOUNT" >> $FILE
if [ $LOOPCOUNT -gt 3 ];
then
echo "$(date +"%d-%m-%Y-%T") - System Reboot" >> $FILE
reboot -d 30
kill -9 $$
break
fi
fi
done
}