Packetwatch.net

Apcupsd in OpenBSD



Last modified: Dec. 1, 2009

Contents
1 - Summary
2 - Dependencies
3 - Apcupsd installation
4 - Service configuration
5 - Apcaccess example
6 - Service check


1 - Summary

This guides will show you how to install apcupsd in OpenBSD. Apcupsd is used
for power management and controlling of APC UPS's. This has been tested in
OpenBSD 4.4 and 4.6.


2 - Dependencies

Install the msmtp package. Msmtp is an SMTP client used to send email. We will
use it to send email notifications.
# pkg_find msmtp
clamsmtp-*.tgz
msmtp-*.tgz
# sudo pkg_add msmtp-*.tgz
Password:

The pkg_find utility used above is a shell script I've created that can search
the list of available packages.

#!/bin/sh
# This script will look for packages with the search term.

echo=/bin/echo
lynx=/usr/bin/lynx
pkg_path=ftp://ftp.openbsd.org/pub/OpenBSD/$rel/packages/$arch/index.txt
tr=/usr/bin/tr
cut=/usr/bin/cut
grep=/usr/bin/grep

if [ $# -ne 1 ]
    then
        exit 0
    else
        # check if a valid parameter
        if [ "$1" == "-help" ]
            then
                $echo Usage: pkg_find [string]
            else
                $lynx -dump $pkg_path | $tr -s " " | $cut -d " " -f 10 | $grep -i $1
        fi
fi
exit 0

# cd ~
# vi pkg_find
# sudo chown root:bin pkg_find
Password:
# sudo chmod 555 pkg_find
Password:
# sudo mv pkg_find /usr/sbin/
Password:

Here is an example of what it can do.
# pkg_find -help
Usage: pkg_find [string]
# pkg_find msmtp 
clamsmtp-*.tgz
msmtp-*.tgz

Find where the msmtp binary was installed to.
# pkg_info -L msmtp-* | grep bin
/usr/local/bin/msmtp

Run ldd to display the shared objects (.so) needed to run the msmtp binary. If
there are any shared objects in /usr/local you will need to run ldconfig.
# ldd /usr/local/bin/msmtp
/usr/local/bin/msmtp:
        Start    End      Type Open Ref GrpRef Name
        1c000000 3c008000 exe  1    0   0      /usr/local/bin/msmtp
        085b3000 285b7000 rlib 0    2   0      /usr/local/lib/libintl.so.4.0
        09ec3000 29fa2000 rlib 0    2   0      /usr/local/lib/libiconv.so.6.0
        0b847000 2b854000 rlib 0    1   0      /usr/lib/libssl.so.15.0
        03c39000 23c79000 rlib 0    1   0      /usr/lib/libcrypto.so.18.0
        0cb58000 2cb84000 rlib 0    1   0      /usr/local/lib/libidn.so.16.30
        0ed02000 2ede1000 rlib 0    1   0      /usr/local/lib/libiconv.so.6.0
        0433c000 24340000 rlib 0    1   0      /usr/local/lib/libintl.so.4.0
        0141c000 21455000 rlib 0    1   0      /usr/lib/libc.so.51.0
        08b4d000 08b4d000 rtld 0    1   0      /usr/libexec/ld.so
# sudo ldconfig /usr/lib /usr/local/lib
Password:

Install the gmake package.
# pkg_find gmake
gmake-*.tgz
# sudo pkg_add gmake-*.tgz
Password:

Find where the gmake binary was installed to.
# pkg_info -L gmake-* | grep bin
/usr/local/bin/gmake

Run ldd to display the shared objects (.so) needed to run the gmake binary. If
there are any shared objects in /usr/local you will need to run ldconfig.
# ldd /usr/local/bin/gmake
/usr/local/bin/gmake:
        Start    End      Type Open Ref GrpRef Name
        1c000000 3c00b000 exe  1    0   0      /usr/local/bin/gmake
        061ef000 261f3000 rlib 0    1   0      /usr/local/lib/libintl.so.4.0
        06226000 26305000 rlib 0    1   0      /usr/local/lib/libiconv.so.6.0
        0a563000 2a59c000 rlib 0    1   0      /usr/lib/libc.so.51.0
        073b5000 073b5000 rtld 0    1   0      /usr/libexec/ld.so
# sudo ldconfig /usr/lib /usr/local/lib
Password:

Install the wget package.
# pkg_find wget
wget-*.tgz
# sudo pkg_add wget-*.tgz
Password:

Find where the wget binary was installed to.
# pkg_info -L wget-* | grep bin    
/usr/local/bin/wget

Run ldd to display the shared objects (.so) needed to run the wget binary. If
there are any shared objects in /usr/local you will need to run ldconfig.
# ldd /usr/local/bin/wget
/usr/local/bin/wget:
        Start    End      Type Open Ref GrpRef Name
        1c000000 3c019000 exe  1    0   0      /usr/local/bin/wget
        079dc000 279e0000 rlib 0    1   0      /usr/local/lib/libintl.so.4.0
        040b0000 2418f000 rlib 0    1   0      /usr/local/lib/libiconv.so.6.0
        06195000 261a2000 rlib 0    1   0      /usr/lib/libssl.so.15.0
        063d0000 26410000 rlib 0    1   0      /usr/lib/libcrypto.so.18.0
        026b1000 226ea000 rlib 0    1   0      /usr/lib/libc.so.51.0
        0118b000 0118b000 rtld 0    1   0      /usr/libexec/ld.so
# sudo ldconfig /usr/lib /usr/local/lib 
Password:

You will also need some information about the UPS and the UPS cable.
  Model number
  UPS cable type
The serial port or USB ports will need to be enabled in the BIOS of the
computer. You can find out the serial port or USB port information by typing
out the following.
# dmesg | grep -E "com|American Power Conversion" | grep -E "16550|American Power Conversion" 
com0 at isa0 port 0x3f8/8 irq 4: ns16550a, 16 byte fifo
com1 at isa0 port 0x2f8/8 irq 3: ns16550a, 16 byte fifo

In this case we are using the serial port.


3 - Apcupsd installation

Apcupsd can be downloaded at http://www.apcupsd.org/. Download and install the
current source files.
# cd ~
# wget http://downloads.sourceforge.net/project/apcupsd/apcupsd - Stable/$ver/apcupsd-$ver.tar.gz
# tar -zxvf apcupsd-*.tar.gz
# cd apcupsd-*/
# ./configure --enable-usb
# gmake
# sudo gmake install
Password:
# sudo gmake clean
Password:


4 - Service configuration

Find where the apcupsd daemon was installed to.
# sudo ldconfig /usr/lib /usr/local/lib
Password:
# sudo whereis apcupsd
Password:
/sbin/apcupsd

Run ldd to display the shared objects (.so) needed to run the apcupsd binary.
If there are any shared objects in /usr/local you will need to run ldconfig.
# sudo ldd /sbin/apcupsd
Password:
/sbin/apcupsd:
        Start    End      Type Open Ref GrpRef Name
        1c000000 3c00f000 exe  1    0   0      /sbin/apcupsd
        0d906000 2d90f000 rlib 0    1   0      /usr/lib/libpthread.so.11.1
        02f05000 22f3e000 rlib 0    1   0      /usr/lib/libc.so.51.0
        0226a000 0226a000 rtld 0    1   0      /usr/libexec/ld.so

Configure /etc/rc.local, so the apcupsd service will start at boot time. Modify
to have the following.
  # Start the UPS daemon. Do not remove the 'TAG_APCUPSD' text
  if [ -x /etc/rc.apcupsd ]; then     # TAG_APCUPSD
          /etc/rc.apcupsd start       # TAG_APCUPSD
  fi                                  # TAG_APCUPSD
# sudo vi /etc/rc.local
Password:

Find where the configuration file should be put.
# grep apcupsd.conf /etc/rc.apcupsd
# sudo strings /sbin/apcupsd | grep apcupsd.conf
Password:
Cannot perform killpower without authentication data. Please set ip:user:pass for DEVICE in \
apcupsd.conf.
## apcupsd.conf v1.1 ##
/etc/apcupsd/apcupsd.conf

You can modify the apccontrol script to send email notifications for different
UPS events.
# sudo cp /etc/apcupsd/apccontrol /etc/apcupsd/apccontrol.example
Password:
# sudo vi /etc/apcupsd/apccontrol
Password:

You can create your own configuration file. Here is a simple example. This
uses an APC UPS 940-0095A serial cable.
  ## apcupsd.conf v1.1 ##
  UPSCABLE 940-0095A
  UPSTYPE apcsmart
  DEVICE /dev/tty00
  LOCKFILE /var/spool/lock
  UPSCLASS standalone
  UPSMODE disable
# sudo cp /etc/apcupsd/apcupsd.conf /etc/apcupsd/apcupsd.conf.example
Password:
# sudo vi /etc/apcupsd/apcupsd.conf
Password:

Start the apcupsd service.
# sudo /etc/rc.apcupsd start
Password:
Starting apcupsd power management  Done.
# sudo cat /var/run/apcupsd.pid
Password:
7446


5 - Apcaccess example

This command prints the UPS model number, software version, status, load
percentage, battery charge and other information.
# apcaccess status localhost
APC      : 001,050,1218
DATE     : Mon Nov 23 20:50:22 CST 2009
HOSTNAME : server.test.com
VERSION  : 3.14.7 (1 August 2009) openbsd
UPSNAME  : UPS_IDEN
CABLE    : APC Cable 940-0095A
MODEL    : Smart-UPS 750
UPSMODE  : Stand Alone
STARTTIME: Mon Nov 23 20:50:06 CST 2009
STATUS   : ONLINE 
LINEV    : 119.5 Volts
LOADPCT  :  12.3 Percent Load Capacity
BCHARGE  : 100.0 Percent
TIMELEFT :  78.0 Minutes
MBATTCHG : 10 Percent
MINTIMEL : 5 Minutes
MAXTIME  : 0 Seconds
MAXLINEV : 119.5 Volts
MINLINEV : 118.8 Volts
OUTPUTV  : 119.5 Volts
SENSE    : High
DWAKE    : 000 Seconds
DSHUTD   : 090 Seconds
DLOWBATT : 02 Minutes
LOTRANS  : 106.0 Volts
HITRANS  : 127.0 Volts
RETPCT   : 000.0 Percent
ITEMP    : 34.6 C Internal
ALARMDEL : 5 seconds
BATTV    : 27.1 Volts
LINEFREQ : 60.0 Hz
LASTXFER : Automatic or explicit self test
NUMXFERS : 0
TONBATT  : 0 seconds
CUMONBATT: 0 seconds
XOFFBATT : N/A
SELFTEST : NO
STESTI   : 336
STATFLAG : 0x07000008 Status Flag
REG1     : 0x00 Register 1
REG2     : 0x00 Register 2
REG3     : 0x00 Register 3
MANDATE  : 09/15/05
SERIALNO : QS0538143065
BATTDATE : 09/15/05
NOMOUTV  : 120 Volts
NOMBATTV :  24.0 Volts
EXTBATTS : 0
FIRMWARE : 651.12.D
APCMODEL : FWD
END APC  : Mon Nov 23 20:50:50 CST 2009


6 - Service check

Reboot your computer. Log in like normal and check to see that the apcupsd
service is running. That's it, now you have apcupsd running in OpenBSD.
# sudo shutdown -r now
Password:
# sudo cat /var/run/apcupsd.pid
Password:
31496


Last modified: Thu Jan 1 00:00:00 1970 UTC
Packetwatch Research 2002-2024.