I’ve experienced a number of power cuts here today due to repairs being carried out on the local grid after the recent freezing weather. Not a problem, I thought, as I’ve got uninterruptible power supplies on all my computers. As long as the electricity isn’t off for too long, it’ll be fine.
And indeed, “Server Corner” in the room upstairs was fine. My LAN switch, the HP Microserver, Raspberry Pis and their external HDs carried on running on their UPS throughout the whole power cut.
The trouble was that my internet router and the house phone share their UPS with my main PC – which happened to be keeping the room warm while I was out walking the doy by running BOINC full-chat on its four CPU cores and on the GPU too. It’s power consumption is pretty close to the UPS’s rated capacity when doing that, so when the power failed, my APC Back-UPS 650 CS was hit with a load close to its recommended load capacity (>90%).
This shouldn’t have been a problem but for three things that have happened since we last had a long power cut. First, I’ve started running BOINC on my main PC again. Second, I recently removed the control cable from the back its APC UPS in order to test a “for spares or repair, no cables and sorry about the sticky mess” APC UPS I scored on eBay (it was fine – it just needed a new battery… and disinfecting). Third, I forgot I’d moved the UPS control cable over to the 99p eBay UPS and had then baulked at buying another control cable when I discovered that they cost nearly as much as a new battery. The cable in question being one of APC’s proprietary USB-to-not-quite-an-ethernet-jack ones.
The result of all this was that my main PC never received a signal from its UPS that the power was out, carried on running BOINC at full-chat and fully depleted the UPS battery in around two minutes. Having reached a critical battery level, UPS then shut itself down, depriving the internet router and house phone of power.
So much for sustaining essential services during a power cut!
Anyway, I’ve now returned the UPS data cable to my main computer and configured
apcupsd (the Linux APC UPS daemon) to automatically shut down
boinc-client when mains power is lost and restart it when power is restored.
To do this, three files must be edited:
but before that, start boinc-client and then from the command line, run the command
sudo apcaccess status to display your UPS status data. We’re interested in the
TIMELEFT value. Note it down.
NB: I’m assuming that you already have apcupsd installed and configured for your UPS and have the data cable connected.
/etc/apcupsd/apcupsd.conf in your favourite text editor. Look for the variables
ONBATTERYDELAY should be set to only a few seconds – we want boinc-client running on batteries for as short a time as possible.
MINUTES must be set to less than the
TIMELEFT value obtained from the output of the
apcaccess status command while
boinc-client is running· Otherwise a complete system shutdown will be initiated before
boinc-client can be stopped.
BATTERYLEVEL should be set to the battery percentage you do want to initiate system shutdown at. I’ve set mine to 70 in order to leave a decent capacity for running the internet router and house phone.
TIMEOUT is set to zero.
Now save the file and restart the
The final step is to add the appropriate commands for stopping and starting
/etc/apcupsd/offbattery. In each file the command should be added after the
#!/bin/bash line but before the default emailing script that’s already in the files.
/etc/apcupsd/onbattery add the line
/sbin/service boinc-client stop (or it’s equivalent for your system – first experiment with starting and stopping
boinc-client from the command line if you’re not sure) and to
/etc/apcupsd/offbattery add the line
/sbin/service boinc-client restart. Save and close the files. You should now be set up for automatically turning the CPU and GPU intensive
boinc-client off whenever the power goes out.
If you want to test this, load up your sysstem monitor so you can see the graph of CPU utilisation. It should be pretty high with
boinc-client running. Now cut the power at the wall socket. Within seconds, the CPU utilistation should drop as
apcupsd reads the
onbattery script and kills
To illustrate the benefits this has, here are the numbers for my system. With
apcaccess status shows
LOADPCT : 88.0 Percent Load Capacity ... TIMELEFT : 4.5 Minutes
and the power meter at the wall socket that the UPS is plugged into shows a UPS load of 3000W/325VA. Whereas without
boinc-client I get
LOADPCT : 47.0 Percent Load Capacity ... TIMELEFT : 14 Minutes
and the power meter at the wall socket that the UPS is plugged into shows a UPS load of 140W/170VA.
This is quite a useful improvement in UPS runtime and just goes to show both how much
boinc-client can stress a powerful machine when it’s running and how efficiently Intel processors and nVidia GPUs can throttle back when there’s no load on them.