Never Walk to the Power Button When an Ubuntu GPU Server Freezes: A Minimal Setup with the Hardware Watchdog and Auto-Reboot on Panic

So that nobody has to go press the power button when an Ubuntu 24.04 GPU server freezes, we added three things to our standard build: the systemd hardware watchdog, auto-reboot on panic, and a oneshot service that loads the watchdog device at boot. Includes the deny-list trap.

Never Walk to the Power Button When an Ubuntu GPU Server Freezes: A Minimal Setup with the Hardware Watchdog and Auto-Reboot on Panic

Hello!

When a GPU inference server freezes inside the kernel, SSH returns its banner and then goes silent, and there is nothing left you can do remotely.

All that remains is a long press on the power button. If nobody is in the office or the server room, even that is out of reach.

Comic: a developer stuck with a frozen GPU server, and a senior engineer proposing to make it reboot automatically
When a server freezes, there is nothing you can do remotely. Stock Ubuntu does not reboot itself
  • Developer"Our GPU server froze. SSH is dead, so someone has to go press the button."
  • Senior"Stock Ubuntu only logs a warning when it freezes. It won't reboot itself."
  • Developer"Can we set the server to reboot on its own when it freezes?"
  • Senior"Yes. It freezes in three ways. Add a catcher for each and make it reboot."

Recently one of our GPU servers froze in the middle of shutting down, and both times a person had to go and press the power button. We wrote up how we isolated the cause (it was a combination of kernel versions) in a separate article, but apart from the root fix,

"If it would just reboot itself when it freezes, nobody would have to run to the site."

That is an obvious thing to want, and this was the first time we put it into our standard configuration.

We added three things.

The systemd hardware watchdog, sysctl settings that reboot automatically on a panic, and a small systemd service that reliably loads the watchdog device's module at boot.

The configuration files come to about 20 lines in total. Ubuntu has one pitfall, though: a watchdog module listed in /etc/modules-load.d/ is not loaded. Step into it and you end up believing the machine is configured when the watchdog is not armed. This article covers the settings, how to apply them, and the check by an actual reboot, with that trap included.

The target is an unattended server running Ubuntu 24.04 with systemd as PID 1. These settings assume the machine should bring itself down when it freezes, so they belong on unattended machines, not on one where a person sits and works.

Contents

  1. Stock Ubuntu does nothing when it freezes
  2. Test environment
  3. Setting 1: Have systemd pet the hardware watchdog
  4. Setting 2: When the kernel finds a fault, panic and reboot in 20 seconds
  5. Setting 3: Load the watchdog device reliably at boot. This is the trap
  6. Acceptance is not done until you confirm re-arming after a reboot
  7. Decide Docker's stop grace periods and put them in reproducibly
  8. We made it one script and built it into our provisioning procedure
  9. Summary

1. Stock Ubuntu does nothing when it freezes

With Ubuntu installed as is, nothing happens when the kernel freezes. After an oops it tries to keep running, and when a hung task (a task stuck in D state) or an RCU stall is detected, it only writes a warning to the log.

The motherboard carries a hardware watchdog, a circuit that forces a reset when no "I'm alive" signal arrives for a set time. But its driver is not loaded, and systemd is not petting it.

What you want for unattended operation is not "keep running no matter what" but "die quickly and come back up cleanly." Rebooting in 20 seconds and being back a minute later means far less downtime than staying frozen until morning.

A server freezes in three ways, and a different mechanism catches each. Figure 1 puts them together.

A server freezes in three ways, and a different mechanism catches each and turns it into a reboot
Figure 1. A server freezes in three ways. When user space stops, the hardware watchdog catches it. When the kernel detects a fault, a panic followed by an automatic reboot catches it. When the late part of shutdown (after systemd-shutdown takes over) stalls, the reboot watchdog catches it. A task that falls into D state in the early part of shutdown is caught by the hung task detection in the second row (figure by Qualiteg)

The first is when user space freezes. When systemd, which is PID 1, cannot pet the watchdog for a set time, the chipset resets the machine.

The second is when the kernel itself can detect the fault. If an oops, a hung task, an RCU stall, or a soft lockup occurs, we escalate it to a panic and reboot a set number of seconds after the panic.

