New Member
Posts: 5
Registered: ‎05-28-2014
Solutions: 1

Edgeroute auto reboot on wan failure

Hi I have and edgerouter that had a WAN failure the other day that was fixed by a reboot and I wanted to know if there is a way to monitor packet loss and reboot after X losses?

 

Seems easy enough.

Veteran Member
Posts: 7,958
Registered: ‎03-24-2016
Kudos: 2076
Solutions: 912

Re: Edgeroute auto reboot on wan failure

Easy enough.

Schedule a cron job that runs every 5 minutes.

This jobs executes pings to some known good hosts , like  both of your ISP DNS servers.

If both ping fails , sleep 10 seconds , retry, else exit

If both ping fails , sleep 10 seconds , retry, else exit

If both ping fails , sleep 10 seconds , retry, else exit

If both ping fails , sleep 10 seconds , issue reboot command

Deleted Account
Posts: 0

Re: Edgeroute auto reboot on wan failure

[ Edited ]

You could adapt the vpncheck script here

 

https://community.ubnt.com/t5/EdgeMAX/ERLite-Auto-Restart-VPN/m-p/1147144/highlight/true#M52923

 

For the script itself something like

 

#!/bin/bash

/bin/ping -c 1 -W 2 8.8.8.8 1>/dev/null 2>&1  

if [ $? -ne 0 ]; then
        echo "Failed"
        /bin/vbash -ic 'sudo shutdown -r now'
fi

might work.  I haven't tested it though.  I was thinking of just putting 'reboot' as the command but you have to push enter again to confirm so I'm not sure how to script that.

 

edit: basicaly this is what @16again said, except I think this script just sends one ping with a timeout of 2 seconds.  It probably would be smart to have it wait until a few pings fail before rebooting the router.