Last modified: Mar. 13, 2010
Contents
1 - Summary
2 - Dependencies
3 - Apcupsd installation
4 - Service configuration
5 - Apcaccess example
6 - View status on website
7 - Service check
1 - Summary
This guide will show you how to install apcupsd in FreeBSD. Apcupsd is used
for power management and controlling of APC UPS's. In this guide, the cgi
scripts will be built with apcupsd and served by apache so information can be
viewed in a web browser. This has been tested in FreeBSD 8.0.
2 - Dependencies
Install the msmtp packge. Msmtp is an SMTP client used to send email. We will
use it to send email notifications.
# sudo pkg_add -r msmtp
Password:
Install the apache22 package. Apache is a web server that will host the cgi
scripts to display information about the UPS.
# sudo pkg_add -r apache22
Password:
Find where the apache daemon was installed to.
# pkg_info -L apache-2.2.* | grep sbin
/usr/local/sbin/ab
/usr/local/sbin/apachectl
/usr/local/sbin/apxs
/usr/local/sbin/checkgid
/usr/local/sbin/dbmmanage
/usr/local/sbin/envvars
/usr/local/sbin/htcacheclean
/usr/local/sbin/htdbm
/usr/local/sbin/htdigest
/usr/local/sbin/htpasswd
/usr/local/sbin/httpd
/usr/local/sbin/httxt2dbm
/usr/local/sbin/logresolve
/usr/local/sbin/rotatelogs
/usr/local/sbin/split-logfile
Edit /etc/rc.conf.local so that the apache daemon will start when the system
starts up. Somewhere in the file add the following.
apache22_enable="YES"
# sudo vi /etc/rc.conf.local
Password:
Find where the configuration file should be put.
# grep httpd.conf /usr/local/etc/rc.d/apache22
required_files=/usr/local/etc/apache22/httpd.conf
# strings /usr/local/sbin/httpd | grep httpd.conf
-D SERVER_CONFIG_FILE="etc/apache22/httpd.conf"
etc/apache22/httpd.conf
directive in your httpd.conf file to list a non-root
You will need to modify the original configuration file. Add the following.
Afterwards, create the apcupsd directory in the apache document root.
ServerName server.test.com
Redirect permanent /apcupsd/ http://server.test.com/cgi-bin/multimon.cgi
#ScriptAlias /cgi-bin/ "/usr/local/www/apache22/cgi-bin/"
ScriptAlias /cgi-bin/ "/usr/local/etc/apcupsd/cgi/"
#<Directory "/usr/local/www/apache22/cgi-bin">
<Directory "/usr/local/etc/apcupsd/cgi">
AddHandler cgi-script .cgi
# pkg_info -L apache-2.2.* | grep httpd.conf
/usr/local/share/examples/apache22/httpd.conf
# sudo cp /usr/local/share/examples/apache22/httpd.conf /usr/local/etc/apache22/httpd.conf
Password:
# sudo cp /usr/local/etc/apache22/httpd.conf /usr/local/etc/apache22/httpd.conf.example
Password:
# sudo vi /usr/local/etc/apache22/httpd.conf
Password:
# sudo mkdir /usr/local/www/apache22/data/apcupsd
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. In this case we are using the serial port.
# dmesg | grep -E "(uart[0-9]|American Power Conversion)"
uart0: <16550 or compatible> port 0x3f8-0x3ff irq 4 flags 0x10 on acpi0
uart0: [FILTER]
3 - Apcupsd installation
Install the apcupsd port. Enable only the following options.
[X] APCSMART_DRV Compile APC SmartUPS serial driver
[X] CGI Compile with CGI programms to show status
[X] USB Compile with USB Support driver
# cd /usr/ports/sysutils/apcupsd/
# sudo make
Password:
# sudo make install
Password:
# sudo make clean
Password:
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
Edit /etc/rc.conf.local so that the apcupsd service will start when the
system starts up. Somewhere in the file add the following.
apcupsd_enable="YES"
# sudo vi /etc/rc.conf.local
Password:
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"
# sudo strings /usr/local/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 ##
/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:
# sudo vi /usr/local/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. In FreeBSD /dev/cuau0 is used instead
of /dev/cuad0.
## apcupsd.conf v1.1 ##
UPSCABLE 940-0095A
UPSTYPE apcsmart
DEVICE /dev/cuau0
LOCKFILE /var/spool/lock
EVENTSFILE /var/log/apcupsd.events
EVENTSFILEMAX 10
UPSCLASS standalone
UPSMODE disable
# pkg_info -L apcupsd-* | grep apcupsd.conf
/usr/local/etc/apcupsd/apcupsd.conf.sample
# sudo cp /usr/local/etc/apcupsd/apcupsd.conf.sample /usr/local/etc/apcupsd/apcupsd.conf
Password:
# sudo cp /usr/local/etc/apcupsd/apcupsd.conf /usr/local/etc/apcupsd/apcupsd.conf.example
Password:
# sudo vi /usr/local/etc/apcupsd/apcupsd.conf
Password:
You can modify the hosts.conf file that lists the UPS's viewable on the
website. Here is a simple example.
MONITOR server.test.com "Server"
# pkg_info -L apcupsd-* | grep hosts.conf
/usr/local/etc/apcupsd/hosts.conf.sample
# sudo cp /usr/local/etc/apcupsd/hosts.conf.sample /usr/local/etc/apcupsd/hosts.conf
Password:
# sudo cp /usr/local/etc/apcupsd/hosts.conf /usr/local/etc/apcupsd/hosts.example
Password:
# sudo vi /usr/local/etc/apcupsd/hosts.conf
Password:
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 908.
Start the apache service.
# sudo /usr/local/etc/rc.d/apache22 start
Password:
Performing sanity check on apache22 configuration:
Syntax OK
Starting apache22.
# sudo /usr/local/etc/rc.d/apache22 status
Password:
apache22 is running as pid 926.
5 - Apcaccess example
This command prints the UPS model number, software version, status, load
percentage, battery charge and other information.
# /usr/local/sbin/apcaccess status localhost
APC : 001,051,1236
DATE : Sat Mar 13 09:00:16 CST 2010
HOSTNAME : server.test.com
RELEASE : 3.14.5
VERSION : 3.14.5 (10 January 2009) freebsd
UPSNAME : UPS_IDEN
CABLE : APC Cable 940-0095A
MODEL : Smart-UPS 750
UPSMODE : Stand Alone
STARTTIME: Sat Mar 13 08:57:58 CST 2010
STATUS : ONLINE
LINEV : 119.5 Volts
LOADPCT : 21.4 Percent Load Capacity
BCHARGE : 100.0 Percent
TIMELEFT : 52.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 : 28.3 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 Mar 13 09:00:48 CST 2010
6 - View status on website
Navigate your web browser to http://server.test.com/apcupsd/. This will be
redirected to the multimon.cgi script which gives a summary of the UPS
specified in the hosts.conf file. Click on the system in the left-hand column.
You can now view the details like battery capacity, run time remaining and UPS
load.
7 - Service check
Reboot your computer. Log in like normal and check to see that the apcupsd
and apache services are running. That's it, now you have apcupsd with cgi
scripts viewable on a website running in FreeBSD.
# sudo shutdown -r now
Password:
# sudo /usr/local/etc/rc.d/apcupsd status
Password:
apcupsd is running as pid 619.
# sudo /usr/local/etc/rc.d/apache22 status
Password:
apache22 is running as pid 735.
|