This tutorial will show you how to use Watchdog to keep your Raspberry Pi running.
Watchdog is an incredibly useful tool for your Raspberry Pi. It allows you to detect when your Pi locks up and automatically restarts the device.
If you have Raspberry Pi’s that aren’t easily accessible, then Watchdog is a must. It allows you to ensure that if it runs into trouble, you can hopefully get it up and running again without having to physically access it.
All of this is made possible by hardware on the Pi board. This hardware acts as a timer that is constantly reset by the operating system. If, for any reason, the Watchdog service stops talking with this hardware, it will power cycle your Raspberry Pi.
Best of all, setting up Watchdog on your Raspberry Pi is a super straightforward process. In fact, it only takes a few commands.
We will be covering two different methods for using Watchdog. The first is to use Systemd. The advantage of this is that it is super easy to use, but it isn’t super configurable.
The other method requires you to install the Watchdog application on your Raspberry Pi. This method is more configurable and allows you to trigger a reset if your Pi’s load averages are super high.
Below, you can find a list of equipment we used when setting up Watchdog on our Pi.
This tutorial was last tested on a Raspberry Pi 400 running the latest version of Raspberry Pi OS Bookworm.
How to Enable the Watchdog on Raspberry Pi OS using Systemd
Over the following sections, we will be showing you how you can enable Watchdog on your Raspberry Pi.
Luckily this is a really straightforward process as the system manager (systemd) has built-in support for handling Watchdog. What this means is that we are not required to install any additional information.
Additionally, if you are using Raspberry Pi OS, most of the default configurations will work straight out of the box.
1. Since systemd is a core part of Raspberry Pi OS, we can begin modifying its configuration immediately.
Start modifying the “
system.conf” configuration file by using the command below.
sudo nano /etc/systemd/system.conf
2. Within this file, you will want to add the following two lines to the bottom.
Now, you are probably wondering what these lines actually mean, so let us quickly go over them.
RuntimeWatchdogSec– This value is what is used to program the Watchdog hardware with how long it should wait before resetting your Raspberry Pi.
Due to the limitations of the Pi, this has a maximum timeout length of 15 seconds. This means that when set to 15, the Raspberry Pi will be reset if the Watchdog doesn’t receive a message for 15 seconds.
RebootWatchdogSec– The reboot watchdog allows you to determine how long your Raspberry Pi should wait for a restart to complete.
If it gets stuck for longer than the specified time, then the Watchdog will force a reset.
3. After making changes to the systemd configuration, you can save and quit by pressing CTRL + X, followed by Y, and then the ENTER key.
4. By enabling Watchdog on our Raspberry Pi, we have made changes to the systemd configuration.
For these changes to take effect, you will need to restart the systemd daemon by running the command below.
sudo systemctl daemon-reload
Alternatively, you can restart your entire system by using the command below.
Using the Watchdog Application on the Raspberry Pi
In this section, we will be showing you how to use the Watchdog application on your Raspberry Pi.
The advantage of using this application over systemd is that it is significantly more configurable than using systemd. For example, you can have Watchdog restart your Pi whenever your average load is consistently over a particular value.
You can even have it restart your device if a network adapter stops getting activity.
Installing Watchdog to your Raspberry Pi
1. Before we continue any further, we should update our Raspberry Pi’s packages as well as update the package list cache.
You can update your Pi and upgrade the cache by utilizing the following two commands.
sudo apt update
sudo apt upgrade
2. Once the update is complete, all you need to do to install the Watchdog application to your Raspberry Pi is to run the following command within the terminals.
sudo apt install watchdog
Configuring Watchdog to Reboot Your Pi
3. You can begin modifying the configuration file for the Watchdog service by using the command below within the terminal.
sudo nano /etc/watchdog.conf
4. Within this file, you will want to add the following lines to the bottom. These lines tell the service to talk with the Pi’s hardware watchdog timer.
There are plenty of other options that this daemon supports, so it is worth exploring the file to see what you can set.
a. This first line tells Watchdog where it should connect to talk with the Raspberry Pi’s hardware.
watchdog-device = /dev/watchdog
b. Next, we need to set the hardware timeout for the Raspberry Pi’s Watchdog. By default, this is set to 60 seconds which is to long for the Pi.
The Raspberry Pi only supports a maximum of 15 seconds for its timeout.
watchdog-timeout = 15
c. Next, you will want to use watchdog to reset your Raspberry Pi if its load is insanely high. Super high loads typically indicate your machine has locked up.
max-load-1 = 24
d. Optionally, you can also use Watchdog to monitor and restart your Raspberry Pi if a network interface isn’t responding or has zero activity.
To do this, all you need to do is specify “
interface” followed by the equal sign and then the name of the network adapter.
The example below will restart your Pi if Watchdog detects zero activity on your wlan0 interface.
interface = wlan0
5. After making the above changes to the file, save and quit by pressing CTRL + X, followed by Y and then the ENTER key.
Starting the Watchdog Service
6. Now that we have configured Watchdog on the Raspberry Pi, we will need to enable the service.
Enabling the service allows it to start when your Pi does.
sudo systemctl enable watchdog
7. If you want the Watchdog to start immediately, you can then use the following command to start the service.
sudo systemctl start watchdog
Hopefully, at this stage, you will now have an idea of how you can use Watchdog to keep your Raspberry Pi running.
This hardware feature allows you to force a restart even if your device is completely unresponsive.
Please feel free to leave a comment below if you have any questions about using Watchdog.
If you found this tutorial to be helpful, we highly recommend checking out our many other Raspberry Pi projects.