The third is when shutdown stops partway through. This is the one we hit. More than ten minutes after typing shutdown, the power is still on and SSH is dead.

Think of this in two stages. In the first, services are being stopped one by one, and systemd as PID 1 is still alive. The second begins once all services have stopped and PID 1 has been replaced by systemd-shutdown. The reboot watchdog works only in the second stage. A task that gets stuck in D state in the first stage is caught by the panic mechanism, the second of the three. The journal from our hang recorded services being stopped one by one in the first stage, almost up to the last step.

We put these three in place with a systemd setting, sysctl, and a systemd service.

2. Test environment

ItemValue
OSUbuntu 24.04.5 LTS
Kernel6.8.0-147-generic (GA series)
GPUNVIDIA RTX 2000 Ada ×2 (several GPU inference containers running under Docker)
ChipsetIntel (the watchdog device is iTCO_wdt)
systemdThe version shipped with Ubuntu 24.04

We applied the same settings to four GPU machines and confirmed that all four arm the watchdog at boot and come back after a reboot with containers still running. The numbers are in section 6.

3. Setting 1: Have systemd pet the hardware watchdog

systemd has had watchdog support from the start, and two lines under [Manager] in system.conf are enough to turn it on. We leave the main system.conf alone and use a drop-in.

/etc/systemd/system.conf.d/10-qualiteg-watchdog.conf

[Manager]
RuntimeWatchdogSec=60s
RebootWatchdogSec=5min
DefaultTimeoutStopSec=60s

RuntimeWatchdogSec=60s is the watch while the system is running. systemd opens /dev/watchdog0 and sends a signal at regular intervals. If it cannot send one for 60 seconds, the hardware resets the machine. This setting catches a freeze severe enough to stop PID 1.

RebootWatchdogSec=5min is the watch over the late part of shutdown. As systemd-system.conf(5) describes, this value applies only in the second stage, after all normal services have stopped and PID 1 has been replaced by systemd-shutdown. If processing stops there, the hardware watchdog resets the machine after 5 minutes. In the first stage, while services are being stopped, RuntimeWatchdogSec=60s is still in effect. As long as PID 1 is alive and keeps sending the signal, no reset happens in the first stage.

Our shutdown hang left records from the first stage, while services were being stopped, so the first stage is covered by hung_task_panic and panic_on_rcu_stall from Setting 2. As soon as a task stuck in D state or an RCU stall is detected, the kernel panics and reboots in 20 seconds. A stall in the second stage is covered by this one line. Each of the two stages has its own watch.

DefaultTimeoutStopSec=60s shortens the default stop timeout for each service from 90 seconds to 60. It prepares the ground for finishing the first stage quickly (Docker gets a longer value separately, in section 7).

Applying it needs no reboot. Re-executing PID 1 is enough.

sudo systemctl daemon-reexec
systemctl show -p RuntimeWatchdogUSec -p RebootWatchdogUSec -p DefaultTimeoutStopUSec

On our machines it returned this.

RuntimeWatchdogUSec=1min
RebootWatchdogUSec=5min
DefaultTimeoutStopUSec=1min

The watchdog actually starts working once /dev/watchdog0 appears. The device is the subject of section 5.

4. Setting 2: When the kernel finds a fault, panic and reboot in 20 seconds

In the cases where the kernel can notice the fault on its own, leaving it alone means it keeps running half dead while printing warnings. We escalate these to a panic, and reboot on a panic.

/etc/sysctl.d/90-qualiteg-panic-reboot.conf

kernel.panic = 20
kernel.panic_on_oops = 1
kernel.hung_task_panic = 1
kernel.hung_task_timeout_secs = 120
kernel.panic_on_rcu_stall = 1
kernel.softlockup_panic = 1

The six lines mean the following.

SettingValueWhat happens
kernel.panic20Reboot 20 seconds after a panic. The default, 0, means "stay stopped in the panic"
kernel.panic_on_oops1Escalate an oops (a non-fatal error inside the kernel) to a panic. Damage like the BUG: Bad page map we saw in our shutdown hang is not left running
kernel.hung_task_panic1Panic when a task stuck in D state is found
kernel.hung_task_timeout_secs120The number of seconds before a task is judged to be stuck
kernel.panic_on_rcu_stall1Panic when an RCU stall is detected. This symptom actually appeared in the log during our shutdown hang
kernel.softlockup_panic1Panic when a soft lockup is detected

