1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
bpowerd v2.0
Author: Christopher Craig <ccraig@cc.gatech.edu>
Copyright: This program is released under the GNU Public License
================
What is it? |
================
bpowerd is a program to monitor Best Power Patriot and Patriot Plus UPSs under
Linux. It uses init to inform the system of a power outage and is capable of
detecting power fail and low battery conditions. It is also capable of
killing the inverter on shutdown.
There are two ways this can happen, which one you use depends on which init
was detected by the configure program:
=================
How does it work|
=================
----------------+
The BSD init way|
----------------+
The following is the steps taken in the event of a powerfail
1) bpowerd detects failure and writes FAIL to /etc/powerstatus and either
FAIL or SCRAM to /etc/upsstatus for a power failure or low battery condition
respectively.
2) bpowerd signals init with SIGPWR
3) init executes the command in the line starting with "pf", this should be
a call to bpowerfail with the "start" argument
4) bpowerfail executes the command associated with the state in /etc/upsstatus
If the power comes back on "OK" is written to both /etc/upsstatus and
/etc/powerstatus and init is signaled. init then runs the command on the line
starting with "pg" which should be a call to bpowerfail with the "stop"
option. bpowerfail then halts all running shutdowns.
-------------------+
The Sys V init way |
-------------------+
1) bpowerd detects a state change and sends a struct with the power status
to /dev/initctl
2) init executes the appropriate line from the /etc/inittab
3) bpowerfail executes the command associated with the argument passed it
by init
===============
Shutting Down |
===============
There are three ways to shut down.
1) Kill bpowerd with SIGTERM: this will cleanly kill bpowerd and remove it
from memory.
2) Kill bpowerd with SIGINT: this will kill bpowerd and kill the inverter if
there is a powerfail. This is normally used in system shutdown scripts
3) Kill bpowerd with SIGKILL: This is a Very Bad Thing. This will immediately
remove bpowerd from memory with out first closing the ups port. Consequently
you will have to reboot before you can restart bpowerd
Furthermore there are two ways to shutdown the system and kill the inverter if
appropriate.
1) Kill bpowerd with SIGTERM and then run 'bpowerd -k' if the inverter should
be killed (this is rather easy on BSD systems since you have yucky state
files, but it is quite difficult on SysV systems)
2) Kill bpowerd with SIGINT and let it kill the inverter if appropriate (This
is what I do and I use the function
kill -INT `/sbin/pidof bpowerd`
while [ "`/sbin/pidof bpowerd`" != "" ]; do
sleep 1;
done
to make sure it waits for the daemon to shutdown.
=========
Cables |
=========
This is a schem for the cable that Best provides for the UPS, so if you want
to make your own here you go:
All: \/\/\/ = Resistor (3.3K)
UPS pin 1 Shutdown
UPS pin 3 Inverter
UPS pin 4 common
UPS pin 5 Low Runtime
DB-9 (UPS) DB-9 (Computer) DB-25 (Computer)
1 ------------------------------------------------- 4 ---------- 20
+--\/\/\/----------- 2 ---------- 3
|
3 -----------------------------+--\/\/\/----------- 3 ---------- 2
4 ------------------------------------------------- 5 ---------- 7
5 -----------------------------+--\/\/\/---+------- 1 ---------- 8
| |
| +------- 6 ---------- 6
+--\/\/\/----------- 7 ---------- 4
Mitch Blevins <mblevin@debian.org> writes in that "[He's] found that
Best will ship you a cable free of charge (www.bestpower.com) The Best part
number is INT-0027A."
==========
Credits |
==========
Thanks to
Best Power for their cooperation in giving me the schematics for thier control
line so that I didn't have to wait for it to get here.
Tom Webster, for writing genpowerd which I pulled heavily from
Mitch Blevins for work on the initctl interface
and
Jesus Christ for allowing me to live.
|