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.
Assuming your UPS supports it, you can have acpupsd kill the power to your UPS. The problem lies in the default 'onbattery' script and the system 'halt' script. Here's what I did:
First things first: The Problem...
If you want your computer to automatically restart after a powerfail situation (as is the case for most servers) then you need to have a couple things set up to happen:
- The system has to be set up to boot up when it gets power. This is usually just a simple BIOS setting.
- The system has to lose power! When there is a UPS attached this doesn't happen unless the UPS is told to shut off power, or it completely drains the battery (and thus has no power to provide). With proper shutdown scripts though, your system will shutdown before the UPS is completely drained, at which point there's no load on the UPS and the battery can last a very very long time. Since the computer never detects that the power was cut out, it conversely never detects that the power is back on and that it should boot up.
apcupsd is capable of sending the "--killpower" command to the UPS, but in the default setup that happened when I emerged apcupsd-3.10.15-r1 this didn't happen. After much poking around, here's what worked for me. For the record, my UPS is the APC BackUPS XS800 (model BR800 according to the USB info).
The solution.
apcupsd apparently checks for the presence of the file
/etc/apcupsd/powerfail when the command to kill the ups power is sent to it. If this file does not exist, it ignores the request. If use the command /etc/apcupsd/apccontrol killpower, you'll see the following output:
Code: Select all
Apccontrol doing: /usr/sbin/apcupsd --killpower on UPS
apcupsd FATAL ERROR in apcdevice.c at line 127
Cannot find /etc/apcupsd/powerfail file.
Killpower requested in non-power fail condition or bug.
Killpower request ignored at apcdevice.c:127
N.B. DO NOT DO THIS: To test out if I could get apcupsd to shut off my UPS, I manually created the /etc/apcupsd/powerfail file and re-tried the apccontrol killpower command. Lo and behold, it worked (and my system went ker-clunk as power was cruelly and heartlessly yanked from it).
Thus, all that was left was to automate the process and get it happening at the right time...
To do this, you'll need to modify 3 files. First, edit /etc/apcupsd/powerout (in my case, it's symlinked to /etc/apcupsd/onbattery). Add the following line prior to the exit 0 line:
This will create the file /etc/apcupsd/powerfail when apcupsd detects loss of power.
Now edit the file /etc/apcupsd/mainsback and add the following command before the exit 0 line:
This will get rid of that file if the power comes back. N.B. The default init script for apcupsd automatically deletes the /etc/apcupsd/powerfail file upon apcupsd startup, so you don't have to worry about modifying any startup scripts to get rid of it.
The last thing to do, is to get your shutdown scripts to call /etc/apcupsd/apccontrol killpower when they are done shutting everything down. Edit the file /etc/init.d/halt.sh and add the following commands at the end of it:
Code: Select all
# Attempting to add APCUPSD's killpower function here
if [ -f /etc/apcupsd/powerfail ]; then
ewarn "Powerfail situation - shutting off the UPS"
/etc/apcupsd/apccontrol killpower
sleep 120
exit 1
fi
The "sleep 120" line is required to give apcupsd enough time to send the commands to the UPS. You may need to increase this value if it's too low for your system.
DISCLAIMER: This worked for me. I can't guarantee it will work in every situation, but the general concept is sound. The basic idea is to have your system issue the command "/etc/apcupsd/apccontrol killpower" when it shuts down, if there has been a power failure.
If there are other things that should be modified, or better places to stick the modifications, I'd appreciate any insight you might have.