I need a Connection Watchdog/Keep Alive scheduler command or custom script.

Discussion in 'Tomato Firmware' started by ScaryFast, Jun 30, 2008.

  1. ScaryFast

    ScaryFast Network Guru Member


    I set up the network at a campground with 5 Linksys WRT54G/GL routers, various Wifi antennas, and for the past 2 years they ran DD-WRT which does exactly this and works great.

    I want to switch to Tomato but the biggest thing I'll miss about DD-WRT is the connection watchdog. While it's quite possible that Tomato will be more stable and I won't NEED a connection watchdog, I sure would feel better if I had one.

    I accidentally left the main routers connection watchdog disabled this spring and in the past week they've had to reboot it manually once each day even though it reboots automatically every morning at 4am. The other routers, which did have the watchdog on, were rebooting on their own but since the main one did not, it did no good. Since enabling the watchdog again the other day I've seen it reboot once on its own, along with the others, and no one has complained about the internet not working.

    Every few days I sit down intending to google the hell out of the problem and get it solved but I haven't had any luck so far.

    I'm pretty sure the watchdog just pings set IP's at set intervals and reboots, which is fine, but I wonder if there's something that can make them try 2 or 3 times before rebooting, just to avoid unnecessary reboots.

    I thought of putting Tomato on the other routers and leaving DD-WRT on the main router (DHCP server) but I want Tomato for the awesome QoS. Every depressing! :p

    Thanks all.

    /edit In a somewhat related story... in DD-WRT it would show the rate at which a Client Bridge(Wireless Ethernet Bridge in Tomato) was connected to an AP at. I could see it jump around, 24mbit, 5.5mbit, 1mbit, etc.

    I'm playing with the Wireless Ethernet Bridge option in Tomato, and see that it shows no such thing. This bothers me. Should it? :p

    I think the rate dipping into the 1 and 2mbit range is what prompted me to buy 2 circular polarized non-line of site panel antennas because a single Yagi pointed at a big omni 400 feet away through a small hole in trees wasn't cutting it.
  2. ScaryFast

    ScaryFast Network Guru Member

    I enabled a scheduled event for 23:00 that simply says reboot, and it rebooted at 11pm as expected, which means the commands are probably fairly simple, but still beyond my knowledge. I'm sure if I had some linux background I could figure it out...

    At least now I know I could, if I wanted, make it reboot at midnight with the dedicated Reboot option, and also at noon.
  3. ScaryFast

    ScaryFast Network Guru Member

    I still need a way for these Tomato using routers to ping each other and reboot when they stop responding! :p
  4. TexasFlood

    TexasFlood Network Guru Member

    Try running the script below in cron however often you want, replace "" with the IP address of the router on the other end of the WDS link. If three consecutive ping attempts to the listed IP address fail, it will reboot the router. You can easily adjust the number of attempts if you'd like.

    while ( ( /bin/ping -c 1 | grep -q '100% packet loss' ) && \
     [ $ping_attempt -lt '3' ] )
     ping_attempt=`expr $ping_attempt + 1`
     /bin/sleep 1
     if [ $ping_attempt = 3 ] ; then
    philess likes this.
  5. azeari

    azeari LI Guru Member

    u might wanna add another do-while loop to ping other routers in the chain to make sure you're not pinging a bad router and reboot as a result
  6. TexasFlood

    TexasFlood Network Guru Member

    This script will only reboot if the 1st, 2nd -and- 3rd pings all fail.

    Each ping probably takes less than a second to succeed and about 10 seconds to time out & fail. So you can estimate how long a given test will take to fail, about 30 seconds for the 3 pings.

    I decided to test this on my routers for a while just for the heck of it. Honestly with WPA PSK + AES, Tomato WDS has been so reliable for me, I probably don't need it but guess it's a good thing to have in a bag of tricks.

    So the following is what I have in my Init script section testing now & it seems to work fine. I just added to the above script a couple of statements and characters to copy the script to a file, change the file permissions to executable, and schedule a cron job to run the script every 5 minutes. Just change the IP address to that of the router to ping on the other side of the WDS link. Again, the number of pings as well as the run time interval is easily adjustable, just ask if you have any questions as to how to make these changes.

    cat <<END > /tmp/keepalive.sh
    while ( ( /bin/ping -c 1 | /bin/grep -q '100% packet loss' ) && \
     [ \$ping_attempt -lt '3' ] )
     ping_attempt=\`expr \$ping_attempt + 1\`
     /bin/sleep 1
     if [ \$ping_attempt = 3 ] ; then
    chmod 755 /tmp/keepalive.sh
    cru a KeepAliveScript "*/5 * * * * /tmp/keepalive.sh >/dev/null 2>&1"
    I only have the two routers right now so this is really all I need. I might give some thought to if one of my routers fails, do I really want the other router rebooting every 5 mins or perhaps give up after a while. I could save a value in NVRAM so it would survive reboots and clear the script from NVRAM if the router was rebooting too frequently.

    There are a lot of possibilities but seems like it would help to know the topology and desired behavior. Heck, I'm lucky to get a simple script to work. Simple is good, the KISS principle! If you have any suggestions for improvement, feel free to post it. If it's cool, maybe I'll steal it and use it myself, :biggrin:
  7. scaredwitless

    scaredwitless Network Guru Member

    I would suggest the script in the third post down on this thread:

    on the gateway router. It works beautifully and will ping a external address you set, if the first ping fails it trys again. If it fails the second time, it trys to renew the external IP lease.

    Then you could modify it for the other routers to ping the gateway and if the ping fails twice, modify it to reboot the router or whatever you like.

    Course with that said, I think this would be mostly for redundancy/peace of mind, Tomatos rather stable. The gateway watchdog will be the most useful as it will smooth out (hopefully) any instability with your net connection.

    Excellent script, I use it on my gateway router with some tiny modifications to make it more verbose in the event logs.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice