Setup apcupsd For Multiple Network-Enabled APC UPSes On EL6

From AN!Wiki
Jump to: navigation, search

 AN!Wiki :: How To :: Setup apcupsd For Multiple Network-Enabled APC UPSes On EL6

This covers the setup of one or more APC UPSes with network management cards installed.

Contents

Installing on RHEL

Build From Source

Rebuild from source (check here for newer versions):

Enable the RHEL Server Optional channel on RHN.

Install dependencies;

yum install gd-devel net-snmp-devel

Install the source RPM;

rpm -Uvh http://pkgs.repoforge.org/apcupsd/apcupsd-3.14.10-1.rf.src.rpm

Change into the SPECS directory and build the RPM.

cd ~/rpmbuild/SPECS/
rpmbuild -ba apcupsd.spec
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.vtS73C
+ umask 022
+ cd /root/rpmbuild/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ cd /root/rpmbuild/BUILD
+ rm -rf apcupsd-3.14.10
+ /usr/bin/gzip -dc /root/rpmbuild/SOURCES/apcupsd-3.14.10.tar.gz
+ /bin/tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd apcupsd-3.14.10
...
<snipped compile messages>
...
Processing files: apcupsd-debuginfo-3.14.10-1.el6.x86_64
Checking for unpackaged file(s): /usr/lib/rpm/check-files /root/rpmbuild/BUILDROOT/apcupsd-3.14.10-1.el6.x86_64
Wrote: /root/rpmbuild/SRPMS/apcupsd-3.14.10-1.el6.src.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/apcupsd-3.14.10-1.el6.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/apcupsd-debuginfo-3.14.10-1.el6.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.YeM7uD
+ umask 022
+ cd /root/rpmbuild/BUILD
+ cd apcupsd-3.14.10
+ /bin/rm -rf /root/rpmbuild/BUILDROOT/apcupsd-3.14.10-1.el6.x86_64
+ exit 0

Now install the RPM;

rpm -Uvh ~/rpmbuild/RPMS/x86_64/apcupsd-3.14.10-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:apcupsd                ########################################### [100%]

Done!

Installing AN!Built RPM

This is a shortcut of AN!, but if you feel brave to try it yourself;

yum install gd
rpm -Uvh https://alteeve.ca/cluster/apcupsd-3.14.10-1.el6.x86_64.rpm

Installing on CentOS

APC UPSes

The easiest way to setup apcupsd is via EPEL. This will install it in such a way that EPEL packages will never mess with core RHEL packages.

Add The EPEL Repo

Template note icon.png
Note: These are version-specific links. They may break as updated packages are released.
yum -y install yum-protectbase
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt # import keys 
rpm -K rpmforge-release-0.5.2-2.el6.rf.*.rpm # verify package integrity 
rpm -i rpmforge-release-0.5.2-2.el6.rf.*.rpm # install

This link may break when a new version of the RPM is released. If this fails, please check here for the updated epel-release package.

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm

Now edit the base repositories to protect the base RPMs from being changed by updated versions found in EPEL.

cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.orig
vim /etc/yum.repos.d/CentOS-Base.repo

Add protect=1 to the [base], [updates], [extras] and [contrib]. Note that RHEL machines may not have all these repos.

diff -u /etc/yum.repos.d/CentOS-Base.repo.orig /etc/yum.repos.d/CentOS-Base.repo
--- /etc/yum.repos.d/CentOS-Base.repo.orig	2012-08-19 15:05:24.350787587 -0400
+++ /etc/yum.repos.d/CentOS-Base.repo	2012-08-19 15:04:58.000000000 -0400
@@ -16,6 +16,7 @@
 #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
 gpgcheck=1
 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
+protect=1
 
 #released updates 
 [updates]
@@ -24,6 +25,7 @@
 #baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
 gpgcheck=1
 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
+protect=1
 
 #additional packages that may be useful
 [extras]
@@ -32,6 +34,7 @@
 #baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
 gpgcheck=1
 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
+protect=1
 
 #additional packages that extend functionality of existing packages
 [centosplus]
@@ -50,3 +53,4 @@
 gpgcheck=1
 enabled=0
 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
