Watchdog is responsible for monitoring tiny systems like raspberry PI, BeagleBone or any other system.
The main functionality of the watchdog is to check, if the system is still responding, lets say, to keep-alive messages.
Let’s assume, the system is stuck in a kernel panic, this will be automatically restarted by watchdog after reaching a grace time period. So a manual rebooting by unplugging the DC adapter is not required at all.
1. DIY – Do it yourself method
The DIY method don’t require installation of any additional system packages and can be realised in any scripting language.
Proof of concept – initialise the watchdog by running:
echo "." > /dev/watchdog
the system gets automatically restarted in 15 seconds if you don’t feed the watchdog or issue the interrupt statement by sending the V-character:
echo "V" > /dev/watchdog
This tiny script can be started with your system and will be responsible system monitoring
#!/usr/bin/env bash # Activate watchdog and run periodically a keep-alive while true; do echo "." > /dev/watchdog sleep 14 done
Or as a python version:
import time watchdog = '/dev/watchdog' while True: with open(watchdog, 'w+') as wf: wf.write('.') time.sleep(14)
2. Ready to go method
The second method is to install watchdog and configure it.
apt install watchdog
Configuration part is short /etc/watchdog.conf and can be filled out just by copy-paste:
max-load-1 = 24 min-memory = 1 watchdog-device = /dev/watchdog watchdog-timeout = 15
Finally start and enable the watchdog:
systemctl start watchdog && systemctl enable watchdog
Get ready for any issue
Start a fork bomb to bring your system out of order to verify if your watchdog implementation works as expected :
: ( ){ : | : & }; :
Or simulate a kernel panic:
echo c > /proc/sysrq-trigger