Linux, a UPS, and a cellphone

| | Comments (1)
I have a Back UPS 500 CS using a usb cable (model 940-0127A). It provides about 10 minutes of battery power to my router, switch, wap, cable modem, and server. It's connected via usb to the server.

I used apcupsd version apcupsd 3.10.3. Actually I installed the debian package which is old enough to not support usb. Then I hand copied my compiled apctest, apcaccess, apcupsd, man pages, and created a new /etc/apcdupsd/apcupsd.conf over writing the debian ones. The debian/apcupsd frame work works fine with the new binaries and they now support usb. You'll need the usb-core, usb-[ohci/uhci], hid, and input modules available to the kernel. There's a page on the apcupsd site that describes compiling for usb.

Like I said the framework pretty much works out of the box. Here's a copy of my /etc/apcupsd/apcupsd.conf file


UPSCABLE usb
UPSTYPE usb
DEVICE /dev/usb/hid/hiddev[0-9]
LOCKFILE /var/lock
BATTERYLEVEL 5
MINUTES 5
TIMEOUT 0
ANNOY 300
ANNOYDELAY 60
NOLOGON disable
KILLDELAY 0
NETSERVER on
NISIP 0.0.0.0
NISPORT 6543
EVENTSFILE /var/log/apcupsd.events
EVENTSFILEMAX 10
UPSCLASS standalone
UPSMODE disable
STATTIME 0
STATFILE /var/log/apcupsd.status
LOGSTATS off
DATATIME 0

I also edited the /etc/apcupsd/onbattery /etc/apcupsd/mainsback files to change the email from root to my cellphone.


#!/bin/sh
#
# This shell script if placed in /etc/apcupsd
# will be called by /etc/apcupsd/apccontrol when the UPS
# goes on batteries.
# We send an email message to root to notify him.
#
SYSADMIN=cell@provider.com
MAIL="/usr/bin/mail"

HOSTNAME=`hostname`
MSG="$HOSTNAME Power Failure !!!"
#
(
   echo "$MSG"
   echo " "
   /sbin/apcaccess status
) | $MAIL -s "$MSG" $SYSADMIN
exit 0

#!/bin/sh
#
# This shell script if placed in /etc/apcupsd
# will be called by /etc/apcupsd/apccontrol when the
# UPS goes back on to the mains after a power failure.
# We send an email message to root to notify him.
#
SYSADMIN=cell@provider.com
MAIL="/usr/bin/mail"

HOSTNAME=`hostname`
MSG="$HOSTNAME Power has returned"
#
(
   echo "$MSG"
   echo " "
   /sbin/apcaccess status
) | $MAIL -s "$MSG" $SYSADMIN
exit 0

So basically if the power goes out. I get a page on my cellphone. The system will shutdown if the battery gets to 5% or the ups' projected time remaining is 5 minutes (whichever comes first). If the power returns before either of those conditions then I get a page on my cellphone.

Normally the last thing the system should do when shutting down becuase of low battery power is turn off the UPS! This cuts power to the computer. This way the "Always On" setting in your CMOS will return the computer turn on your computer when the power's back. But the usb code for shuting down the ups is broken in apcupsd. They are working on it.

Consequently there is a short window of time that if the power were to return my computer would still be powered on but shutdown. It would then require reboot by hand.

But if the power stays off long enough for the battery in the ups to run out then the ups will turn off. Cutting power to my equipment. When the power returns the equipment and server will turn on.

my ups' battery lasts a lot longer without a server on it. So I either want a short power outage (less than 10 minutes) or a long one (more than 5 minutes). Becuase if the power returns during last 5 minutes of battery life then my computer stays shutdown

Also, the UPS only polls the usb every so often. So after module load at boot time a fast computer can start apcupsd before the ups has polled and an hid device is registered with the kernel. This will cause your computer startup and hardlock (use alt-prtscr tricks to reboot). I added a 10 second pause right before apcupsd in its init script to get around this.

1 Comments

here's the list of files that debian installs. * are files I replaced from the source distro or edited

/sbin/apcupsd*
/sbin/apcaccess*
/sbin/apctest*

/etc/logrotate.d/apcupsd*
/etc/init.d/apcupsd*
/etc/init.d/ups-monitor
/etc/apcupsd/apccontrol
/etc/apcupsd/apcupsd.conf*
/etc/apcupsd/changeme
/etc/apcupsd/commfailure
/etc/apcupsd/commok
/etc/apcupsd/onbattery*
/etc/apcupsd/mainsback*
/etc/apcupsd/hosts.conf
/etc/apcupsd/multimon.conf
/etc/cron.daily/apcupsd

/usr/lib/cgi-bin/apcupsd/upsstats.cgi
/usr/lib/cgi-bin/apcupsd/upsfstats.cgi
/usr/lib/cgi-bin/apcupsd/upsimage.cgi
/usr/lib/cgi-bin/apcupsd/multimon.cgi
/usr/lib/cgi-bin/apcupsd/multimoncss.cgi

/usr/share/man/man8/apcupsd.8.gz*