+protect=1

Now unprotect the EPEL repo as any conflicts that might arise should be replaced by the official versions.

cp /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.orig
vim /etc/yum.repos.d/epel.repo

This time, add protect=0 to [epel], [epel-debuginfo] and [epel-source].

diff -u /etc/yum.repos.d/epel.repo.orig /etc/yum.repos.d/epel.repo
--- /etc/yum.repos.d/epel.repo.orig	2012-08-19 15:24:47.631307949 -0400
+++ /etc/yum.repos.d/epel.repo	2012-08-19 15:26:31.119599427 -0400
@@ -6,6 +6,7 @@
 enabled=1
 gpgcheck=1
 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
+protect=0
 
 [epel-debuginfo]
 name=Extra Packages for Enterprise Linux 6 - $basearch - Debug
@@ -15,6 +16,7 @@
 enabled=0
 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
 gpgcheck=1
+protect=0
 
 [epel-source]
 name=Extra Packages for Enterprise Linux 6 - $basearch - Source
@@ -24,3 +26,4 @@
 enabled=0
 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
 gpgcheck=1
+protect=0

Install apcupsd

To install apcupsd, simply run;

yum install apcupsd

Now setup the configuration file:

cp /etc/apcupsd/apcupsd.conf /etc/apcupsd/apcupsd.conf.orig
vim /etc/apcupsd/apcupsd.conf

The main arguments to change/set are;

  • UPSNAME - Important if you will be setting up two or more UPSes. Optional otherwise.
  • UPSTYPE - This needs to be set to snmp to enable network access to the UPS's stats.
  • DEVICE - This is where we tell the apcupsd daemon where to find the UPS. For most people, this should be set to 10.20.3.1:161:APC:private, substituting 10.20.3.1 for the IP of your UPS.

In our case, we don't want apcupsd to shut down the server. We'll handle the shutdown using AN!CM. We also want to tighten up the check time to 30 seconds. If you are not using this with an AN!Cluster, then you may wish to alter how these are set. So, for our needs, we also want to set the following;

  • POLLTIME - Set this to the number of seconds you want apcupsd to check for changes in the UPS. The lower this number, the higher the overhead.
  • BATTERYLEVEL - This sets the remaining battery percentage at which point apcupsd will initiate a shutdown of the host.
  • MINUTES - This sets the remaining nunmber of minutes (according to the UPS itself) at which point apcupsd will initiate a shutdown of the host. In our case, AN!CM will trigger a withdrawl sooner than this anyway.
diff -u /etc/apcupsd/apcupsd.conf.orig /etc/apcupsd/apcupsd.conf
--- /etc/apcupsd/apcupsd.conf.orig	2012-08-19 16:03:10.521542722 -0400
+++ /etc/apcupsd/apcupsd.conf	2012-08-19 16:47:26.938607712 -0400
@@ -12,7 +12,7 @@
 #   Use this to give your UPS a name in log files and such. This
 #   is particulary useful if you have multiple UPSes. This does not
 #   set the EEPROM. It should be 8 characters or less.
-#UPSNAME
+UPSNAME an-u01
 
 # UPSCABLE <cable>
 #   Defines the type of cable connecting the UPS to your computer.
@@ -76,8 +76,8 @@
 #                            3052. If this parameter is empty or missing, the 
 #                            default of 3052 will be used.
 #
-UPSTYPE apcsmart
-DEVICE /dev/ttyS0
+UPSTYPE snmp
+DEVICE 10.20.3.1:161:APC:private
 
 # POLLTIME <int>
 #   Interval (in seconds) at which apcupsd polls the UPS for status. This
@@ -86,7 +86,7 @@
 #   will improve apcupsd's responsiveness to certain events at the cost of
 #   higher CPU utilization. The default of 60 is appropriate for most
 #   situations.
-#POLLTIME 60
+POLLTIME 30
 
 # LOCKFILE <path to lockfile>
 #   Path for device lock file. Not used on Win32.
@@ -132,12 +132,12 @@
 # If during a power failure, the remaining battery percentage
 # (as reported by the UPS) is below or equal to BATTERYLEVEL, 
 # apcupsd will initiate a system shutdown.
