Edgemax connectivity check

At home we use the EdgeMax EdgeRouter as my primary router connected to gigabit fiber. I'm generally very happy with this device and the internet connectivity as both have been reliable. I have had one occasion on which the Centurylink PPPoE link was dropped and did not automatically recover although a router reboot did successfully reestablish the connection. This script automates that "troubleshooting" step which is impossible from a remote site.

The script is fairly simple, it sends a couple of ping requests off to some reliable DNS servers and if any of them reply, peacefully exits. If none of the pings receive a reply, a reboot is triggered. A file is used as a primitive form of reboot protection; the script will not run

#!/bin/bash

# check Google DNS, followed by Level3, then Centurylink. If none work, reboot.

PROTECTION="/var/run/ping-watchdog"

if [ -e $PROTECTION ] && [ `cat $PROTECTION` = 0 ] ; then
        /bin/ping -c2 8.8.8.8 > /dev/null 2>&1
        if [ $? -ne 0 ] ; then
                /bin/ping -c2 4.2.2.2 > /dev/null 2>&1
                if [ $? -ne 0 ] ; then
                        /bin/ping -c2  205.171.3.65 > /dev/null 2>&1
                        if [ $? -ne 0 ] ; then
                                echo "1" > /var/run/ping-watchdog
                                logger -t ping-watchdog "All pings failed. Rebooting..."
                                /sbin/reboot
                        fi
                fi
        else
                logger -t ping-watchdog "Connectivity working. Nothing to do."
        fi
else
        logger -t ping-watchdog "Reboot protection in place. Waiting."
fi

Finally there are two cron tasks in place to keep this running. The first resets the reboot protection every thirty minutes. The second makes the test every two minutes.

These are configured through the config.boot file declaratively to persist reboots and firmware upgrades. The EdgeMax OS handles translating these into actual cron tasks.

task-scheduler {
  task ping-watchdog-reset {
    executable {
      path /bin/bash
      arguments "-c 'echo 0 > /var/run/ping-watchdog'"
    }
    interval 30m
  }

  task ping-watchdog {
    executable {
      path /config/ping-watchdog
    }
    interval 2m
  }
}

No further issues to report!