Bob Hauck |
Software and Systems Engineering Merrimack, NH |
upsd -- UPS monitor daemon.
/sbin/upsd [options] serial-device | host-name
Upsd is a daemon process that sits in the background and
monitors the state of the DCD and CTS lines of the speci-
fied serial device. These lines are to be connected to a
UPS (Uninterruptible Power Supply) so that the computer
can monitor the state of the UPS. The DCD line monitors
for a power fail condition, while CTS monitors for a low
battery condition. RTS may be optionally used to shut
down the UPS, if that feature is supported by the UPS.
CTS and RTS may be left unconnected if the UPS does not
support the corresponding features.
Upsd can also run in slave mode. In this mode, upsd polls
another copy of itself running on a remote host. This can
be used to give a controlled shutdown capability to all of
the hosts on a network, even ones which do not have a
hardwired monitor connection to the UPS.
When upsd senses that the power is failing, it notifies
init(8), which will execute the powerwait and powerfail
entries in /etc/inittab. If upsd senses that the power
has been restored, it notifies init again and init will
execute the powerokwait entry.
Upsd uses the syslog(2) facility for status reporting when
running as a daemon.
serial-device
Some serial port that is not being used by another
device, and does not share an interrupt with any
other serial port. Not valid with -s.
host-name
A host name or IP address. Only valid if the -s
option is used.
-c count
Wait count poll intervals before shutdown. The
default is 2. This option is intended to prevent
users on the system from being bothered by alerts
caused by short power glitches. It should probably
be set to 0 (signal right away) on slave machines.
-h Print a short usage message and exit.
Set the poll interval to time seconds. Default is
10 seconds. This should probably be shorter on the
master machine and longer on the slaves. Times
less than 0 are interpreted to mean that upsd
should get the UPS status and exit immediately
(this is useful in a "halt" script). The UPS sta-
tus is returned in the exit code.
-k Kill the UPS power. Most brands of UPS will honor
this signal only if they are running on battery
power. Causes RTS to go high for 5 seconds.
-l Don't shut down until a low battery indication
appears. Should only be used on standalone
machines, and only with init set up for immediate
shutdown. On battery indications will still be
logged, but won't cause a shutdown.
-m Disable master mode. Do not respond to polls from
slave machines. Do not listen on a TCP port. Do
monitor the UPS and signal power failures to init.
This mode is intended for standalone machines.
-p port
Listen on port in master mode, try to contact port
for updates in slave mode. Default is port 401.
-s Run in slave mode. Poll a master host for UPS sta-
tus. The host name or IP replaces the device name
on the command line if this flag is specified.
-t Test mode. Do not become a daemon, do not send
SIGPWR to init. This mode is intended for testing
your setup.
Normally, upsd does not return status codes, because it
does not exit. If upsd does exit abnormally, it will
return a status of 1. If killed by SIGTERM, it will
return a status of 0. If upsd is run with a poll interval
(-i) value less than zero, it will get the UPS status and
exit. The return codes are as follows:
100 Power is OK.
101 UPS is on battery, but the battery is ok.
102 UPS is on battery, and the battery is low.
103 There was a UPS connection error. Cound not con-
tact the host (in slave mode), or the monitor cable
is disconnected (in master mode).
Upsd regularly checks the DSR line to see if it is high.
DSR should be directly connected to DTR and upsd keeps
that line high, so if DSR is low then something is wrong
with the connection. Upsd will notify you about this
fact. When it sees that the connection has been restored
it will say so.
It's pretty simple to connect your UPS to a Linux machine.
The steps are as follows:
1. Make sure you have an UPS with a simple relay out-
put; it should close its connections (make) if the
power is gone, and it should open its connections
(break) if the power is good.
2. Buy a serial plug. Connect the DTR line to the DSR
line directly. Connect the DTR line and the DCD
line with a 10 kOhm resistor. Connect the CTS line
and the DTR line with another 10 kOhm resistor.
Now connect the (normally open) ON BATTERY relay of
the UPS to the DCD line and the (normally open) LOW
BATTERY relay to the CTS line. Connect the RTS
line to the SHUTDOWN input on the UPS. Connect the
return side of the relays to GROUND.
3. You're all set. It is also safe to use this setup
with a UPS having open collector outputs, like the
APC SmartUPS v/s series, but be very careful to not
exceed the current limit of the output transistors.
It is possible, though unlikely, that you may need
to increase the resistor values for some units.
/etc/inittab
Control file for init(8).
/etc/powerstatus
Power status file read by init(8) after receiving
SIGPOWER.
No way to specify the polarity of the SHUTDOWN signal
(always goes high for shutdown). Could probably handle
connection errors better. There's probably a standard for
UPS monitoring on a network somewhere, but if so I don't
know about it.
shutdown(8), init(8), inittab(5).
Bob Hauck