UPS monitor/shutdown service
I have messed around with NUT to trigger a graceful shutdown of my home server running Ubuntu Server. I have struggled with setting NUT up on bare metal, but would like a gui anyway. I saw PVE-UPS which looks good, but I think but I think it is meant for Proxmox. Any alternatives, or a spin of PVE-UPS for docker compose anybody know about?
I was hoping to setup a server and clients to shutdown the other Raspberry Pis and such, scattered around the house if the main server senses a power failure.
Also, I had an issue where it insisted on triggering a shutdown the SECOND the UPS triggered, even if it came right back. I might take another swing at it at some point, but I liked the look of that PVE-UPS things.
A basic NUT configuration does an immediate shutdown as soon as an ONBATT status is reached (upssched.conf has “at ONBATT execute…”, which causes the upssched-cmd to run the shutdown command immediately). But you can change that to a timer, which can be cancelled if the UPS goes back online, or only shutdown at LOWBATT.
It’s complicated, but NUT should be able to do everything you have stated as a goal. But it takes some testing.
One thing I found helpful while setting it up is the Dummy UPS driver that is included in the documentation. Rather than plug and unplug a physical UPS during testing you can make text files with various ups statuses and cp one to the dummy’s input file target to make it change to battery power or back online. Use logger to log information into the system journal from upssched-cmd to see what’s running in your script (with a unique keyword to grep on). Monitor in another terminal with
journalctl -f | grep yourkeywordto view your messages. This made it much easier to get the upssched stuff sorted out.One of my goals was unattended power-on management for when I was away from home. If power returned for an amount of time, send power commands to various smart outlets to bring everything back up in sequence. So I used a pretty big upssched-cmd, with timers for both shutdown and power up and different UPS battery levels (no power up until 30% battery, for example). It would have been pretty difficult to debug without the dummy UPS.
Anyway, NUT is really powerful.
Thanks. Good info. Feel like sharing your conf file to see how it’s formatted in an example that actually works? Might make this my weeks evening project.
It’s a lot. But here are my most recent notes.
Note that the pipe & lock locations different by distro, as does the nut username. So these files won’t drop in and work anywhere.
The dummy driver will need to be installed and configured.
Mine also have several layers of timers on battery an online:
Most configs would have the client side cancel their timers if power returns. In my case I don’t want that because I prefer more certainty of state so that I know it’s safe to power cycle an outlet to bring a device back up. My NUT server runs on an old pi 3b with a read-only file system. So it never needs a safe shutdown. It’s the last man standing to bring everything else back up if the UPS returns to line power before the battery is exhausted. That’s why there is no local shutdown on the NUT server config.
Each
snmpset…is a truncated version of an outlet power command.Also, the wall commands were a debug aid. Uncomment to use, but test a command first. Wall doesn’t work on some distros.
NUT Server
NUT.CONF:
MODE=netserverUPS.CONF:
UPSD.CONF:
UPSD.USERS:
UPSMON.CONF:
UPSSCHED-CMD
NUT Client
NUT.CONF
MODE=netclientUPS.CONF
maxretry = 3UPSD.CONF
# emptyUPSD.USERS
# emptyUPSMON.CONF
UPSSCHED.CONF
UPSSCHED-CMD
On clients you mostly have to set
MODE=netclientin thenut.confand modify theupsmon.confaccording to the manual and detailed manual. By default, it should only shutdown systems when reaching a “low battery” situation, not immediately when switching to battery power.