I set up this Linux ‘Watchdog’ and now my system auto-reboots when it locks up


3d rendering of a futuristic mechanical dog stuffed toy in a dark black background with a effect of boom for the purpose of advertisement and commercial use

AssasinatorCzar via iStock / Getty Images Plus

Follow ZDNET: Add us as a preferred source on Google.


ZDNET key takeaways

  • If your Linux system locks up, it might need rebooting.
  • With the help of a small application, this can be automated.
  • Watchdog is easy to install and free to use.

I have several Linux systems connected to my home lab; some of them are desktops, and some of them are servers. Ninety-nine percent of the time, those machines work flawlessly. When that one percent happens, any machine that goes south needs help.

One way of helping is via a small software package called Watchdog. This piece of software runs various checks to see if the hardware has “locked up.” If it detects that it has happened, it will reboot the machine.

Also: 6 reasons a minimal Linux install might be the smartest move you make

There are two types of Watchdogs: software and hardware. The hardware Watchdog is much more reliable, but it requires specialty hardware for it to work. The software Watchdog isn’t quite as reliable, but it works on most Linux systems.

How Watchdog works

A kernel module (softdog), in conjunction with the Watchdog service, watches the system with a countdown timer.

  • A virtual device is created (/dev/watchdog).
  • If the virtual device is “kicked” by a process, the timer resets.
  • If the virtual device isn’t “kicked” by a process, Watchdog reboots the system.

It’s simple in theory, but the underpinnings are much more complicated. Fortunately, as a user, you don’t have to dig too deeply to get the gist of Watchdog.

Also: The first 8 Linux commands every new user should learn

Although Watchdog can be essential for servers (especially those that don’t have a monitor, keyboard, or mouse connected), it can also be useful for desktops. For example, say you need to log into a Linux machine on your home network from work. If that machine locks up, you won’t be able to access it. If that machine has Watchdog keeping tabs on it, it’ll reboot, and you’ll be able to access it.

This can be very handy.

You might think Watchdog is hard to set up, but you’ll be surprised that it’s not that much of a challenge, even if you’re just starting out with Linux.

Also: My 5 go-to Linux commands for troubleshooting – and how I use them

Let me show you how it’s done.

How to install Watchdog

What you’ll need: I’m going to demonstrate this on a machine running Ubuntu 24.04. Watchdog is found in the standard Ubuntu repositories (as well as the Fedora standard repositories). For Arch users, you have to use yay to install this software. You’ll also need a user with sudo privileges.

The first thing to do is install Watchdog, which can be done with the command:


Show more

sudo apt-get install watchdog -y

If you’re using a Fedora-based machine, the command is:

sudo dnf install watchdog -y

For Arch, it’s:

yay -S watchdog

With Watchdog installed, you then have to load the softdog kernel module, which is done with:


Show more

sudo modprobe softdog

Verify the module has loaded with:

lsmod | grep softdog

If you see softdog listed, then it’s successfully loaded.

Also: The best Linux laptops in 2026: Expert tested for students, hobbyists, and pros

Check to make sure the device node exists with:

ls -la /dev/watchdog

You’ll also need to have the Watchdog kernel module loaded at boot. If you don’t do this, the service won’t be running after a reboot (so it won’t be watching the system). This is done with:


Show more

Watchdog

Make sure to type this command correctly.

Jack Wallen\ZDNET

You’re now ready to configure Watchdog.

How to configure Watchdog

With Watchdog running, you’ll want to make sure the configuration file is set up such that it’ll actually do what it’s supposed to do when it should. This is done by way of a configuration file. Open that file with the command:

sudo nano /etc/watchdog.conf

In that file, look for the following lines (they are not found consecutively in the file):

# watchdog-device = /dev/watchdog

# interval = 1

# watchdog-timeout = 20 # Time in seconds before reboot

# realtime = yes

# priority = 1

# max-load-1 = 24

# max-load-5 = 18

# max-load-15 = 12

# min-memory = 1

What you need to do is remove the # and the space before each line. Note: If you don’t see the watchdog-timeout = 20 line, manually add it.

Save and close the file.

You’ll then need to start and enable the service with the command:

sudo systemctl enable –now watchdog

Watchdog is now running in the background and will do its thing, should something go awry.

Also: You can use Linux 7.0 on these 7 distros today – here’s what to expect

If you want to test whether or not Watchdog is working, you can manually cause a kernel panic with the following three commands:

sudo sysctl -w kernel.sysrq=1

sudo su –

echo c > /proc/sysrq-trigger

The system will become unresponsive, and Watchdog should reboot it.

The hardware method

If you happen to have a hardware watchdog, systemd can be configured to kick it and enact a reboot. Here’s how you configure this.

Open the systemd config file with:

sudo nano /etc/systemd/system.conf

Locate the following lines:

#RuntimeWatchdogSec=0

#RebootWatchdogSec=10min

#WatchdogDevice=

Change those lines to:

RuntimeWatchdogSec=30

RebootWatchdogSec=10min

WatchdogDevice=/dev/watchdog

Save and close the file.

Also: My proven way to speed up Linux when RAM upgrades aren’t worth it (and it’s free to do)

Restart the systemd daemon with:

