APC UPS

From ArchWiki
Revision as of 17:23, 23 July 2005 by Klapmuetz (Talk | contribs) (Wiki migration)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

APC UPS Daemon Installation

This document describes how to install the APC UPS daemon. The main advantage of using an APC UPS (for me) is that it can communicate with your Linux box through either a RS-232 or USB serial connection. In the event of a prolonged power outage, should the APC UPS lose most of its battery capacity, it can tell the Linux box to perform a safe shutdown.

Create the PKGBUILD File

First make a directory called "apcupsd" under the local ABS directory:

mkdir /var/abs/local/apcupsd

Then copy the text below and paste it into the PKBUILD file:

# cat > /var/abs/local/apcupsd/PKGBUILD
PASTE HERE
^D

(Ctrl-D exits 'cat')

Code:

pkgname=apcupsd
pkgver=3.10.16
pkgrel=1
pkgdesc="APC UPS Daemon"
url="http://sourceforge.net/projects/apcupsd/"
depends=('glibc')
source=(http://umn.dl.sourceforge.net/apcupsd/$pkgname-$pkgver.tar.gz apcupsd)
md5sums=('07de8f7d7488b6ef91f128f51713f4ea' '3128fff6672b0bf9901452d547fd72be')

build() {
  cd $startdir/src/$pkgname-$pkgver
  ./configure --prefix<code>/usr --sbindir</code>/sbin --enable-threads --enable-pthreads --enable-powerflute --enable-nls --enable-usb
  make ||| return 1
  make prefix=$startdir/pkg/usr install
  install -D -m755 ../apcupsd $startdir/pkg/etc/rc.d/apcupsd
}

Create the apcupsd Initialization Script

First, cut and paste the following code into the apcupsd file:

# cat > /var/abs/local/apcupsd/apcupsd
PASTE HERE
^D

Code:

#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

PID=`pidof -o %PPID /sbin/apcupsd`

start() {
  stat_busy "Starting APC UPS Daemon"
  [[ -z "$PID" ]] && /sbin/apcupsd
  if [[ $? -gt 0 ]]; then
    stat_fail
  else
    add_daemon apcupsd
    stat_done
  fi
}

stop() {
  stat_busy "Stopping APC UPS Daemon"
  [[ ! -z "$PID" ]]  && kill $PID &> /dev/null
  if [[ $? -gt 0 ]]; then
    stat_fail
  else
    rm /var/run/apcupsd.pid
    rm_daemon apcupsd
    stat_done
  fi
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    stop
    sleep 10
    start
    ;;
  *)
    echo "usage: $0 {start||stop||restart}"
esac
exit 0

Next, perform a checksum of the file:

# md5sum /var/abs/local/apcupsd/apcupsd
3128fff6672b0bf9901452d547fd72be apcupsd

This is a very important step. Note the md5sum=() reference in the PKBUILD file. The checksum must match.

Create and Install the Package

First, change directories to your package location and run the package builder:

# cd /var/abs/local/apcupsd
# makepkg

Next, install the package:

# pacman -A apcupsd-3.10.16-1.pkg.tar.gz

If things down't work quite as expected and you need to re-install, perform an upgrate:

# pacman -U apcupsd-3.10.16-1.pkg.tar.gz

Configure APC UPS

The main configuration file for the APC UPS daemon can be found here: /etc/apcupsd/apcupsd.conf

In the following example, the lines of text are changed to support a USP style cable:

Before:

UPSCABLE smart

UPSTYPE smartups

DEVICE /dev/ttyS0

After:

UPSCABLE usb

UPSTYPE usb

DEVICE /dev/usb/hiddev[[0-15]]

Test

First, start the daemon:

# /etc/rc.d/apcupsd start

Next, wait about a minute and confirm the daemon is running and properly monitoring the battery:

# apcaccess status
APC      : 001,033,0819
DATE     : Sat Mar 05 SOMETIME 2005
HOSTNAME : somehostname
RELEASE  : 3.10.16
VERSION  : 3.10.16 (04 November 2004) unknown
UPSNAME  : somehostname
CABLE    : USB Cable
MODEL    : Back-UPS ES 725
UPSMODE  : Stand Alone
STARTTIME: Sat Mar SOMETIME 2005
STATUS   : ONLINE
LINEV    : 119.0 Volts
LOADPCT  :  23.0 Percent Load Capacity
BCHARGE  : 100.0 Percent
TIMELEFT :  30.5 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME  : 0 Seconds
LOTRANS  : 088.0 Volts
HITRANS  : 138.0 Volts
ALARMDEL : Always
BATTV    : 13.5 Volts
NUMXFERS : 0
TONBATT  : 0 seconds
CUMONBATT: 0 seconds
XOFFBATT : N/A
STATFLAG : 0x02000008 Status Flag
MANDATE  : 2002-12-02
SERIALNO : QB0249360043
BATTDATE : 2000-00-00
NOMBATTV :  12.0
FIRMWARE : 02.n2.D USB FW:n2
APCMODEL : Back-UPS ES 725
END APC  : Sat SOMETIME 2005

To fully test your setup:

  1. Change TIMEOUT form 0 to 1 in the /etc/apcupsd/apcupsd.conf file
  2. Remove wall power from the UPS
  3. Observe that your Linux box powers down, in short order
  4. Plug the UPS back into the wall
  5. Power on your Linux box
  6. Change TIMEOUT from 1 back to 0 in the /etc/apcupsd/apcupsd.conf file

Congratulations!

Now all that's left to do is add the 'apcupsd' daemon to the DAEMONS=() list in /etc/rc.conf