Linux Reliability Watchdog

watchdog — detailed guide + 10 practical examples

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.

What watchdog is good for

  • Automatic recovery: reboot the machine if the OS hangs and stops “feeding” the timer.
  • Fail-safe for remote systems: servers, embedded devices, kiosks, headless boxes.
  • Health checks: the daemon can also monitor processes, load, files, and network and trigger actions.
  • Systemd alternative: systemd can manage a hardware watchdog too (RuntimeWatchdogSec=).

Install & first run

On many distros, watchdog is a package. Configuration is commonly in /etc/watchdog.conf.

Install (common distros)
# 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
Danger: Once a watchdog device is active, not feeding it can reboot the machine. Always test in a safe window.
Tip: Before configuring, check if your kernel exposes a watchdog device: ls -l /dev/watchdog*

How watchdogs work

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.

10 examples you can copy/paste

1) Verify watchdog device(s) exist

check

See whether the kernel has exposed a watchdog interface.

Command
ls -l /dev/watchdog*

Use when: you’re not sure the hardware/driver is present or loaded.

2) Start the watchdog service (systemd)

service

Enable and start the daemon (if your distro provides a service unit).

Commands
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

test

Foreground mode helps you see log output directly.

Command
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

config

Many setups only need the device path and an interval.

Example snippet
# /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)

test

A write to /dev/watchdog typically feeds the watchdog. Use with care.

Command
# 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)

systemd

Let systemd ping the hardware watchdog automatically.

Commands
# 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)

health

You can configure watchdog to check for a process and act if it vanishes.

Example snippet
# /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

health

Trigger action if load exceeds a threshold (example).

Example snippet
# /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)

logs

Inspect daemon logs to confirm checks and feeding are working.

Commands
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)

diagnose

Many watchdog drivers announce themselves in dmesg.

Commands
dmesg | grep -i watchdog
lsmod | grep -i wdt

Use when: you’re confirming which driver is active and whether it’s blacklisted or missing.

Notes & gotchas