Next Previous Contents

5. Do it yourself guide

This discussion is specifically tailored for dumb UPS control. However, most of the process is about the same for dumb UPSs and smart UPSs. The biggest difference is in the details of how the UPS monitoring daemon (typically powerd) communicates with the UPS.

Before doing anything, I suggest the following algorithm:

5.1 What you need to do (summary)

5.2 How it's supposed to work

UPS's job

When the power goes out, the UPS continues to power the computer and signals that the power went out by throwing a relay or turning on an opticoupler on it's control port.

Cable's job

The cable is designed so that when the UPS throws said relay, this causes a particular serial port control line (typically DCD) to go high.

Powerd's job

The powerd daemon monitors the serial port. Keeps raised/lowered whatever serial port control lines the UPS needs to have raised/lowered (typically, DTR must be kept high and whatever line shuts off the UPS must be kept low). When powerd sees the UPS control line go high, it writes FAIL to /etc/powerstatus and sends the init process a SIGPWR signal. (Older versions of powerd and initd wrote to /etc/powerfail.) When the control line goes low again, it writes OK to /etc/powerstatus and sends init a SIGPWR signal.

Init's job (aside from everything else it does)

When it receives a SIGPWR, it looks at /etc/powerstatus. If it contains FAIL it runs the powerfail entry from /etc/inittab. If it contains OK it runs the powerokwait entry from inittab.

5.3 How to set things up

The following presupposes that you have a cable that works properly with powerd. If you're not sure that your cable works (or how it works), see section Reverse-engineering cables and hacking powerd.c for information on dealing with poorly described cables and reconfiguring powerd.c. Sections Serial port pin assignments and Ioctl to RS232 correspondence will also be useful.

If you need to make a cable, see section How to make a cable for the overall details, and the subsection of section Info on selected UPSs that refers to your UPS. The latter might also include information on manufacturer supplied cables. You may want to at least skim all of section Info on selected UPSs because each section has a few additional generally helpful details.

Congratulations! You now have a Linux computer that's protected by a UPS and will shutdown cleanly when the power goes out!

5.4 User Enhancements

Next Previous Contents