deniz.in

Markets

Weather

Loading weather

· via Hacker News – Front Page (native)

Guide walks through Network UPS Tools setup so Linux servers shut down cleanly on battery

A linuxjunkies.org guide that reached Hacker News's front page explains how to configure Network UPS Tools so a Linux machine shuts down cleanly before its UPS battery runs out.

Guide walks through Network UPS Tools setup so Linux servers shut down cleanly on battery

A configuration guide published on linuxjunkies.org and upvoted to Hacker News's front page addresses a reliability gap that shows up in many home labs and small server rooms: an uninterruptible power supply that nothing on the host is actually watching. According to the guide, the hardware will carry a machine through an outage, but without monitoring software the system still dies abruptly once the battery empties. The recommended fix is Network UPS Tools (NUT), an open-source project that supports hundreds of UPS models and can trigger a clean shutdown before the charge is gone.

Three components on one host

The guide opens by breaking NUT into its moving parts. A daemon called upsd reads data from the UPS and serves it over a socket. A monitor process, upsmon, watches that data and runs the shutdown command when the battery reaches a critical level. Between them sits a per-model driver — the binary that actually talks to the hardware over USB, serial or SNMP. In the single-machine scenario the guide targets, all three run on the same host, with the UPS most often attached over USB.

Installation and device detection

Packages exist across the major distributions: apt on Debian and Ubuntu installs the nut, nut-client and nut-server packages, dnf installs nut on Fedora, RHEL 9 and Rocky Linux with the server and client components bundled together, and pacman covers Arch. In every case, configuration files land in /etc/nut/.

Detection comes next. Running nut-scanner with root privileges probes the buses and prints a block identifying the driver, port, USB vendor and product IDs, and model name. That block gets pasted into ups.conf under a short name for the device. Including the vendor and product IDs is recommended, the guide notes, because it prevents NUT from grabbing the wrong USB device if several UPS units are ever connected.

Driver choice matters: usbhid-ups handles most USB HID-compliant units from vendors such as APC, Eaton and CyberPower, blazer_usb covers many budget units and rebrands, and nutdrv_qx targets Q-series protocol hardware. The project's hardware compatibility list maps specific models to drivers.

Wiring up the shutdown path

A small file, nut.conf, declares the host's role. MODE=standalone covers the one-machine case; netserver is reserved for setups where other machines monitor the same UPS over the network. For a standalone install, upsd is configured to listen on loopback only, and upsd.users must define at least one account with upsmon master privileges. The guide stresses picking a real password and tightening the file's permissions with chmod and chown, since the credential sits in plain text even when the listener never leaves localhost.

upsmon.conf holds the line that ties everything together: a MONITOR entry naming the UPS, host, power value, credentials and role, followed by the shutdown command, notification flags for events like switching to battery or losing communication, and polling intervals. Two values are worth checking before the services start: MINSUPPLIES should be 1, and the UPS should already report being on mains power. If NUT cannot reach the UPS at startup, the guide warns, it may treat the machine as having lost its supply and shut it down immediately.

Testing and common failure modes

Once the services are enabled — unit names vary between distribution families — the upsc client dumps live variables from the device. The guide highlights ups.status (OL for mains power, OB for on battery, LB for low battery), battery.charge and battery.runtime. A safe end-to-end test is to pull the UPS's mains plug and watch the status flip to OB in a looping query, without ever reaching a real shutdown.

The troubleshooting section covers the failures that come up most often: USB permission errors resolved by the udev rule shipped with the package, a "Driver not connected" error traced through journalctl to a wrong driver value or a typo in the UPS name, and COMMBAD warnings that point to upsd being unreachable or to credentials that do not match exactly, including letter case.

Why it matters

Plenty of people buy a UPS and assume the job is done. Without software bridging the battery and the operating system, an outage merely postpones a hard crash by however long the charge lasts — and hard crashes on machines with databases, NAS volumes or in-flight writes are how filesystems get corrupted. NUT closes that gap with a lightweight, hardware-agnostic daemon stack that runs on a single host, and the standalone setup described here is the configuration most home labs and small servers actually need. The guide's popularity on Hacker News suggests this is a well-trodden yet frequently missed piece of operational hygiene, and one that pays for itself the first time the power flickers.

  • #linux
  • #open-source
  • #sysadmin
  • #ups
  • #power-management

Related posts