Applying and checking takes just this.

sudo sysctl --system
sysctl kernel.panic kernel.panic_on_oops kernel.hung_task_panic kernel.hung_task_timeout_secs kernel.panic_on_rcu_stall kernel.softlockup_panic

After sysctl --system, confirm that all six values read back match the values in the configuration file. If one does not match, look for another file that sets the same key under /etc/sysctl.d/, /run/sysctl.d/, /usr/lib/sysctl.d/, or in /etc/sysctl.conf. The value from the file read last wins, so check the name order of the files that share the key too.

We keep hung_task_timeout_secs at its default of 120 seconds. A GPU inference container can sit in D state for tens of seconds during heavy work, and 120 seconds absorbs that variation. This is a value to decide according to what the machine does.

5. Setting 3: Load the watchdog device reliably at boot. This is the trap

Comic: a module listed in modules-load.d is not loaded after a reboot, and a senior engineer suggests a service that calls modprobe by name
The module is listed in modules-load.d, yet the watchdog device is missing after a reboot
  • Developer"I listed the watchdog module in modules-load.d. Now it loads at boot, right?"
  • Senior"After the reboot, does /dev/watchdog0 exist?"
  • Developer"It doesn't! The log says module iTCO_wdt is deny-listed."
  • Senior"Ubuntu blocks the auto-load. A service that calls modprobe by name will load it."

The settings in section 3 mean something only once /dev/watchdog0 exists.

In our environment, when iTCO_wdt was loaded and /dev/watchdog0 appeared, systemd recognized the device and armed it automatically. No daemon-reload was needed. We confirmed that /sys/class/watchdog/watchdog0/state changed to active and timeout to 60. When applying by hand, also run the daemon-reexec described below and read back the armed state.

On Intel motherboards, the iTCO_wdt module provides this device. Load it by hand and the device appears on the spot.

sudo modprobe iTCO_wdt
wdctl /dev/watchdog0
cat /sys/class/watchdog/watchdog0/state /sys/class/watchdog/watchdog0/timeout

The Identity line of wdctl showed iTCO_wdt [version 6], state was active, and timeout was 60. So far so good.

The problem comes at the next reboot.

Normally, a module you want loaded at boot goes into /etc/modules-load.d/. But list iTCO_wdt there and reboot, and there is no /dev/watchdog0. The journal shows systemd-modules-load skipping it with this message.

Module 'iTCO_wdt' is deny-listed (by kmod)

Ubuntu's kernel module package (linux-modules-<version>) ships a file named /lib/modprobe.d/blacklist_linux_<version>.conf, and it contains blacklist iTCO_wdt. A file of the same name is generated for each kernel version, so even if you delete it yourself, it comes back with the next kernel update.

This deny-list applies to the automatic loading done by systemd-modules-load, but not to an explicit modprobe iTCO_wdt that names the module. That is why the manual modprobe went through.

Not loaded through modules-load.d, but loaded by a service that calls modprobe explicitly
Figure 2. For the same iTCO_wdt, the path through /etc/modules-load.d/ is skipped by the deny-list, while the path where a service calls modprobe by name loads it and systemd arms the watchdog (figure by Qualiteg)

So the fix is to place a service that runs modprobe explicitly, early in boot.

/etc/systemd/system/qualiteg-watchdog.service

[Unit]
Description=Qualiteg: load iTCO hardware watchdog (Ubuntu deny-lists it; systemd arms RuntimeWatchdogSec once /dev/watchdog0 appears)
DefaultDependencies=no
After=systemd-udev-trigger.service
Before=sysinit.target
ConditionPathExists=!/dev/watchdog0

[Service]
Type=oneshot
ExecStart=/sbin/modprobe iTCO_wdt
RemainAfterExit=yes

[Install]
WantedBy=sysinit.target

DefaultDependencies=no and Before=sysinit.target make it run very early in boot, ahead of ordinary services. Because of ConditionPathExists=!/dev/watchdog0, it does nothing and is skipped on a machine where the device already exists (which is what we want).

