Thursday, January 17, 2013

Auto-reboot a hung Raspberry Pi using the on-board watchdog timer

A watchdog timer is a special kind of timer commonly found on embedded systems that is used to detect when the running software is hung up on some task. The watchdog timer is basically a countdown timer that counts from some initial value down to zero. When zero is reached, the watchdog timer understands that the system is hung up and resets it. Therefore, the running software must periodically update the watchdog timer with a new value to stop it from reaching zero and causing a reset. When the running software is locked up doing a certain task and cannot update the watchdog timer, the timer will inevitably reach zero and a reset will occur.

Luckily for us, the Broadcom BCM2835 SoC on the Raspberry Pi comes with a hardware-based watchdog timer that can do just that. You will find this specially useful if you have a Raspberry Pi in a remote location and the operating system hangs and there's no one around to reboot it.

Load the bcm2708_wdog kernel module

To load the watchdog kernel module right now, issue the following command:
$ sudo modprobe bcm2708_wdog

If you are running Raspbian, to load the module the next time the system boots, add a line to your /etc/modules file with "bcm2708_wdog". The -a option makes sure tee appends instead.
$ echo "bcm2708_wdog" | sudo tee -a /etc/modules

If you are running Arch Linux, add a file called "bcm2708_wdog.conf" with the text "bcm2708_wdog" in /etc/modules-load.d/ with the following command:
$ echo "bcm2708_wdog" | sudo tee /etc/modules-load.d/bcm2708_wdog.conf

Install the software watchdog daemon

In Raspbian, run the following command:
$ sudo apt-get install watchdog
But in Arch we use pacman:
$ sudo pacman -S watchdog

Then, make sure it runs after every boot.
In Raspbian, run:
$ sudo update-rc.d watchdog defaults
$ sudo chkconfig --add watchdog
In Arch run the following:
$ sudo systemctl enable watchdog

Configure the watchdog daemon

Open /etc/watchdog.conf with your favorite editor (mine is nano).
$ 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 Pis to complete that task in 1 minute. You may tweak this value to your liking.

Start the watchdog daemon

In Raspbian:
$ sudo chkconfig watchdog on
$ sudo /etc/init.d/watchdog start

In Arch:
$ sudo systemctl start watchdog.service

That's it!

You are done! You may play around with the settings in /etc/watchdog.conf if you'd like.
The watchdog daemon performs other tests that you will probably want to configure.

Arch Linux users: I'm well aware that the watchdog daemon is not necessary in Arch because you can enable watchdog features with systemd by editing /etc/systemd/system.conf but I prefer the watchdog daemon as it is much more featured.

2013-01-17 11:45 AM EST: Fixed the chkconfig command to start and enable the watchdog daemon at startup.

Source: Raspberry Pi @ Gadgetoid


  1. It's important to mention that the hardware watchdog timeout is 16 seconds, so you must set your heartbeat interval to something less than that. This is assuming that this post is correct.

  2. Wonderful blog! I found it while surfing around on Yahoo News. Do you have any suggestions on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Appreciate it.

  3. Hello I am so delighted I located your blog, I really located you by mistake, while I was watching on google for something else, Anyways I am here now and could just like to say thank for a tremendous post and a all round entertaining website. Please do keep up the great work. auto repair near me

  4. I needed to thank you for this phenomenal read!! I unquestionably adored each and every piece of it. I have you bookmarked your site to look at the new stuff you post. auto hail repair denver

  5. When you use a genuine service, you will be able to provide instructions, share materials and choose the formatting style. auto reply text

  6. This is a good post. This post gives truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. Thank you so much. Keep up the good works. purchase travel insurance - third party car insurance

  7. Rafting in Vjosa river in Albania is a wonderful experience. Vjosa is the most wild river of Europe so is definitely something worth trying. Travel Albania

  8. PTCL is Pakistan's 1st Telecommunication company. People usually face problem in Changing PTCL Wifi Password which is not an issue it can simply be changed by signing in to your PTCL account. PTCL has also launched Latest Packages

  9. This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post. Bus Rental Dubai | van rental Dubai

  10. Great article, really happy from your work..keep it up Good Luck Roadside Assistance Pakistan

  11. i am browsing this website dailly , and get nice facts from here all the time .

  12. I hear a lot about watchdog timer, many people suggests it as one of the best tool to monitor the performance of a software. To be safe and feel secure we should always have a auto car insurance policy to help out in tough situations.

  13. That's a really informative post

  14. Always renew 10year . Don't be like the car dealer that they will only do 5year. They kill it . Like a cancer for the car in 5year. Top of the cost. I have renew all my car and bike 10year . I have keep a few car and bike and they run good. Depend how you take care of them. carcar

  15. Rent a car Islamabad is one of the most trustworthy and renowned name of the VIP car rental market place in Pakistan.
    We offer premium car rental service at affordable charges to keep your traveling need absolutely budget friendly.
    carcarshire a car

  16. I think this is the best information about car and I recommend all the car owners and the information seekers of cars to have car tracker Pakistan