December 5, 2026

UPS Battery Backup With NUT: Testing an Automatic Shutdown Before the Power Actually Fails

A UPS on the floor powering a NAS and router on a shelf above

A UPS buys a home server a few minutes when the power goes out. What happens at the end of those minutes depends entirely on software. If nothing tells the server to shut down, it runs until the battery dies and loses power mid-write, exactly the failure the UPS was bought to prevent. Network UPS Tools, usually called NUT, is the standard open-source way to connect the two. Rather than pulling a plug to find out whether it works, NUT 2.8.1 was set up on Linux with its built-in simulated UPS driver, and a power failure was staged step by step to watch every decision it made.

Video: Techno Tim on YouTube

How NUT is put together

Three pieces

NUT splits the job into parts. A driver talks to the UPS hardware over USB or serial. The upsd server collects the driver’s data and makes it available over the network. And upsmon watches that data and decides when to shut the machine down.

The upsmon manual describes two roles. A “primary” client is one “running on the system with the UPS actually plugged into a serial or USB port.” A “secondary” is “drawing power from the UPS but can’t talk to it directly,” such as a second server plugged into the same UPS. NUT, upsmon(8) One UPS can therefore protect several machines, with the primary telling the others when to go.

The test setup

The dummy-ups driver that ships with NUT reads UPS values from a plain text file instead of real hardware. Editing that file changes what NUT believes the UPS is doing. The file started with:

ups.status: OL
battery.charge: 100
battery.runtime: 1800

OL means on line, running from wall power. upsc myups@localhost returned the full list of values, including the simulated driver’s model name, confirming that the driver and server were talking.

White router on black table

When upsmon decides to shut down

On battery is not enough

The first test switched the status to OB, on battery, with the charge at 95%. Within two seconds upsmon logged an ONBATT event. Twelve seconds later the status still read OB and no shutdown had been requested. Switching back to OL produced an ONLINE event and the system carried on.

That is the designed default. The upsmon manual defines a critical UPS as “on battery and low battery.” Going on battery alone is a warning, not a reason to shut down.

On battery plus low battery

The status was then set to OB with 60% charge, and a few seconds later to OB LB, on battery and low battery, with 18% charge and 240 seconds of runtime. The notification log showed:

08:05:46 ONBATT
08:05:52 LOWBATT
08:05:52 SHUTDOWN

Three seconds after the SHUTDOWN notice, at 08:05:55, upsmon ran its shutdown command. Afterward the UPS status read FSD OB LB. The manual explains that FSD is the “forced shutdown” flag, which the primary sets on its UPS so that secondary machines know to shut down too. upsmon also created its power-down flag file, which tells the system’s final shutdown scripts that the UPS itself may now be switched off.

Timing settings

The three-second gap came from FINALDELAY 3 in the test configuration. The upsmon.conf manual says “By default this is set to 5 seconds.” The test also polled every 2 seconds instead of the default; the manual notes that “Normally upsmon polls the upsd(8) server every 5 seconds.” NUT, upsmon.conf(5) On a real system the defaults are sensible.

The problem with waiting for low battery

Who decides what “low” means

The LB flag comes from the UPS, or from thresholds the driver applies. Many consumer units raise it late, leaving only a couple of minutes of runtime. A server with a slow-to-stop database, a NAS with several drives to park, or a hypervisor shutting down a handful of virtual machines may need longer than that. And older batteries hold less charge than the original runtime estimate suggests, so “low” arrives sooner than expected.

Shutting down early instead

The upssched manual suggests the alternative directly: “To shut down the system early, define a timer that starts due to an ONBATT condition,” and “Be sure you cancel the timer if power returns (ONLINE).” NUT, upssched(8) The tool exists “to allow users to execute programs at times relative to events being monitored by upsmon.”

Black flat screen tv turned on near black laptop computer

A timed shutdown, tested

The configuration

The test pointed upsmon’s notification command at upssched and set two rules in upssched.conf:

AT ONBATT * START-TIMER onbatt-shutdown 10
AT ONLINE * CANCEL-TIMER onbatt-shutdown

