Watching the dog (the Pi watchdog process)

If the Pi is going to be running unattended for a period of time, it’s important to have it automatically “fix” itself if something goes wrong. The chip that runs the Pi has a “watchdog” that can reboot the Pi if it determines that the computer has hung (or if other conditions are met). There are several blogs that explain how to set this up, but none of them get it completely right. I’ve finally gotten it to work, including doing the “fork-bomb” panic test. The several sites that have information on the watchdog are,

They all seem to miss an important “sudo” at the right place. Here’s what I did which seemed to work well.

sudo modprobe bcm2708_wdog
sudo vi /etc/modules  # Add line bcm2708_wdog
apt-get install watchdog chkconfig
sudo chkconfig watchdog on
sudo /etc/init.d/watchdog start
sudo vi /etc/watchdog.conf  # uncomment lines with "watchdog-device"
                            # and "max-load-1 = 24"
sudo /etc/init.d/watchdog restart

You should now be protected. There is a “watchdog daemon” that sends a signal to /dev/watchdog every ten seconds. A reboot is triggered if this file does not receive the “heartbeat”, indicating that your Pi is hung.

There are some situations where the Pi will be unresponsive, but the heartbeat may still occur. Uncommenting the max-load-1 line means that if your one minute load average exceeds 24, then the Pi will reboot. A load average of 24 means that the Pi is abnormally busy and should never be reached in normal operation. Indeed, while running the Pi with XBMC showing a Youtube video, the one minute load average never broke 2.

You can test the watchdog with a “fork-bomb”. You need to turn off the swap space first and make sure nothing critical is going on. Turn off swap with swapoff -a. Then issue this strange looking command

# DANGER - this will crash your Pi
:(){ :|:& };:

After 10 seconds the Pi should reboot. Pretty neat!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: