watchdog is a userspace daemon that “feeds” a kernel or hardware watchdog timer (often via /dev/watchdog) to ensure the system reboots automatically if it freezes. Depending on your distro, you might also use systemd's built-in watchdog support.
On many distros, watchdog is a package. Configuration is commonly in /etc/watchdog.conf.
# Debian/Ubuntu sudo apt update sudo apt install watchdog # RHEL/CentOS/Fedora sudo dnf install watchdog # Arch (package availability can vary) sudo pacman -S watchdog
A watchdog is essentially a countdown timer. A userspace agent (like watchdog or systemd) periodically "pings" the watchdog device. If the OS freezes and pings stop, the countdown expires and the machine reboots.
Hardware watchdogs are preferred when available (they can recover from deeper hangs). Software watchdog behavior can depend on system state.
1) Verify watchdog device(s) exist
checkSee whether the kernel has exposed a watchdog interface.
ls -l /dev/watchdog*
Use when: you’re not sure the hardware/driver is present or loaded.
2) Start the watchdog service (systemd)
serviceEnable and start the daemon (if your distro provides a service unit).
sudo systemctl enable --now watchdog systemctl status watchdog
Use when: you want watchdog active at boot and running now.
3) Run watchdog in the foreground for testing
testForeground mode helps you see log output directly.
sudo watchdog -F -c /etc/watchdog.conf
Use when: you’re iterating on config and want immediate feedback.
4) Minimal config: point to the watchdog device
configMany setups only need the device path and an interval.
# /etc/watchdog.conf (example - keep minimal at first) watchdog-device = /dev/watchdog interval = 10
Use when: you want the simplest working configuration before adding checks.
5) Test the watchdog “feed” mechanism (carefully)
testA write to /dev/watchdog typically feeds the watchdog. Use with care.
# WARNING: enabling the watchdog may cause reboot if not fed continuously sudo sh -c 'echo 1 > /dev/watchdog'
Use when: you’re confirming the device responds (do this only during planned testing).
6) Enable systemd hardware watchdog (RuntimeWatchdogSec)
systemdLet systemd ping the hardware watchdog automatically.
# Edit /etc/systemd/system.conf and set: # RuntimeWatchdogSec=20s sudo systemctl daemon-reexec
Use when: you want a simple system-wide watchdog without the watchdog daemon.
7) Add process monitoring (restart/alert logic depends on config)
healthYou can configure watchdog to check for a process and act if it vanishes.
# /etc/watchdog.conf (example concept) # check if a PID file exists (common pattern) pidfile = /run/mydaemon.pid # or check a process by name (varies by build) # test-binary = /usr/sbin/mydaemon
Use when: you want watchdog to react to a critical service dying (in addition to hangs). /p>
8) Monitor load to detect “system stuck” scenarios
healthTrigger action if load exceeds a threshold (example).
# /etc/watchdog.conf (example) max-load-1 = 24 max-load-5 = 18 max-load-15 = 12
Use when: runaway load correlates with hard lockups on your system (tune carefully).
9) Log watchdog output (journalctl)
logsInspect daemon logs to confirm checks and feeding are working.
journalctl -u watchdog -b journalctl -u watchdog -f
Use when: you’re validating the configuration and want to see why a check fails.
10) See current watchdog driver/status (kernel messages)
diagnoseMany watchdog drivers announce themselves in dmesg.
dmesg | grep -i watchdog lsmod | grep -i wdt
Use when: you’re confirming which driver is active and whether it’s blacklisted or missing.