-BATTERYLEVEL 5
+BATTERYLEVEL 0
 
 # If during a power failure, the remaining runtime in minutes 
 # (as calculated internally by the UPS) is below or equal to MINUTES,
 # apcupsd, will initiate a system shutdown.
-MINUTES 3
+MINUTES 0
 
 # If during a power failure, the UPS has run on batteries for TIMEOUT
 # many seconds or longer, apcupsd will initiate a system shutdown.

Now start the apcupsd daemon.

chkconfig apcupsd on
/etc/init.d/apcupsd start
Starting UPS monitoring:                                   [  OK  ]

You can confirm that it's working via apcaccess

apcaccess
APC      : 001,050,1228
DATE     : 2012-08-19 17:25:59 -0400  
HOSTNAME : an-c01n01.alteeve.ca
VERSION  : 3.14.10 (13 September 2011) redhat
UPSNAME  : APCUPS
CABLE    : Ethernet Link
DRIVER   : SNMP UPS Driver
UPSMODE  : Stand Alone
STARTTIME: 2012-08-19 17:24:58 -0400  
MODEL    : Smart-UPS 1500
STATUS   : ONLINE 
LINEV    : 124.0 Volts
LOADPCT  :  16.0 Percent Load Capacity
BCHARGE  : 093.0 Percent
TIMELEFT :  71.0 Minutes
MBATTCHG : 0 Percent
MINTIMEL : 0 Minutes
MAXTIME  : 0 Seconds
MAXLINEV : 124.0 Volts
MINLINEV : 123.0 Volts
OUTPUTV  : 123.0 Volts
SENSE    : High
DWAKE    : 000 Seconds
DSHUTD   : 000 Seconds
DLOWBATT : 02 Minutes
LOTRANS  : 106.0 Volts
HITRANS  : 127.0 Volts
RETPCT   : 35594256.0 Percent
ITEMP    : 23.0 C Internal
ALARMDEL : 30 seconds
BATTV    : 27.0 Volts
LINEFREQ : 60.0 Hz
LASTXFER : Line voltage notch or spike
NUMXFERS : 0
TONBATT  : 0 seconds
CUMONBATT: 0 seconds
XOFFBATT : N/A
SELFTEST : OK
STESTI   : OFF
STATFLAG : 0x07000008 Status Flag
MANDATE  : 06/08/2012
SERIALNO : xxxxxxxxxxxx
BATTDATE : 06/08/2012
NOMOUTV  : 120 Volts
NOMBATTV : 35594256.0 Volts
HUMIDITY :   0.0 Percent
AMBTEMP  :   0.0 C
EXTBATTS : 35594256
BADBATTS : 0
FIRMWARE : UPS 08.3 / MCU 14.0
END APC  : 2012-08-19 17:26:28 -0400

Likewise, you can test by pulling the UPS from the mains and within POLLTIME seconds you should see a broadcast message on all terminals. Plug the UPS back into mains and again within POLLTIME seconds you should see another broadcast saying that power has been restored.

Broadcast message from root@an-c01n01.alteeve.ca (Sun Aug 19 16:51:33 2012):
 
Power failure on UPS APCUPS. Running on batteries.
 
Broadcast message from root@an-c01n01.alteeve.ca (Sun Aug 19 16:52:09 2012):
 
Power has returned on UPS APCUPS...

Done!

Monitoring 2 or More APC UPSes at Once

This section was improved and rewritten as part of a the Second edition of the AN!Cluster Tutorial 2. It improved on what used to be here by a good degree.

Instead of maintaining two copies of the same tutorial, please jump over there. The multi-UPS section stands alone well, so you do not need to worry about any other part of the tutorial in order to configure multi-UPS monitoring.

 

Any questions, feedback, advice, complaints or meanderings are welcome.
Us: Alteeve's Niche! Support: Mailing List IRC: #clusterlabs on Freenode   © Alteeve's Niche! Inc. 1997-2019
legal stuff: All info is provided "As-Is". Do not use anything here unless you are willing and able to take responsibility for your own actions.
Personal tools
Namespaces

Variants
Actions
Navigation
projects
Toolbox