sudo systemctl daemon-reload

And there you have it. You now have a service watching your system and will reboot it, should things go south.





Source link

Leave a Reply

Subscribe to Our Newsletter

Get our latest articles delivered straight to your inbox. No spam, we promise.

Recent Reviews


Serials have become the backbone of the streaming era, especially on Netflix. Serialized television is when a show’s plot unfolds in sequential order over the course of a season. It’s long-form storytelling that typically works best with dramas—Stranger Things, The Crown, etc. Watching the episodes in release order matters. Often, these shows are binged because the complex character arcs and cliffhangers encourage streaming multiple episodes at once.

Serial shows can feel like homework, especially when you fall behind on an episode and need to catch up. That always happens to me, and it leads to anxiety I didn’t want. Thankfully, Netflix offers shows where viewers can jump at any time and not feel lost. These episodic series are perfect for jumping around and picking the episodes you want to watch. One of the most famous comedies ever fits the criteria of an episodic sitcom. Anthology shows, including a Netflix sci-fi classic, are also ideal for watching episodes out of order.

Black Mirror

Welcome to your worst nightmare

Black Mirror wants to scare you. Charlie Brooker’s sci-fi anthology series has been warning humanity about the dangers of technology since 2011. It seems like ages ago that Rory Kinnear had sexual intercourse with a pig in the first episode. Apologies for the spoiler, but the media’s role in the spread of misinformation has never been more relevant.

Black Mirror features self-contained episodes with a beginning, middle, and an end. There has only been one direct sequel: USS Callister: Into Infinity, a season 7 episode that continues the events of season 4’s USS Callister. Otherwise, feel free to jump around and check out the best episodes of each season. Since most episodes feature bleak endings, I’ll leave you with one that ends on an upbeat note: San Junipero.

Seinfeld

Greatest comedy ever?

Comedies are the perfect vehicle for episodic storytelling. While having an overarching plot throughout a season helps attract viewers, many comedy fans are just looking for a few laughs. Write a self-contained story with numerous jokes over 20 to 30 minutes, and you’re ready to go. Seinfeld, aka the show about nothing, is the ideal escape from serialized dramas.

Seinfeld stars Jerry Seinfeld as a fictionalized version of himself as he navigates the comedic scene in New York City. The show revolves around Jerry’s interactions with his friends George (Jason Alexander), Elaine (Julia Louis-Dreyfus), and Kramer (Michael Richards). The gang faces a problem, hilarity ensues, and the episode ends. That’s really all you need to know. Enjoy the laughs.

Guillermo del Toro’s Cabinet of Curiosities

The genre maestro curates new horror stories

There’s a reason why Guillermo del Toro is considered the “King of the Monsters.” The genre expert is as elite as it comes when dealing with mythology and creating new worlds. The Oscar winner relied on his horror expertise in the anthology series Guillermo del Toro’s Cabinet of Curiosities.

I hate referring to episodes of television as “mini-movies.” However, that’s how I would describe the eight episodes of Cabinet of Curiosities. Each director puts their own signature style on a story and brings audiences into their terrifying creation. Del Toro wrote two of the episodes, including one about a demon being summoned. Some are scarier than others, but horror fans will feel right at home with this series. ​​​​​​​

Beat Bobby Flay

Bobby brings the heat

As I’ve gotten older, the Food Network has become one of my favorite channels. I mean, who doesn’t love food? I love eating my (average) home-cooked meal while watching contestants duke it out in the kitchen on my favorite show, Beat Bobby Flay. The competition breaks down into two rounds. In the first round, two chefs have 20 minutes to construct a meal using a secret ingredient. The winner advances to the main event, where they face off against Bobby Flay.

The challenger gets to pick the dish for the final round, so Bobby has a disadvantage. However, Bobby is an award-winning chef with a few tricks up his sleeves. He can handle making a version of your grandmother’s lasagna. With episodes available on Netflix, be prepared to learn why Bobby always throws chiles into his dishes.​​​​​​​

S.W.A.T.

Broadcast TV still knows how to make entertaining programs

The procedural is a genre best produced on broadcast television. Name a cop, doctor, or law drama—chances are it’s a procedural on broadcast TV. While the way we watch television has changed, people still love these types of shows on CBS, NBC, Fox, and ABC. Law & Order, NCIS, and Criminal Minds are procedurals that gained a bigger following thanks to streaming.

S.W.A.T. is cut from the same cloth as Chicago P.D. and CSI. Sergeant Daniel “Hondo” Harrelson (Shemar Moore) is tasked with leading a new S.W.A.T. unit in the LAPD. This action-packed show utilizes a “case of the week” formula in which the team must solve a dangerous situation, such as active shooters and hostage situations. You’re in and out in 44 minutes. What’s better than that?​​​​​​​


Netflix has more content coming your way

After you’re done watching these shows, stay on Netflix for more top-notch content. Netflix has an entire section dedicated to thrillers, and this week, The Guilty and El Camino are two of the section’s best. Keep an eye out for new movies, like Alan Ritchson’s War Machine, which is currently in the streamer’s top 10.

Subscription with ads

Yes, $8/month

Simultaneous streams

Two or four




Source link