External Watchdog OS integration

integrated into the Raspbian kernel and OS there are pre-built utilities for configuring and managing watchdogs, in this example we will show how to configure the OS such that a file's last update timestamp will trigger a watchdog time out.

In this configuration if the target file is not updated the system will attempt an “orderly” reset as it performs some basic "clean-up" tasks prior to finally stopping the watchdog input line toggling, and so causing the Raspberry Pi Compute Module’s reset line (aka RUN pin) to be momentarily pulled low by the watchdog device resulting in a hard reset.

The watchdog system is configured by 3 main files

  •  - A device tree configuration file to enable the GPIO Watchdog timer /dev/watchdog1
  •  - A systemd service file /lib/systemd/system/watchdog.service
  •  - The conditional check options specified in /etc/watchdog.conf

Let's start by installing the requisite files and configuring them

Raspbian-external-watchdog-OS-integration
 
Add the line below to the bottom of /boot/config.txt

Raspbian-external-watchdog-OS-integration


The configuration we’re using to determine both the watchdog device the system should be using and the test for system time out is setup in /etc/watchdog.conf

Raspbian-external-watchdog-OS-integration


 
Next the systemd service file needs editing to set the external watchdog’s enable line to enabled after the watchdog input line has been set toggling

Raspbian-external-watchdog-OS-integration
 
Copies of these files have been stored in /root/config_backups/ext-watchdog for quick reference


 
With these in place reboot the unit so the changes take effect
On reboot you should be able to issue the commands shown below to check the services have started correctly.
 

If the file we have configured as the test for watchdog time out is not written to for a period of 3 x the change value (in seconds) then the system will attempt a managed restart, by shutting as many services down as possible etc and then stopping the watchdog timer, causing a hard reset


 
At any point up to this final time out writing/touching the file will reset the counter.


To test the system operation in the event of a kernel fault run the below to provoke a kernel panic

 # echo c > /proc/sysrq-trigger


Alternatly a recursive "fork bomb" which causes all CPU resources to be used can be provoked using the command below

 # :(){ :|:& };:


 

 

External Watchdog Config Files

 

 

 

Watchdog.conf Configuration Options

Systemd Watchdog Configuration notes

StackExchange: Raspberry Pi Watchdog

StackExchange: Provoking a Kernel Panic/Forkbomb

Contact us now to discuss your project

Ready to order, contact us today for pricing or samples

Contact Us