upsd: UPS monitoring daemon

Quick links

Introduction

upsd is a small daemon that monitors an UPS, Uninterruptable Power Supply unit attached to your host, and reacts to various events such as lost of input power, battery failure and the like. It can shut down your machine for example.

This is a project similar to NUT project, but is much simpler/smaller and has more control (and simpler control, too) over the various things.

Currently it can monitor a single UPS attached to a given host, but network control is planned (since it's quite common to have single UPS for several hosts). It is also designed to support more than one UPS for a single host (think redundrand power supplies), but this functionality isn't implemented.

Supported hardware

upsd supports the following hardware:

upsd is designed so that it is relatively easy to add support for other hardware.

Usage

upsd communicates with the UPS and executes an external command if some significant event occurs (most obvious is the lost of input power, when the UPS switches to battery mode). Usually communications are done over a serial (COM) port, but recently more and more UPS vendors started producing models that works over USB port (not yet supported). Another option is to run several computers on a single UPS, in which case only one computer is connected to the control port of the UPS, and all the rest communicate with the first one over network (not yet supported).

It is trivial to write "event handler" using shell command language for example, and upsd package comes with a ready-to-use (on some systems anyway) example script.

In order to shut the system down properly, the scripts should be able to plug in to the very end of the shutdown process. The problem is that when the system is ready to turn the power off, it should notify UPS that it's safe to turn itself off too, or else UPS will continue to work and will discharge battery.

Even more, modern computers are able to turn themselves on when the input power restores (usually it's an option in BIOS). For servers which are running 24x7 for example, when we shut down due to lost power, it's essential to come back when the power restores - for this to work, UPS should turn itself off BEFORE the system will be switched off. But not all computers are 24x7 servers, and in certain cases there's no need to turn the computer back on after power returns.

On the other hand, in case of real user-triggered system shutdown, UPS monitoring software should turn the UPS off as well, without restoring everything when power returns (which not goes off in this case).

Another interesting point here is that modern operating systems are able to save all the state to disk and suspend all operations (hibernation). This can be used instead of shutdown if supported.

Note that upsd should trigger the UPS shutdown at the very last point of shutdown process, when all the processes has been terminated and all the filesystems has been unmounted. At this stage, there's no place where to save information about what exactly to do (allow system to be turned off before the UPS or UPS before the system; order UPS to turn back on when power returns etc). In case of hibernation, no external processes are invoked at all (it's done in the kernel), so there's no way to control the UPS.

Due to all this, real integration may turn out to be quite difficult and is definitely very system-specific. In many cases it is sufficient to just turn the system off and don't touch the UPS - when system is turned off, UPS battery isn't discharged that much, and the system is in a safe state. Sure that in this case there's no way to turn the system back on when the power returns (think of 24x7 servers), but it's still far better than to lose power and battery at an unexpected time and lose your data as a result. I know no other UPS monitoring package for Unix that does all the steps here, but basic steps are done by most of the available packages.

Download

The software is released under the GPL license version 3 or any later version.

See this directory for actual software.

Contacts

upsd is written by Michael Tokarev (so far), my email is mjt+upsd {atte} corpit {dotte} ru.

Please drop me a note if you have some information about hardware, some ideas, suggestions, patches, corrections and the like. Especially welcome is the information about whenever upsd works or not with a given hardware -- please collect as much information as possible.

Drop me a note if you think that it's worth the effort to set up a mailinglist for all this stuff.


Return to my software page.