The following presupposes that you have a cable that works properly
with powerd.c. 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'll probably want to read all of section Info on selected UPSs because each section has afew additional generally helpful details.
/etc/inittab
. Put in something like this:
# What to do when power fails (Halt system & drain battery :): pf::powerfail:/etc/powerfailscript +5 # If power is back before shutdown, cancel the running shutdown. pg:0123456:powerokwait:/etc/powerokscript
/etc/powerfailscript
and
/etc/powerokscript
to shutdown in 5 minutes (or whatever's
appropriate) and kill any existing shutdown, respectively.
Depending on the version of shutdown that you're using, this will
be either so trivial that you'll dispense with the scripts, or be a
1 line bash script, something along the lines of:
kill `ps -aux | grep "shutdown" | grep -v grep | awk '{print $2}'`and you'll keep the scripts. (In case it doesn't come out right, the first single quote on the above line is a backquote, the second and third are single quotes, and the last is also a backquote.)
telinit q
powerd <line>Replace
<line>
with the serial port that the modem
is connected, such as /dev/cua1
.
/etc/powerfailscript
runs./etc/powerokscript
runs./etc/powerfailscript
is not running.Congratulations! You now have a Linux PC that's protected by a UPS and will shutdown cleanly when the power goes out!