When the timer fires, upssched runs a small script, which calls upsmon -c fsd to start the same forced shutdown that low battery would. A real system would use several minutes; 10 seconds kept the test short.

A short outage

The status was set to OB and, five seconds later, back to OL. Fourteen seconds after that, nothing had happened: no script call and no shutdown. The ONLINE event had cancelled the timer before it ran out. A flicker, a brief brownout or a generator switching over will not shut the server down.

A long outage

The status was set to OB at 08:06:45 and left there. The timer script ran at 08:06:59, fourteen seconds later: up to two seconds of polling before upsmon noticed, then the ten-second timer, then a moment for the script. The forced shutdown followed, and the shutdown command ran at 08:07:02, three seconds after that, set by the same FINALDELAY.

The battery charge in the simulated file never dropped below 100% during this test. The shutdown happened purely because of time spent on battery, which is the point: the server shuts down cleanly while the UPS still has plenty in reserve.

Choosing the numbers for a real server

How long to wait

The right timer depends on two measurements: how long the UPS really runs at the server’s load, and how long the server takes to shut down cleanly. The simulated UPS reported 1,800 seconds of runtime at 35% load; a real one reports its own estimate in battery.runtime, readable with upsc. A common approach is to wait long enough to ride out ordinary short outages, then leave at least twice the measured shutdown time in the battery.

Test it without pulling the plug

The test above can be repeated on a real system without risk by temporarily pointing NUT at the dummy driver, or by running upsmon -c fsd deliberately during a maintenance window and timing the shutdown. A real pull-the-plug test is still worth doing once, with backups current. The x9m8 guide to the 3-2-1 backup rule covers why a UPS is not a substitute for them.

Protecting the disks

A clean shutdown matters most for storage. Drives that lose power mid-write can corrupt files or file systems, and repeated hard power losses show up in drive health counters. The x9m8 guide to checking disk health with smartctl explains how to read those counters.

An alarm clock on a wooden table at night

Hardware notes

What to look for in a UPS

A UPS for a home lab needs a data connection NUT can read, usually USB, and enough capacity for the equipment’s real draw. Sine-wave output is often recommended for computer power supplies with active power factor correction. One widely sold example:

As an Amazon Associate I earn from qualifying purchases. A commission may be earned if you buy through this link, at no extra cost to you.

One UPS, several machines

When a NAS, a router and a server share one UPS, only one machine can hold the USB cable. That machine runs upsmon as primary; the others run upsmon as secondary, connecting to the primary’s upsd over the network. When the primary sets FSD, the upsmon manual notes that a secondary “immediately invokes the local shutdown command” once the UPS goes critical, and the primary waits for its secondaries before shutting itself down.

The configuration lines that matter

On the primary, the monitoring line in the test read MONITOR myups@localhost 1 monuser testpass primary: the UPS name and server, the number of power supplies that UPS feeds in this machine, a NUT user defined in upsd.users, and the role. A secondary uses the same line with the primary’s address in place of localhost and secondary at the end, and the primary’s upsd.conf must listen on an address the secondary can reach instead of only 127.0.0.1. The user name and password in that line are NUT’s own, not a system login, and are best given a value used nowhere else, since they travel over the local network.

Keep the network powered

Secondaries learn about the outage over the network. If the switch between them and the primary is not on the UPS, they lose contact the moment the power fails and cannot be told to shut down. The switch belongs on a battery-backed outlet along with the servers.

Sources

  • Network UPS Tools, upsmon(8): https://networkupstools.org/docs/man/upsmon.html
  • Network UPS Tools, upsmon.conf(5): https://networkupstools.org/docs/man/upsmon.conf.html
  • Network UPS Tools, upssched(8): https://networkupstools.org/docs/man/upssched.html

920 Posts

Peter Kalafatis writes and edits X9M8. He holds a bachelor's degree from LIU Post and a master's in Media Studies from The New School, with academic work in the philosophy of science, human behavior, AI, and memetics.

View All Posts

Leave a Reply

Your email address will not be published. Required fields are marked *