apcupsd is a program for controlling APC UPS devices. Install on Gentoo as follows…
Make sure that you have the computer plugged in to the UPS, a USB cable connecting the two, the power on and the computer booted!
Install apcupsd:
emerge -avDuN apcupsd
Config in /etc/apcupsd/apcupsd.conf (this will shut down the computer when the UPS battery has only 6% or 2 minutes left):
UPSNAME myups
UPSCABLE usb
UPSTYPE usb
DEVICE
POLLTIME 30
LOCKFILE /run/apcupsd
SCRIPTDIR /etc/apcupsd
PWRFAILDIR /etc/apcupsd
NOLOGINDIR /etc
ONBATTERYDELAY 10
BATTERYLEVEL 6
MINUTES 2
TIMEOUT 0
ANNOY 45
ANNOYDELAY 90
NOLOGON disable
KILLDELAY 0
NETSERVER on
NISIP 127.0.0.1
NISPORT 3551
EVENTSFILE /var/log/apcupsd.events
EVENTSFILEMAX 25
UPSCLASS standalone
UPSMODE disable
STATTIME 0
STATFILE /var/log/apcupsd.status
LOGSTATS off
DATATIME 0
You can use apctest
to run a self-test (and other things):
myserver ~ # apctest
2016-08-31 19:47:24 apctest 3.14.13 (02 February 2015) gentoo
Checking configuration ...
sharenet.type = Network & ShareUPS Disabled
cable.type = USB Cable
mode.type = USB UPS Driver
Setting up the port ...
Doing prep_device() ...
You are using a USB cable type, so I'm entering USB test mode
Hello, this is the apcupsd Cable Test program.
This part of apctest is for testing USB UPSes.
Getting UPS capabilities...SUCCESS
Please select the function you want to perform.
1) Test kill UPS power
2) Perform self-test
3) Read last self-test result
4) View/Change battery date
5) View manufacturing date
6) View/Change alarm behavior
7) View/Change sensitivity
8) View/Change low transfer voltage
9) View/Change high transfer voltage
10) Perform battery calibration
11) Test alarm
12) View/Change self-test interval
Q) Quit
Select function number: 2
This test instructs the UPS to perform a self-test
operation and reports the result when the test completes.
Clearing previous self test result...CLEARED
Initiating self test...INITIATED
Waiting for test to complete...COMPLETED
Result of last self test: PASSED
...
I attempted to view the UPS status with apcaccess
:
myserver ~ # apcaccess
*** buffer overflow detected ***: apcaccess terminated
======= Backtrace: =========
/lib64/libc.so.6(+0x71adb)[0x7ffa8188aadb]
/lib64/libc.so.6(__fortify_fail+0x37)[0x7ffa81911ff7]
/lib64/libc.so.6(+0xf7070)[0x7ffa81910070]
...
Turns out you need apcupsd running to avoid buffer overflow with apcaccess.
Start the apcupsd daemon and try apcaccess
again:
myserver ~ # /etc/init.d/apcupsd start
* /run/apcupsd: correcting mode
* /run/apcupsd: correcting owner
* Starting APC UPS daemon ... [ ok ]
myserver ~ # apcaccess
APC : 001,036,0877
DATE : 2016-08-31 19:53:12 +0100
HOSTNAME : myserver
VERSION : ---cut---
UPSNAME : myups
CABLE : USB Cable
DRIVER : USB UPS Driver
UPSMODE : Stand Alone
STARTTIME: 2016-08-31 19:51:08 +0100
MODEL : Back-UPS XS 700U
STATUS : ONLINE
LINEV : 240.0 Volts
LOADPCT : 9.0 Percent
BCHARGE : 100.0 Percent
TIMELEFT : 58.3 Minutes
MBATTCHG : 6 Percent
MINTIMEL : 2 Minutes
MAXTIME : 0 Seconds
SENSE : Medium
LOTRANS : 140.0 Volts
HITRANS : 300.0 Volts
ALARMDEL : 30 Seconds
BATTV : 13.7 Volts
LASTXFER : Automatic or explicit self test
NUMXFERS : 0
TONBATT : 0 Seconds
CUMONBATT: 0 Seconds
XOFFBATT : N/A
SELFTEST : OK
STATFLAG : 0x05000008
SERIALNO : 3B1622X12363
BATTDATE : 2016-06-01
NOMINV : 230 Volts
NOMBATTV : 12.0 Volts
NOMPOWER : 390 Watts
FIRMWARE : 924.Z3 .I USB FW:Z3
END APC : 2016-08-31 19:53:17 +0100
Add apcupsd to the default runlevel so that it starts automatically:
myserver ~ # rc-update add apcupsd default
* service apcupsd added to runlevel default
Reference: Linux: Configure and Control APC SmartUPS During a Power Failure