Soon I'm going for holidays and leave my Pi on its own. Thus, I made some precautions in case it froze (though after almost a month with it, I never had such a problem, but never say never). I've found a great tool, that would reboot my machine after it suddenly froze for any reason. This would soothe my nerves in case I wasn't able to access my device and was wondering what might have happened (I'm not afraid the power might fail; not unless there was a nuclear war or a nasty sun burst that would destroy all electrical equipment - than we would be doomed and there would be no reason to worry about a small Pi).
The on-board timer
A watchdog timer is commonly found on embedded systems and is used to detect when the system is hung up on a task. Watchdog timer is basically a countdown timer counting from some initial value down to zero. When zero is reached, the watchdog understands that the system has hung up and resets it automatically.
Thankfully, the Raspberry Pi's BCM2835 SoC has a hardware-based watchdog timer on board. It is specially useful if you have a Raspberry Pi in a remote location (or a headless Pi) and the operating system hangs and there's no one around to reboot it. How to enable the watchdog timer?
First, install the watchdog:
sudo apt-get install watchdog
Load it and add it if necessary to your modules-configuration for loading it at startup:
sudo modprobe bcm2708_wdog
sudo nano /etc/modules
Where you add line
Or, a faster way:
echo "bcm2708_wdog" | sudo tee -a /etc/modules
Next, make sure it runs after every boot:
sudo update-rc.d watchdog defaults
sudo chkconfig --add watchdog
Configuring watchdog daemon
After installation, comes configuration. To configure watchdog daemon, edit /etc/watchdog.conf file:
sudo nano /etc/watchdog.conf
Uncomment the line that starts with
#watchdog-device by removing the hash (
#) to enable the watchdog daemon to use the watchdog device.
Uncomment the line that says
#max-load-1 = 24 by removing the hash symbol to reboot the device if the load goes over 24 over 1 minute. A load of 25 of one minute means that you would have needed 25 Raspberry Pi to complete that task in 1 minute. You may tweak this value to your liking.
Finally, we start the watchdog daemon:
sudo chkconfig watchdog on
sudo /etc/init.d/watchdog start
And that's it! You may sleep well and relax, as your Pi will automatically reboot in case of seizure!