Enable and apply it like this.

sudo systemctl daemon-reload
sudo systemctl enable --now qualiteg-watchdog.service
sudo systemctl daemon-reexec

The final daemon-reexec re-executes PID 1 after /dev/watchdog0 has been created, so that it picks up the device right then. The watchdog is armed without waiting for a reboot.

If a file from the old approach is still sitting in /etc/modules-load.d/, remove it. A setting that is never read, left in place, leads whoever looks later to take the machine as configured.

A different machine means a different module name. First, look at the current state.

ls -l /dev/watchdog*
ls /sys/class/watchdog/
lsmod | grep -E 'iTCO_wdt|watchdog'
sudo wdctl /dev/watchdog0

If the device does not exist yet, the first ls and the final wdctl return errors. Those results are part of what you are checking.

If another driver already provides /dev/watchdog0, just use that module as is. There is no need to add a modprobe on top. If there is nothing, find the watchdog driver for your motherboard's chipset, modprobe it, confirm that /dev/watchdog0 is created, and then rewrite the service's ExecStart. Our machines are Intel, and the module was iTCO_wdt.

6. Acceptance is not done until you confirm re-arming after a reboot

Comic: a developer about to finish acceptance on read-back values, and a senior engineer telling them to reboot and check
Matching read-back values do not finish acceptance. Reboot for real and check that it works from power-on
  • Developer"I wrote the config files and the values read back fine. So acceptance is done?"
  • Senior"Not yet. Reboot and check the watchdog still runs after a fresh start."
  • Developer"After the reboot, state is active. The log also says Using hardware watchdog."
  • Senior"That's a pass. Only a reboot shows whether it works from power-on."

It is tempting to call it done once the configuration files are written and the read-back matches, but here we go as far as an actual reboot.

We checked in this order.

StepWhat to look atExpected
1systemctl show -p RuntimeWatchdogUSec -p RebootWatchdogUSec1min and 5min
2The six sysctl valuesThe values in section 4
3That /dev/watchdog0 exists, and wdctl /dev/watchdog0Identity is shown. state=active, timeout=60
4systemctl is-enabled qualiteg-watchdog.serviceenabled. No leftovers of the old approach in /etc/modules-load.d/
5Actually rebootThe shutdown journal shows Using hardware watchdog 'iTCO_wdt'. After boot, /dev/watchdog0 is active and there is a record that the service ran

Only step 5 confirms that the watchdog is enabled from power-on.

In the first reboot test the shutdown-side watchdog worked, and systemd-shutdown wrote "Using hardware watchdog 'iTCO_wdt' ... Watchdog running with a timeout of 5min." That was because the manual modprobe just before had created the device. The read-back after boot showed that /dev/watchdog0 had not appeared, which led us to the deny-list behavior. We switched to the service approach, and the next reboot confirmed that it works from power-on.

In that reboot, qualiteg-watchdog.service ran right after boot and the device was detected, one second later systemd printed Using hardware watchdog 'iTCO_wdt', and the state was state=active timeout=60.

We also measured how long a reboot takes. With GPU containers still running, we issued systemctl reboot and counted the seconds until TCP 22 dropped and until we could log in again over SSH.

Even with containers still running, SSH comes back about a minute after a reboot
Figure 3. Seconds until TCP 22 dropped and until SSH login worked again, after systemctl reboot with containers still running. All four machines had the watchdog armed at boot (values measured on our machines, figure by Qualiteg)

On the slowest machine it took 29 seconds until TCP 22 dropped and 59 seconds until SSH login worked again. The other three were back in 34 to 38 seconds. An ordinary shutdown finishes with plenty of room to spare against the watch timeouts.

7. Decide Docker's stop grace periods and put them in reproducibly

Comic: after shortening the service stop timeout, a developer and a senior engineer settle Docker's stop waits at 120 and 180 seconds
Once the stop timeout is shortened, decide for yourself how long to wait for Docker, which is slow to stop
  • Developer"I cut the stop timeout to 60 seconds. Do Docker containers stop in 60?"
  • Senior"Some containers ignore SIGTERM. So Docker alone gets a longer stop wait."
  • Developer"dockerd now waits up to 120 s for containers, and systemd up to 180 s for dockerd."
  • Senior"That 60 s gap is the margin. Normally, stop containers first, then the OS."

