BACKGROUND:
It all started last summer when the annual, unexplained micro-outages began rolling through my neighborhood again: my entire residence would lose power for roughly .5 seconds at exactly the same time each morning. These outages were nothing the coffee maker and VCR couldnt handle, but they proved just enough to bounce every single one of my machines. Annoying.
I purchased a couple APC UPS units (a Back-UPS CS350 for my routers, and a Back-UPS XS1000 for my two antediluvian servers) to solve the problem. Both ran in dumb mode for months, i.e. there was no communication between the UPS and the machines they supported, no automated system shutdown in the event of complete battery exhaustion. UPS plugs into wall, stuff plugs into UPS, done. This setup allowed me to weather the outages of late summer in style and I wasnt too concerned about the lack of features
Needless to say, the winter months have been less forgiving to the local power supply. After two outages that left both batteries completely drained (one of which found me dancing around some minor flooding, frantically performing manual shutdowns on my machines) I decided I needed something a bit more robust. After some research, apcupsd seemed the obvious choice, so I set about implementing it on my newly-minted Gentoo systems. The following was born from my experiences doing so, and the dearth of any comprehensive Gentoo-specific documentation on the subject. I infer from the latter that there are either quite a few UPS units running in dumb mode on Gentoo installations, or Im just the ass that couldnt get this to work out of the box. In either case, I figure this cant hurt.
A few things you ought to know before we get started
OBJECTIVES:
By the time youve gone through all this, you should have:
- USB support for your APC UPS.
- Power management support allowing apcupsd to completely poweroff the system (rather than simply halting it, requiring a manual poweroff at the mains).
- Functionality allowing apcupsd to control and monitor multiple systems over Ethernet in a master/slave configuration.
- The ability to monitor the status of your UPS with apcupsd via your favorite browser.
This HOWTO assumes the following:
- You own an APC UPS attached via the supplied USB cable to a Gentoo installation. I dont know anything about other cables, non-APC products, other Linux distributions, the UPS with the bad smell your brother found in the parking lot, etc. La-la-la, I cant hear you
- You will be performing these operations on an x86-based system however, I have at least one report of this HOWTO functioning for AMD64 systems.
- Your master and slave machines will both be running some version of Gentoo. If youre mixing your operating systems, Id be interested to hear what was necessary to adapt these procedures.
- You are familiar with the procedures and potential consequences of recompiling your own kernel.
- You already have Apache configured and running on the system that will act as the master for apcupsd (namely the one the USB cables plugged into). If youre not interested in the browser status aspect of this HOWTO, feel free to ignore this.
- You understand enough about networking protocols (and your own network) to be dangerous.
- You can use a text editor.
DISCLAIMERS, CAVEATS, ETCETERA:
- I am in no way, shape, or form associated with APC, the apcupsd project, or much of anything else.
- I am frequently wrong.
- The following procedures worked for me on my hardware this week. YMMV.
- You will reboot your machine(s). Kiss that uptime goodbye for the time being.
- This HOWTO is not a substitute for reading and understanding the extensive documentation in the apcupsd Users Manual. I just bumped my head on a few things trying to implement the procedures outlined therein.
- apcupsd runs as root. These procedures are for home networks that have been properly secured against external factors where you trust every machine on your network and every person in your place of residence. Having someone else arbitrarily poweroff your systems sort of defeats the purpose of owning a UPS, wouldnt you say?
KERNEL CONFIGURATION:
The first thing well need to do is recompile our kernel to support both USB and ACPI or APM on the system that will act as the master installation. If you dont know whether your machine supports APM or ACPI, reboot and go root around in your BIOS options (usually under Power Management oddly enough). If you see something like Enable ACPI [y/n]? you know what youve got and what the response to that [y/n] should be. The rule seems to be that pre-millennium boards use APM, more recent hardware uses ACPI. Just make a note of which youre using for now; well come back to it momentarily.
One more thing: if youre using ACPI, you may want to add it to your USE settings in /etc/make.conf. I didnt and lived to tell the tale, but its up to you.
A NOTE ON POWER MANAGEMENT: Since this guides inception, Ive received several reports indicating that neither APM nor ACPI is necessary for some systems to successfully perform an unassisted shutdown. If your system already handles its power management needs to your satisfaction, Id advise not changing anything; if you run into problems you can always come back here and follow the steps below. If it isnt broken
Now, drop into a console, su to root, and grab your favorite kernel sources:
Code: Select all
# cd /usr/src/linux; make menuconfigCode: Select all
General setup --->
[*] Power Management support
< > Advanced Power Management BIOS support
ACPI Support --->
[*] ACPI Support
< > AC Adapter
< > Battery
<M> Button
< > Fan
<M> Processor
< > Thermal Zone
< > ASUS Laptop Extras
< > Toshiba Laptop Extras
[ ] Debug Statements
[ ] Relaxed AML CheckingCode: Select all
Power management options (ACPI, APM) --->
[*] Power Management support
[ ] Software Suspend (EXPERIMENTAL)
[ ] Suspend-to-Disk Support
ACPI (Advanced Configuration and Power Interface) Support --->
[*] ACPI Support
[ ] Sleep States (EXPERIMENTAL)
<*> AC Adapter
<*> Battery
<*> Button
< > Fan
<*> Processor
< > Thermal Zone
< > ASUS/Medion Laptop Extras
< > Toshiba Laptop Extras
[ ] Debug Statements
[ ] Power Management Timer SupportIf youre using APM, youll probably want to disable ACPI support and try something like this for your 2.4 kernel:
Code: Select all
General setup --->
[*] Power Management support
<*> Advanced Power Management BIOS support
[ ] Ignore USER SUSPEND
[*] Enable PM at boot time
[ ] Make CPU Idle calls when idle
[ ] Enable console blanking using APM
[ ] RTC stores time in GMT
[*] Allow interrupts during APM BIOS calls
[*] Use real mode APM BIOS call to power off
ACPI Support --->Code: Select all
Power management options (ACPI, APM) --->
[*] Power Management support
[ ] Software Suspend (EXPERIMENTAL)
[ ] Suspend-to-Disk Support
APM (Advanced Power Management) BIOS Support --->
<M> APM (Advanced Power Management) BIOS support
[*] Ignore USER SUSPEND (NEW)
[ ] Enable PM at boot time (NEW)
[ ] Make CPU Idle calls when idle (NEW)
[ ] Enable console blanking using APM (NEW)
[ ] RTC stores time in GMT (NEW)
[*] Allow interrupts during APM BIOS calls (NEW)
[*] Use real mode APM BIOS call to power off (NEW)As a side note, Ive read that ACPI and SMP do not play well together. There are several threads about this on the forums, so I wont go into it just be advised that if youre running multiple processors or one of those new-fangled Pentiums with HT technology, this may be an issue for you.
Next, well get USB support set for our UPS (2.4 kernels first):
Code: Select all
USB support --->
<M> Support for USB
[ ] USB verbose debug messages
--- Miscellaneous USB options
[*] Preliminary USB device filesystem
[ ] Enforce USB bandwidth allocation (EXPERIMENTAL)
--- USB Host Controller Drivers
< > EHCI HCD (USB 2.0) support (EXPERIMENTAL)
< > UHCI (Intel PIIX4, VIA, ...) support
< > UHCI Alternate Driver (JE) support
<M> OHCI (Compaq, iMacs, OPTi, SiS, ALi, ...) support
< > SL811HS Alternate (x86, StrongARM, isosynchronous mode)
< > SL811HS (x86, StrongARM) support, old driver
--- USB Device Class drivers
< > USB Audio support
< > USB Bluetooth support (EXPERIMENTAL)
< > USB MIDI support
--- SCSI support is needed for USB Storage
< > USB Modem (CDC ACM) support
< > USB Printer support
--- USB Human Interface Devices (HID)
<M> USB Human Interface Device (full HID) support
--- Input core support is needed for USB HID input layer or HIDBP
[*] /dev/hiddev raw HID device support
< > USB HIDBP Keyboard (basic) support
< > USB HIDBP Mouse (basic) support
< > Aiptek 6000U/8000U tablet support
< > Wacom Intuos/Graphire tablet support
< > KB Gear JamStudio tablet support
< > Griffin Technology PowerMate supportCode: Select all
Device Drivers --->
USB support --->
<*> Support for Host-side USB
[ ] USB verbose debug messages
--- Miscellaneous USB options
[*] USB device filesystem
[ ] Enforce USB bandwidth allocation (EXPERIMENTAL)
[ ] Dynamic USB minor allocation (EXPERIMENTAL)
--- USB Host Controller Drivers
< > EHCI HCD (USB 2.0) support
<*> OHCI HCD support
< > UHCI HCD (most Intel and VIA) support
--- USB Device Class drivers
< > USB Audio support
< > USB Bluetooth TTY support
< > USB MIDI support
< > USB Modem (CDC ACM) support
< > USB Printer support
< > USB Mass Storage support
--- USB Human Interface Devices (HID)
<*> USB Human Interface Device (full HID) support
[*] HID input layer support
[ ] Force feedback support (EXPERIMENTAL)
[*] /dev/hiddev raw HID device support
< > Aiptek 6000U/8000U tablet support
< > Wacom Intuos/Graphire tablet support
< > KB Gear JamStudio tablet support
< > Griffin PowerMate and Contour Jog support
< > MicroTouch USB Touchscreen Driver
< > eGalax TouchKit USB Touchscreen Driver
< > X-Box gamepad support
< > ATI / X10 USB RF remote control
--- USB Imaging devices
< > USB Mustek MDC800 Digital Camera support (EXPERIMENTAL)
< > Microtek X6USB scanner support
< > HP53xx USB scanner support (EXPERIMENTAL)
--- USB Multimedia devices
< > DABUSB driver
--- Video4Linux support is needed for USB Multimedia device support
--- USB Network adaptors
< > USB CATC NetMate-based Ethernet device support (EXPERIMENTAL)
< > USB KLSI KL5USB101-based ethernet device support
< > USB Pegasus/Pegasus-II based ethernet device support
< > USB RTL8150 based ethernet device support (EXPERIMENTAL)
< > Multi-purpose USB Networking Framework
--- USB port drivers
USB Serial Converter support --->
--- USB Miscellaneous drivers
< > EMI 6|2m USB Audio interface support
< > EMI 2|6 USB Audio interface support
< > Texas Instruments Graph Link USB (aka SilverLink) cable support
< > USB Auerswald ISDN support (EXPERIMENTAL)
< > USB Diamond Rio500 support (EXPERIMENTAL)
< > USB Lego Infrared Tower support (EXPERIMENTAL)
< > USB LCD driver support
< > USB LED driver support
< > Cypress USB thermometer driver support
< > USB PhidgetServo support
< > USB testing driver (DEVELOPMENT)
USB Gadget Support --->Second, the Preliminary USB device filesystem is very important (as I found when I took my first swing at this project). I had neglected to build this in; the result gave me a seemingly functional installation with full communication between apcupsd and the UPS. I just couldnt get apcupsd to shutdown the machine, which I viewed as a rather important piece of functionality. Make sure its there.
Next, be sure to build the appropriate driver for your chipset. Mine is made by SiS, hence I use the OHCI driver if you use Intel or VIA, you need the UHCI driver. If you dont know what you use, do an Alt-F2 (or open a new console window, or whatever) and run:
Code: Select all
# /sbin/lspci vNote that I dont have anything else enabled in the way of printers, audio, Bluetooth thats because the UPS is the only USB device plugged into this system. Your needs may be different.
Thats it for the kernel. Hit Esc twice, and do the usual for 2.4 kernels:
Code: Select all
# make dep && make bzImage modules modules_install
# mount /boot/
# cp arch/i386/boot/bzImage /boot/kernel-<your-kernel-version-goes-here>
# cp System.map /boot/System.map-<your-kernel-version-goes-here>
# cp .config /boot/config-<your-kernel-version-goes-here>Code: Select all
# make && make modules_install
# mount /boot/
# cp arch/i386/boot/bzImage /boot/kernel-<your-kernel-version-goes-here>
# cp System.map /boot/System.map-<your-kernel-version-goes-here>
# cp .config /boot/config-<your-kernel-version-goes-here>Finally, this would be a good time to
Code: Select all
# emerge sync; emerge hotplug; rc-update add hotplug defaultRemember that whole master/slave thing about controlling two machines with one UPS? If youve got a standalone machine (one UPS controlling one machine) youre done if, however, youve got multiple machines on the same UPS youll want to head over to your slave machine at this point and make sure that it also has the appropriate power management built into its kernel. Whether you compile with USB support on the slave is up to you its not necessary for our purposes here, though.
If everything looks good, make sure your UPS is plugged in at both ends and reboot into your new kernel.
CHECKING YOUR USB SUBSYSTEM:
For a more detailed explanation, see the document from which this was shamelessly cribbed.
Basically, you just run:
Code: Select all
# cat /proc/bus/usb/devicesCode: Select all
T: Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=1.5 MxCh= 0
D: Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1
P: Vendor=051d ProdID=0002 Rev= 1.00
S: Manufacturer=American Power Conversion
S: Product=Back-UPS 350 FW: 5.2.I USB FW: c1
S: SerialNumber=BB0115017954
C:* #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr= 30mA
I: If#= 0 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=00 Prot=00 Driver=hid
E: Ad=81(I) Atr=03(Int.) MxPS= 8 Ivl= 10msAssuming that went according to plan, now would also be a good time to make sure our power management is working properly.
Code: Select all
# shutdown h nowGood so far? Then lets get apcupsd installed on our master machine.
INSTALLING AND CONFIGURING APCUPSD:
As usual, this is an absolutely painless process in Gentoo. Emerge apcupsd and set it to start automatically.
Code: Select all
# emerge sync; emerge apcupsd; rc-update add apcupsd defaultCode: Select all
# nano -w /etc/apcupsd/apccontrolCode: Select all
mainsback)
echo "Power has returned on UPS ${2}..." | wall
if [ -f /etc/apcupsd/powerfail ] ; then
printf "Continuing with shutdown." | wall
fi
;;
;;Code: Select all
mainsback)
echo "Power has returned on UPS ${2}..." | wall
if [ -f /etc/apcupsd/powerfail ] ; then
printf "Continuing with shutdown." | wall
fi
;;FAILURE TO DO THE ABOVE MAY RESULT IN REDUCED FUNCTIONALITY, SYSTEM HANGS, SPONTANEOUS DECAPITATION, ETC.
Now its time to start configuring our master installation:
Code: Select all
# nano -w /etc/apcupsd/apcupsd.confCode: Select all
## apcupsd.conf v1.1 ##
#
# for apcupsd release 3.10.9 (31 December 2003) gentoo
# sample master configuration file
UPSNAME <some-unique-string>
UPSCABLE usb
UPSTYPE usb
LOCKFILE /var/lock
ONBATTERYDELAY 6
BATTERYLEVEL 5
MINUTES 3
TIMEOUT 0
ANNOY 300
ANNOYDELAY 60
NOLOGON disable
KILLDELAY 0
NETSERVER on
NISPORT 3551
EVENTSFILE /var/log/apcupsd.events
EVENTSFILEMAX 10
UPSCLASS netmaster
UPSMODE net
NETTIME 10
NETPORT 6666
SLAVE <your-slave-machines-IP-address>
USERMAGIC <some-unique-string>
STATTIME 0
STATFILE /var/log/apcupsd.status
LOGSTATS off
DATATIME 0- For our purposes, both UPSCABLE and UPSTYPE must be set to usb in order to establish communication with the UPS.
- Youll notice that the DEVICE parameter does not appear here. Thats because its been commented out of my apcupsd.conf file. See this for the reason why.
- Youll also notice that NISIP does not appear here, as it has also been commented out. See this thread (again) for the reason why.
- The NETSERVER and NISPORT settings are crucial to obtaining status information from apcupsd. Make sure they appear as listed in the above file.
- UPSCLASS must be set to netmaster and UPSMODE must be set to net in order for this installation to act as the master. If youll be running the standalone configuration without a slave, see below.
- SLAVE is the IP address or FQDN of your slave machine.
- USERMAGIC is a basic form of authentication between the master and slave. Break out your favorite password generator and enter the results here. Make sure youve got it handy somewhere; youll need it again for the slave machines configuration file.
Code: Select all
## apcupsd.conf v1.1 ##
#
# for apcupsd release 3.10.9 (31 December 2003) gentoo
# sample standalone configuration file
UPSNAME <some-unique-string>
UPSCABLE usb
UPSTYPE usb
LOCKFILE /var/lock
ONBATTERYDELAY 6
BATTERYLEVEL 5
MINUTES 3
TIMEOUT 0
ANNOY 300
ANNOYDELAY 60
NOLOGON disable
KILLDELAY 0
NETSERVER on
NISPORT 3551
EVENTSFILE /var/log/apcupsd.events
EVENTSFILEMAX 10
UPSCLASS standalone
UPSMODE disable
STATTIME 0
STATFILE /var/log/apcupsd.status
LOGSTATS off
DATATIME 0- NETTIME, NETPORT, SLAVE, and USERMAGIC are no longer relevant and have been removed.
- UPSCLASS must be set to standalone and UPSMODE must be set to disable.
STARTING APCUPSD:
Its time to kick this thing in the guts and see if it runs. Start apcupsd manually with:
Code: Select all
# /etc/init.d/apcupsd startCode: Select all
* Starting APC UPS daemon... [ ok ]Code: Select all
# tail /var/log/messagesNOTE: Ive experienced problems with the apcupsd process going undead on me when it gets a bad start; attempts to stop it, kill it, or restart it are futile. If you get a bad start, youll need to do:
Code: Select all
# /etc/init.d/apcupsd zapANOTHER NOTE ON BAD STARTS: You may get an error message similar to the following:
Code: Select all
apcupsd FATAL ERROR in linux-usb.c at line 684
Cannot open UPS device:Code: Select all
# /etc/init.d/apcupsd zap
# tail -f /var/log/messagesNow it's time to test apcupsd for full functionality. We'll run through each of these tests in brief; for more detailed testing information, please refer to the invaluable-and-frequently-cited apcupsd User's Manual section on this subject.
ANOTHER NOTE: These tests are applicable for installations running apcupsd in both master and standalone modes. Standalone users should not see messages about apcupsd being unable to connect to its slave, but I doubt this will bother them much.
A FURTHER NOTE: During these tests, you may not get wall messages to your console; instead, you may see things like the following in /var/log/messages:
Code: Select all
Feb 10 15:36:17 <your-host-here> sSMTP[2626]: Unable to locate mail
Feb 10 15:36:17 <your-host-here> sSMTP[2626]: Cannot open mail:25
Feb 10 15:36:17 <your-host-here> wall[2630]: wall: user root broadcasted 1 lines (42 chars)ectospasm notes that you can drop the wall messages entirely (if they annoy you) by commenting out the WALL=wall variable in /etc/apcupsd/apccontrol, like so:
Code: Select all
#
# These variables are needed for set up the autoconf other variables.
#
prefix=/usr
exec_prefix=${prefix}
APCPID=/var/run/apcupsd.pid
APCUPSD=/usr/sbin/apcupsd
SHUTDOWN=/sbin/shutdown
SCRIPTSHELL=/bin/sh
SCRIPTDIR=/etc/apcupsd
# WALL=wallTESTING APCUPSD Process-Status Test:
Once you've got apupsd started, execute the following command:
Code: Select all
# ps faxCode: Select all
2429 ? S 0:00 \_ /usr/sbin/apcupsd
2430 ? S 0:00 \_ /usr/sbin/apcupsd
2431 ? S 0:00 \_ /usr/sbin/apcupsdTESTING APCUPSD Logging Test:
Now that we know the apcupsd processes are running, do a tail of your system log file:
Code: Select all
# tail /var/log/messagesCode: Select all
Feb 11 11:07:37 <your-host-here> apcupsd[2411]: apcupsd 3.10.9 (31 December 2003) gentoo startup succeeded
Feb 11 11:07:37 <your-host-here> apcupsd[2431]: NIS server startup succeeded
Feb 11 11:08:07 <your-host-here> apcupsd[2430]: Slave connection failed Connection refused! Down slave 0TESTING APCUPSD apcaccess Test:
Run the following:
Code: Select all
# apcaccess statusCode: Select all
APC : 001,027,0653
DATE : Wed Feb 11 11:12:37 EST 2004
HOSTNAME : <your-host-here>
RELEASE : 3.10.9
VERSION : 3.10.9 (31 December 2003) gentoo
UPSNAME : APC
CABLE : USB Cable
MODEL : Back-UPS 350
UPSMODE : Net Master
STARTTIME: Wed Feb 11 11:07:37 EST 2004
SHARE : NetworkUPS
STATUS : ONLINE
BCHARGE : 100.0 Percent
TIMELEFT : 43.0 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME : 30 Seconds
NUMXFERS : 0
TONBATT : 0 seconds
CUMONBATT: 0 seconds
XOFFBATT : N/A
STATFLAG : 0x02000008 Status Flag
MANDATE : 2003-05-15
BATTDATE : 2003-05-15
NOMBATTV : 12.0
FIRMWARE : 5.4.D USB FW: c1
APCMODEL : Back-UPS 350
END APC : Wed Feb 11 11:13:36 EST 2004If you see something resembling:
Code: Select all
attach_shmarea: shared memory version mismatch (or UPS not yet ready to report)TESTING APCUPSD Communications Test:
If everything's gone smoothly, we now need to ascertain whether the UPS and apcupsd are communicating properly. Do a running tail of the apcupsd events file:
Code: Select all
# tail -f /var/log/apcupsd.eventsCode: Select all
Wed Feb 11 11:15:59 EST 2004 Communications with UPS lost.
Wed Feb 11 11:16:07 EST 2004 Slave connection failed Connection refused! Down slave 0ectospasm notes that is may take some time for this message to appear. Remember, patience is a virtue.
Reconnect the USB cable. You should see:
Code: Select all
Wed Feb 11 11:16:20 EST 2004 Communications with UPS restored.
Wed Feb 11 11:16:37 EST 2004 Slave connection failed Connection refused! Down slave 0If you don't see these messages, you need to correct the problem before proceeding. Did you emerge hotplug? Kernel compiled correctly?
TESTING APCUPSD Simulated Power Fail Test:
First we'll need to reconfigure a few things to make sure apcupsd doesn't actually shutdown our system. Somewhat counterintuitive, I know, but we're still testing the installation. Do the following:
Code: Select all
# cp /etc/apcupsd/apccontrol /etc/apcupsd/apccontrol.save
# cp /etc/apcupsd/safe.apccontrol /etc/apcupsd/apccontrolWe're about to pull the plug. Do I need to tell you to make sure your system is properly backed up? Do another running tail of the apcupsd events file:
Code: Select all
# tail -f /var/log/apcupsd.eventsCode: Select all
Wed Feb 11 11:19:52 EST 2004 Power failure.
Wed Feb 11 11:19:58 EST 2004 Running on UPS batteries.Code: Select all
Wed Feb 11 11:20:06 EST 2004 Power is back. UPS running on mains.
Wed Feb 11 11:20:08 EST 2004 Slave connection failed Connection refused! Down slave 0Code: Select all
# cp /etc/apcupsd/apcupsd.conf /etc/apcupsd/apcupsd.saveCode: Select all
# /etc/init.d/apcupsd restartCode: Select all
Wed Feb 11 11:35:27 EST 2004 Power failure.
Wed Feb 11 11:35:33 EST 2004 Running on UPS batteries.Code: Select all
Wed Feb 11 11:36:04 EST 2004 Reached run time limit on batteries.
Wed Feb 11 11:36:04 EST 2004 Initiating system shutdown!
Wed Feb 11 11:36:04 EST 2004 User logins prohibitedCode: Select all
Wed Feb 11 11:36:07 EST 2004 Cancelling shutdown
Wed Feb 11 11:36:07 EST 2004 Power is back. UPS running on mains.
Wed Feb 11 11:36:07 EST 2004 Allowing loginsReplace your apccontrol and apcupsd.conf files, restart apcupsd and we'll move on to the final test...
Code: Select all
# cp /etc/apcupsd/apccontrol.save /etc/apcupsd/apccontrol
# cp /etc/apcupsd/apcupsd.save /etc/apcupsd/apcupsd.conf
# /etc/init.d/apcupsd restartSystem still properly prepared for catastrophic failure? Then let's do it for real.
You have two options here: simulate a complete loss of power by yanking the plug and waiting for the batteries to exhaust themselves, or set a low TIMEOUT value (e.g. 60) in apcupsd.conf. Remember to restart apcupsd if you choose the latter option. Either way, your system should power itself off once it has reached the appropriate parameter: roughly sixty seconds after unplugging if you chose to modify the TIMEOUT value as above, or when the battery reaches either 5% or has only three minutes of runtime remaining (whichever comes first, assuming you used the values from my sample apcupsd.conf files). These values are set (where else?) in your apcupsd.conf file, and can be modified to taste. You can run a tail of /var/log/apcupsd.events if you're into watching that sort of thing while your UPS bleats at you incessantly.
TESTING APCUPSD The Aftermath
If everything went flawlessly, congratulations. You now have a functional master (or standalone) installation of apcupsd. If you altered the TIMEOUT value in apcupsd.conf, remember to set it back to 0 and restart apcupsd before you continue.
If something didn't go as planned, double-check your configuration file; check that you restored the original version of apccontrol after the Simulated Power Fail Test; make sure your UPS is still communicating successfully with apcupsd, and so on.
Now that we've got that sorted, let's set up our slave. If you're running apcupsd in standalone mode, you can skip this section and move on to OBTAINING UPS STATUS VIA YOUR BROWSER. If you're not interested in that either, you're done. Smoke 'em if you got 'em.
INSTALLING, CONFIGURING AND STARTING THE APCUPSD SLAVE:
Now it's time to get our slave up and running. This is much less involved as we're already familiar with the basic principles, right?
Code: Select all
# emerge sync; emerge apcupsd; rc-update add apcupsd defaultCode: Select all
## apcupsd.conf v1.1 ##
#
# for apcupsd release 3.10.9 (31 December 2003) gentoo
# sample slave configuration file
UPSCABLE ether
UPSTYPE smartups
LOCKFILE /var/lock
NOLOGON disable
NETSERVER on
NISPORT 3551
EVENTSFILE /var/log/apcupsd.events
EVENTSFILEMAX 10
UPSCLASS netslave
UPSMODE net
NETPORT 6666
MASTER <your-master-machines-IP-address>
USERMAGIC <some-unique-string>A few (very important) notes on the above:
- UPSCABLE must be set to ether.
- UPSTYPE must be set to smartups. I'm not kidding. This was worth twenty-four hours of aggravation when I was attempting to set my first slave. I've read documentation suggesting that the master and slave must have the same UPSTYPE. I've read documentation stating that UPSTYPE must be set to net just like UPSMODE. Neither of these settings worked on my installation. Just take my word for it: set UPSTYPE to smartups and don't look back.
- Unless you want to be locked out of your slave machine the moment your UPS switches to battery, I'd set the NOLOGON value to disable.
- Neither EVENTSFILE nor EVENTSFILEMAX are necessary, but I like to see what my slave's been up to even though the master calls all the shots. It's your decision to include or omit this.
- Remember when I told you to make a note about your master installation's USERMAGIC setting? Enter the same thing here or you'll be sorry.
Code: Select all
# /etc/init.d/apcupsd start
* Starting APC UPS daemon... [ ok ]Code: Select all
Wed Feb 11 15:39:08 EST 2004 apcupsd 3.10.9 (31 December 2003) gentoo startup succeeded
Wed Feb 11 15:39:38 EST 2004 Connect from master <your-master-machines-IP-address> succeededCode: Select all
Wed Feb 11 15:39:38 EST 2004 Connect to slave <your-slave-machines-IP-address> succeededTESTING THE APCUPSD SLAVE:
This goes just like it did for the master; just remember, your slave takes its orders from the master, so all file reconfiguration for testing should be done on the master, not on the slave. If you're lazy, overconfident, or just don't care by this point you can do what I did: once you've established the master and slave are communicating, pull the plug and see if the slave powers down with the master.
Remember to reset any configuration files to their operational states after testing and to restart apcupsd if you made any changes.
That's it. You now have a slave that will shutdown when its master tells it. Note that you can add BATTERYLEVEL, MINUTES, and TIMEOUT settings to the above slave configuration file to have the slave shutdown before the master, thereby conserving more battery for the master's use.
OBTAINING UPS STATUS VIA YOUR BROWSER:
First, you'll need to edit the /etc/apcupsd/hosts.conf file on your master installation to tell apcupsd which machines to monitor. Mine looks like this:
Code: Select all
MONITOR <your-master-machines-IP-address> <your-master-machines-name>
MONITOR <your-slave-machines-IP-address> <your-slave-machines-name>Now then...you had Apache installed, configured, and operational before you emerged apcupsd on your master machine, right? If this is the case, direct your browser to:
Code: Select all
http://<your-master-machines-IP-address>/apcupsd/multimon.cgiYour stats may or may not be as extensive as those noted in the above links; it will depend on your UPS.
You're done. When emerged, apcupsd automatically creates these files and directories in your /var/www directory (assuming a default Apache configuration). It's that simple...and if it's not, you need better help than I can give you here.
FINISHING UP:
Did you replace all your test configuration files with the proper ones? Are all your TIMEOUT values set to 0? Did you plug the UPS back in?
Stellar. I'd reboot both machines for good measure; bring the master online first, then the slave. Make sure apcupsd starts automatically (and properly) on both machines, check your logs, and relax. You're now running your UPS in smart mode...
CALIBRATION:
Oh, and one last thing. This is as good a place as any to talk about calibration of the UPS unit. It has recently become apparent that some (if not all) of the UPS units need to be calibrated in order to achieve their proper runtime while operating under load during a power failure. This has been confirmed as a necessity for the Back-UPS RS 1500; it can't hurt to follow this procedure for other APC UPS units as well.
First, if you're reading this prior to purchasing or installing a new APC UPS, I strongly recommend following the manufacturer's advice on charging the battery for the first time. For those without their manuals handy, that's usually a minimum of eight hours without anything else being plugged into the unit.
Once your unit has been properly charged, place the unit under at least a 50% load (you can monitor this either with your browser or apcaccess). Now disable apcupsd and yank the plug, letting the battery run until it is completely dead.
NOTE: It probably goes without saying, but you may not want to use your expensive server or gaming rig to run the battery into the ground (especially since we're disabling apcupsd). I'd think about loading the UPS unit with another (less valuable) appliance and simply using your system to ascertain the actual load. I'm not going to make any recommendations about what to load the UPS with, but please, use common sense.
Plug the UPS unit back into the wall and allow it to recharge completely. This should greatly improve the accuracy of the TIMELEFT estimate (and consequently, your actual runtime with apcupsd).
Thanks go to ectospasm for finding this issue and chasing it down, as well as Adam Kropelin for the providing the answer.
NOTES ON MISCELLANEOUS FUNCTIONALITY:
- Currently, apcupsd on USB UPS units does not send the UPS into hibernation when it powers down the system(s) it supports. This means that while apcupsd will monitor the status of the UPS and shutdown its supported system(s) as appropriate, it will not automatically bring the UPS and its supported systems(s) back online when power returns, as the UPS itself is never shut down (unless, of course, youre without power long enough that the UPS actually exhausts itself). Please see this section of the Troubleshooting apcupsd with USB thread for more details, but this functionality should be enabled sometime in the near future. Once apcupsd includes this feature for USB UPS units, Ill update this document with general guidelines regarding the procedure for making sure your system(s) come back to life automatically following a UPS-induced shutdown.
UPDATE: mark_lagace has developed a temporary workaround for this lack of functionality. Please see this section of this thread for his solution. If you're going to implement it, please read it carefully and take all the necessary precautions. Thanks, Mark! - As noted in the OBTAINING UPS STATUS VIA YOUR BROWSER section, the amount of information your UPS reports will vary depending on your model for example, my Back-UPS RS 1000 reports line voltage, while my two Back-UPS XS 800s do not. I may eventually include a separate section detailing the vagaries of the individual APC models, but for the time being this HOWTO will only encompass what I consider to be the primary functions of apcupsd, i.e. basic monitoring of the UPS unit itself and controlled shutdown of its supported system(s) according to user-defined parameters.
I can't say enough about the apcupsd project. If you're having problems, look there first. Much of this HOWTO was derived (or blatantly copied) from their work. Send them money, flowers, hardware, etc.
This document was lovingly crafted on OpenOffice and represents the whole of my knowledge on apcupsd. Any errors or omissions are mine alone. I would welcome any comments, corrections or further information on this daemon; I've only scratched the surface of what it can do and would like to hear about others' experience with/uses for it.
Finally, in September 2004 this HOWTO and its ensuing thread finally broke the three-page mark, necessitating (at least in my mind) the need for a separate topic to discuss problems with installation and execution. Therefore, if you're having problems please read through the remainder of this thread first; if you don't find an answer there, please post to the Troubleshooting apcupsd with USB thread.
CHANGELOG:
02.14.04: Edited the KERNEL CONFIGURATION section to reflect new minimal configuration options.
02.16.04: Edited the sample slave configuration file in INSTALLING, CONFIGURING AND STARTING THE APCUPSD SLAVE to include the NOLOGON value and a note beneath regarding the importance of same.
02.21.04: Edited the STARTING APCUPSD section to advise of a possible need to unplug/replug the USB cable.
03.05.04: Edited the INSTALLING AND CONFIGURING APCUPSD section regarding the necessary change in the /etc/apcupsd/apccontrol file for apcupsd-3.10.10. Also qualified the 2.6 kernel disclaimer.
04.22.04: The /etc/apcupsd/apccontrol file for apcupsd-3.10.10-r1 seems to have corrected the above issue, noted same in the INSTALLING AND CONFIGURING APCUPSD section.
09.10.04: Edited the KERNEL CONFIGURATION section to include suggested parameters for both 2.4 and 2.6 kernels; started the Troubleshooting apcupsd with USB thread.
10.07.04: Edited the KERNEL CONFIGURATION section to include advice regarding power management; edited the PREREQUISITES section to include the first-reported successful execution of these procedures on AMD64 hardware; added the NOTES ON MISCELLANEOUS FUNCTIONALITY section.
10.30.04: Added the CALIBRATION section after recent events on the Troubleshooting apcupsd with USB thread.
12.31.04: Added a link to mark_lagace's workaround for the UPS killpower issue discussed in the NOTES ON MISCELLANEOUS FUNCTIONALITY section. Added links here as well, I suppose.
01.31.05: Edited the TESTING APCUPSD Communications Test and STARTING APCUPSD sections per suggestions from ectospasm.



