apcupsd

I recently had to replace the batterypack on my APC Smart-UPS 3000 RM, which I ordered from shop4power. It was as cheap as I could get. (And I mean 112 euro is really cheap!)
I had to reinstall apcupsd (latest version I could find) because I could not write the battery-installdate into the EEPROM. I took the package from the Debian unstable repository. I decided to update the apcupsd-cgi scripts package also. The latter presents a statuspage in a webbrowser which is also fancy to have.


The UPS is connected through a USB-port, which is setup using at least the following statements in /etc/apcupsd/apcupsd.conf:

UPSCABLE smart
UPSTYPE usb
DEVICE /dev/usb/hid/hiddev[0-15]

  • Install the packages: sudo aptitude -t unstable install apcupsd apcupsd-cgi
  • Stop the daemon: sudo /etc/init.d/apcupsd stop
  • Start the apctest executable: sudo apctest

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) QuitSelect function number:

  • It’s obvious that number 4 should be selected:

Select function number: 4
Current battery date: 06/17/2004
Enter new battery date (MM/DD/YYYY), blank to quit: 01/12/2013
Writing new date…SUCCESS
Waiting for change to take effect…SUCCESS
Current battery date: 01/12/2013

  • And start the deamon: sudo /etc/init.d/apcupsd start
  • Check with: apcaccess |grep BATTDATEBATTDATE : 2013-01-12

Apcupsd on Synology NAS

Because I own a synology NAS, I would like to control it using the “nis” function of apcupsd. Apcupsd can be configured to provide a network service for other servers in the same lan.
First the server config should be slightly modified:

  • Edit /etc/apcupsd/apcupsd.conf and change the following statements:
    NETSERVER on.
    NISIP 0.0.0.0
    NISPORT 3551
    UPSMODE share

To install the apcupsd package on the synology, we need to install the bootstrap functionality first, so we can use the “ipkg” package handling utility. To start all this you must be certain of which CPU your NAS contains.

  • Enable SSH
  • Download the appropriate bootstrap file to a folder on your Synology box.
  • SSH or Telnet into the Synology Box
  • Login as root
  • Go to the directory containing the bootstrap file
  • Install bootstrap file, e.g. for ARM models type:
    • sh syno-x07-bootstrap_1.2-7_arm.xsh
  • After install remove bootstrap file, e.g. for ARM models type:
    • rm syno-x07-bootstrap_1.2-7_arm.xsh
  • Type: ipkg update
    • This will update the ipkg package feed on your box.
  • Type: ipkg upgrade
    • This will upgrade any installed ipkg packages to the latest version.
  • Type: ipkg install apcupsd.
    • Packages are installed in /opt
  • Configure the apcupsd daemon and edit /opt/etc/apcupsd/apcupsd.conf:
    • vi /opt/etc/apcupsd/apcupsd.conf
  • Modify the file:
UPSCABLE ether
UPSTYPE net
DEVICE 192.168.1.X:3551
POLLTIME 10
  • Test the setup and execute: /opt/sbin/apcupsd
  • Then exectute the command: /opt/sbin/apcaccess

APC      : 001,039,1005
DATE     : 2013-01-19 18:37:22 +0100
HOSTNAME : NAS
VERSION  : 3.14.8 (16 January 2010) unknown
UPSNAME  : striterax
CABLE    : Ethernet Link
MODEL    : Smart-UPS 3000 RM
UPSMODE  : Stand Alone

  • Which is looking good…….

Setup on boot:

  • Create a bootscript as was stated here in the first place:
  • vim /usr/local/etc/rc.d/apcupd.sh
  • Add the following lines to the file:
#!/bin/sh
#apcupsd.sh v1.4 by Federico Holgado
# startup scripts for APCUPSD.
apcupsd_enable=${apcupsd_enable:-YES}
apcupsd_program=${apcupsd_program:-/opt/sbin/apcupsd}
apcupsd_flags=${apcupsd_flags:-"--kill-on-powerfail"}
apcupsd_pidfile=${apcupsd_pidfile:-/var/run/apcupsd.pid}
apcupsd_lockfile=${apcupsd_pidfile:-/var/spool/lock/apcupsd.lock}
case $1 in
start)
case "${apcupsd_enable}" in
[Yy][Ee][Ss])
rm -f /var/run/powerfail
rm -f /var/run/nologin
if [ -f ${apcupsd_program} ]; then
echo -n " apcupsd"
${apcupsd_program} ${apcupsd_flags} || return="  Failed."
touch ${apcupsd_lockfile}
fi
;;
esac
;;
stop)
if [ -f ${apcupsd_pidfile} ]; then
PID=`cat ${apcupsd_pidfile}`
kill -KILL $PID || return="  Failed."
rm -f ${apcupsd_pidfile}
# some slaves won't die
killall apcupsd > /dev/null 2>&1
echo " apcupsd killed"
else
return="  Failed."
fi
;;
restart)
$0 stop
$0 start;
;;
status)
${PREFIX}/sbin/apcaccess status
;;
*)
echo "usage: $0 {start|stop|restart|status}" 1>&2
;;
esac
exit 0;
  • Make the file executable: chmod 700 /usr/local/etc/rc.d/apcupd.sh
  • Test with: /usr/local/etc/rc.d/apcupd.sh start
  • Check if the process is running with: /opt/sbin/apcaccess

2 thoughts on “apcupsd

  1. Hi,
    I have one question… after configuring apcupsd on the Synology NAS, does it see the network UPS within the UPS configuration in DSM or do you have to configure power-off or things like that directly in the apcupsd server from the command line? If the latter, can you put the synology NAS in Safe-mode from the command line?

    Thank you for the tutorial
    Gianni

  2. No the DSM UPS option is used for example when you have plugged-in the usb-cable from the APC UPS-unit direct into the Synology. After this the option “enable UPS support” should be enabled in the Synology (Control -> Hardware -> UPS) This way the Synology will be put in safe mode when a power-failure occurs.

    Using the setup mentioned in my blog only apcaccess can be used on the synology to show the status of the UPS itself. The Synology will not be powered down automatically or put in safe-mode. Maybe this is possible, but I did not researched it further.

    I chose to configure my linux box to communicate directly with the UPS instead of the Synology.

Leave a Reply

Your email address will not be published. Required fields are marked *

*