Once you shorten the stop timeout, you then have to decide for yourself where in shutdown to wait, and for how long. A service with a long stop grace period stretches the first stage by that much.

For us the long one was Docker. Some of our GPU inference containers do not respond to SIGTERM, so they wait out the full grace period and then get SIGKILL.

We set this in two places on the Docker side. The first is /etc/docker/daemon.json. Keep the existing settings and add one key (ours already held the NVIDIA runtime settings, so we added it next to them).

{
  "shutdown-timeout": 120
}

shutdown-timeout is the upper limit dockerd waits for containers to stop when it exits. It is separate from the per-container SIGTERM grace period (docker stop -t, compose's stop_grace_period, and the daemon default default-stop-timeout). This one sets the limit the daemon as a whole will wait.

After editing, validate the syntax. Applying it requires restarting dockerd, which stops the containers, so do it within a planned outage (we ran the reboot test right afterward, and it took effect there).

sudo dockerd --validate --config-file=/etc/docker/daemon.json

The second is a drop-in for docker.service. Open it with sudo systemctl edit docker and it is saved to /etc/systemd/system/docker.service.d/override.conf.

[Service]
TimeoutStopSec=180s

Apply and read back like this.

sudo systemctl daemon-reload
systemctl show docker.service -p TimeoutStopUSec

On our machines it returned TimeoutStopUSec=3min.

The numbers relate like this. dockerd waits up to 120 seconds for containers to exit, and systemd waits up to 180 seconds for dockerd to stop, so Docker's exit handling has 60 seconds of margin. Both settings act on the first stage (while services are being stopped) and work separately from RebootWatchdogSec=5min in the second stage.

The shutdown time of the OS as a whole is the total that includes stopping other services and devices. In our measurements, even the slowest machine took 29 seconds until TCP 22 dropped (section 6).

We added one more rule on the operations side. Before a shutdown or reboot, stop the GPU containers gently with docker stop first, and then stop the OS. We are also bringing the containers in line so that they stop on SIGTERM. The watchdog is the last safety net, and we operate so that we normally never land in it.

8. We made it one script and built it into our provisioning procedure

We bundled the three items above into a single script that runs as root and made it part of our standard server provisioning procedure. It is built to leave the same state however many times you run it (idempotent), and it takes the module name as an argument (the default is iTCO_wdt).

At the end it reads the state back and exits non-zero unless state=active and timeout=60. We also added three checks to our verification script: "the service is enabled," "watchdog0 is armed," and "no leftovers of the old approach in modules-load.d."

The three configuration files and the commands to apply them are given in full in sections 3 to 5, so copying them as they are gives you the same state. On machines that use Docker, add the two items from section 7 as well (the shutdown-timeout in daemon.json and the drop-in for docker.service). We keep these out of the script and decide the values machine by machine.

9. Summary

Remember which mechanism catches which kind of freeze, and the rest is three configuration files.

ProblemWhat catches itWhere to write it
PID 1 freezes as a whole and SSH diesRuntimeWatchdogSec=60s (the hardware resets)A drop-in under /etc/systemd/system.conf.d/
The kernel reports an oops, hung task, RCU stall, or soft lockupSix sysctl values escalate it to a panic, and the machine reboots in 20 seconds/etc/sysctl.d/
A task stays stuck in D state in the early part of shutdown (while services are stopping)The same six sysctl values as above (hung_task_panic, panic_on_rcu_stall)/etc/sysctl.d/
The late part of shutdown (after systemd-shutdown takes over) stallsRebootWatchdogSec=5min (reset after 5 minutes)The same drop-in
The watchdog device does not appear at bootA oneshot service with an explicit modprobe/etc/systemd/system/

And listing iTCO_wdt in /etc/modules-load.d/ does not get it loaded. If /dev/watchdog0 is missing after a reboot, suspect this first.

Acceptance means reading the settings back and then actually rebooting until Using hardware watchdog appears. Whether the watchdog is enabled from power-on is confirmed by the read-back after the reboot.

See you next time!

References

Read more