Packetwatch.net

Apcupsd in FreeNAS



Last modified: Nov. 21, 2009

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


1 - Summary

This guide will show how to install apcupsd in FreeNAS. Apcupsd is used for
power management and controlling of APC UPS's. This has been tested in FreeNAS
0.69.2.4700.


2 - Dependencies

Make sure that email has been configured using msmtp. We will use is to send
email notifications. Also, make sure that the SSH service has been enabled and
that sudo has been installed.

You will also need some information about the UPS and the UPS cable.

  Model number
  UPS cable type

SSH into FreeNAS. 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 the following.
> dmesg | grep -E "(^\sio[0-9]:|American Power Conversion)" | uniq
sio0: <16550A-compatible COM port> port 0x3f8-0x3ff irq 4 flags 0x10 on acpi0
sio0: type 16550A
sio1: configured irq 3 not in bitmap of probed irqs 0
sio1: port may not be enabled

In this case we are using the serial port.


3 - Apcupsd installation

Install the apcupsd package.
> su - root
Password:
# pkg_add -r apcupsd
# logout


4 - Service configuration

Find where the apcupsd daemon was installed to.
> pkg_info -L apcupsd-* | grep sbin
/usr/local/sbin/apcupsd
/usr/local/sbin/apcaccess
/usr/local/sbin/apctest
/usr/local/sbin/smtp

Log into the website interface and go to the System menu, then Advanced and
click on rc.conf. Click on the plus symbol to add an option. Type in the
following. After typing in the information, click on Add then Apply changes.

  Name: apcupsd_enable
  Value: YES

Go back to the SSH connection and find where the configuration file should be
put.
> grep apcupsd.conf /usr/local/etc/rc.d/apcupsd
required_files="/usr/local/etc/apcupsd/apcupsd.conf"

You can modify the apccontrol script to send email notifications for different
UPS events.
> pkg_info -L apcupsd-* | grep apccontrol
/usr/local/etc/apcupsd/apccontrol
> sudo cp /usr/local/etc/apcupsd/apccontrol /usr/local/etc/apcupsd/apccontrol.example
Password:

Go back to the website interface and go to Advanced menu and select File
Editor. Type in the following file path and click on Load. When finished
modifying the file click on Save.

  File path: /usr/local/etc/apcupsd/apccontrol

Go back to the SSH connection and backup the existing configuration file.
> pkg_info -L apcupsd-* | grep apcupsd.conf
/usr/local/etc/apcupsd/apcupsd.conf.sample
> cd /usr/local/etc/apcupsd/
> sudo mv apcupsd.conf.sample apcupsd.conf
Password:
> sudo cp apcupsd.conf apcupsd.conf.example
Password:

Go back to the website interface and go to Advanced menu and select File
Editor. Type in the following file path and click on Load. When finished
modifying the file click on Save.

  File path: /usr/local/etc/apcupsd/apcupsd.conf

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/cuad0
  LOCKFILE /var/spool/lock
  UPSCLASS standalone
  UPSMODE disable

Go back to the SSH connection and start the apcupsd service.
> sudo /usr/local/etc/rc.d/apcupsd start
Password:
Starting apcupsd.
> sudo /usr/local/etc/rc.d/apcupsd status
Password:
apcupsd is running as pid 3453.

Make a backup of the website page to display diagnostic information about the
UPS.
> sudo cp /usr/local/www/diag_infos_ups.php /usr/local/www/diag_infos_ups.php.original
Password:

Go back to the website interface and go to the Advanced menu and select File
Editor. Replace the PHP code at the bottom of the page with the following.

  <?php html_titleline(gettext("UPS status"));?>
  <tr>
    <td>
      <pre><?php system("/usr/local/sbin/apcaccess status localhost 2>&1");?></pre>
    </td>
  </tr>

After typing in the information click on Save. You can view the UPS status by
going to the Diagnostics menu, then Information and finally click on UPS.


5 - Apcaccess example

This command prints the UPS model, software version, status, load percentage,
battery charge and other information.
> sudo /usr/local/sbin/apcaccess status localhost
Password:
APC      : 001,051,1234
DATE     : Sat Nov 21 18:57:24 CST 2009
HOSTNAME : server.test.com
RELEASE  : 3.14.4
VERSION  : 3.14.4 (18 May 2008) freebsd
UPSNAME  : UPS_IDEN
CABLE    : APC Cable 940-0095A
MODEL    : Smart-UPS 750
UPSMODE  : Stand Alone
STARTTIME: Sat Nov 21 18:55:08 CST 2009
STATUS   : ONLINE 
LINEV    : 120.2 Volts
LOADPCT  :  13.0 Percent Load Capacity
BCHARGE  : 100.0 Percent
TIMELEFT :  75.0 Minutes
MBATTCHG : 10 Percent
MINTIMEL : 5 Minutes
MAXTIME  : 0 Seconds
MAXLINEV : 120.2 Volts
MINLINEV : 119.5 Volts
OUTPUTV  : 120.2 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    : 35.1 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  : Sat Nov 21 18:58:01 CST 2009


6 - Service check

Reboot your computer. SSH back in to check to see that the apcupsd service is
running. That's it, now you have apcupsd running in FreeNAS.
> sudo shutdown -r now
Password:
> sudo /usr/local/etc/rc.d/apcupsd status
Password:
apcupsd is running as pid 1339.


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