Setup apcupsd For Multiple Network-Enabled APC UPSes On EL6: Difference between revisions

From Alteeve Wiki
Jump to navigation Jump to search
Line 382: Line 382:
chmod 755 /etc/init.d/apcupsd
chmod 755 /etc/init.d/apcupsd
</source>
</source>
<source lang="text">
/source>


'''''Alternatively''''';
'''''Alternatively''''';

Revision as of 02:55, 1 October 2012

 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.

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. However, if the client has official RHEL support, consult with Red Hat to ensure this doesn't violate support. If it does, discuss alternative options.

Add The EPEL Repo

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

Note: This section is based off of this document on the official apcupsd website. However, changes are made to reflect our UPSes being network connected and specifically for EL6.

To setup apcupsd to support multiple APC UPSes, we need to duplicate the configuration file. To do this, first stop the apcupsd daemon.

/etc/init.d/apcupsd stop
Shutting down UPS monitoring:                              [  OK  ]
Note: The new name of the configuration file needs to be in the format apcupsd.*.conf. This tutorial stays in line with the original tutorial by using upsX.

Next rename the existing stock configuration and then copy it for the second (and third...) UPSes.

mv /etc/apcupsd/apcupsd.conf /etc/apcupsd/apcupsd.ups0.conf
cp /etc/apcupsd/apcupsd.ups0.conf /etc/apcupsd/apcupsd.ups1.conf

Edit the new apcupsd.ups1.conf file to reflect the configuration of the second UPS. Note in a few key changes;

  • DEVICE - The vendor portion has to change from APC to APC_NOTRAP. Without this change, both daemons will try to listen to the same port for SNMP traps and, thus, cause the second daemon to fail with the error bind: Address already in use (only visible if the daemon is started manually with the -d 1 switch).
  • The second daemon needs to have it's scripts set to a new, empty directory called /etc/apcupsd/null to avoid conflicts. For us, this is fine because we won't be using apcupsd to shutdown the hosts.
vim /etc/apcupsd/apcupsd.ups1.conf
diff -u /etc/apcupsd/apcupsd.ups0.conf /etc/apcupsd/apcupsd.ups1.conf
--- /etc/apcupsd/apcupsd.ups0.conf	2012-08-19 21:05:08.558601798 -0400
+++ /etc/apcupsd/apcupsd.ups1.conf	2012-08-19 21:05:22.035606926 -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 ups0
+UPSNAME ups1
 
 # UPSCABLE <cable>
 #   Defines the type of cable connecting the UPS to your computer.
@@ -77,7 +77,7 @@
 #                            default of 3052 will be used.
 #
 UPSTYPE snmp
-DEVICE 10.20.3.1:161:APC_NOTRAP:private
+DEVICE 10.20.3.2:161:APC_NOTRAP:private
 
 # POLLTIME <int>
 #   Interval (in seconds) at which apcupsd polls the UPS for status. This
@@ -94,19 +94,19 @@
 
 # SCRIPTDIR <path to script directory>
 #   Directory in which apccontrol and event scripts are located.
-SCRIPTDIR /etc/apcupsd
+SCRIPTDIR /etc/apcupsd/null
 
 # PWRFAILDIR <path to powerfail directory>
 #   Directory in which to write the powerfail flag file. This file
 #   is created when apcupsd initiates a system shutdown and is
 #   checked in the OS halt scripts to determine if a killpower
 #   (turning off UPS output power) is required.
-PWRFAILDIR /etc/apcupsd
+PWRFAILDIR /etc/apcupsd/null
 
 # NOLOGINDIR <path to nologin directory>
 #   Directory in which to write the nologin file. The existence
 #   of this flag file tells the OS to disallow new logins.
-NOLOGINDIR /etc
+NOLOGINDIR /etc/apcupsd/null
 
 
 #
@@ -199,11 +199,11 @@
 #  It is not used unless NETSERVER is on. If you change this port,
 #  you will need to change the corresponding value in the cgi directory
 #  and rebuild the cgi programs.
-NISPORT 3551
+NISPORT 3552
 
 # If you want the last few EVENTS to be available over the network
 # by the network information server, you must define an EVENTSFILE.
-EVENTSFILE /var/log/apcupsd.0.events
+EVENTSFILE /var/log/apcupsd.1.events
 
 # EVENTSFILEMAX <kilobytes>
 #  By default, the size of the EVENTSFILE will be not be allowed to exceed

Create the empty script directory;

mkdir /etc/apcupsd/null

Now the tricky part... We need to alter the init.d script so that it fires multiple daemons, one for each configuration.

We can't make the usual backup, so we'll put a copy of the original version in the root user's home directory.

cp /etc/init.d/apcupsd /root/apcupsd.init.orig

Now you have two choices; Edit the init.d script yourself or download a copy from this website.

To download a updated/multi-UPS copy, run:

rm -f /etc/init.d/apcupsd
wget https://alteeve.ca/files/apcupsd -O /etc/init.d/apcupsd
chmod 755 /etc/init.d/apcupsd

Alternatively;

Now to edit it to fire on multiple config files;

vim /etc/init.d/apcupsd
diff -u /root/apcupsd.init.orig /etc/init.d/apcupsd
--- /root/apcupsd.init.orig	2012-08-19 17:47:28.766433318 -0400
+++ /etc/init.d/apcupsd	2012-08-19 18:36:33.554601345 -0400
@@ -1,7 +1,7 @@
 #! /bin/sh
 #
 # apcupsd      This shell script takes care of starting and stopping
-#	       the apcupsd UPS monitoring daemon.
+#	       the apcupsd UPS monitoring daemon. Multi-UPS version.
 #
 # chkconfig: 2345 60 99
 # description: apcupsd monitors power and takes action if necessary
@@ -15,18 +15,24 @@
     start)
        rm -f /etc/apcupsd/powerfail
        rm -f /etc/nologin
-       echo -n "Starting UPS monitoring:" 
-       daemon /sbin/apcupsd -f /etc/apcupsd/apcupsd.conf
-       RETVAL=$?
-       echo
-       [ $RETVAL -eq 0 ] && touch /var/lock/subsys/apcupsd
+       for conf in /etc/apcupsd/apcupsd.*.conf ; do
+          inst=`basename $conf`
+          echo -n "Starting UPS monitoring ($inst):"
+          daemon /sbin/apcupsd -f $conf -P /var/run/apcupsd-$inst.pid
+          RETVAL=$?
+          echo
+          [ $RETVAL -eq 0 ] && touch /var/lock/subsys/apcupsd-$inst
+       done
        ;;
     stop)
-       echo -n "Shutting down UPS monitoring:"
-       killproc apcupsd
-       echo
-       rm -f $APCPID
-       rm -f /var/lock/subsys/apcupsd
+       for conf in /etc/apcupsd/apcupsd.*.conf ; do
+          inst=`basename $conf`
+          echo -n "Shutting down UPS monitoring ($inst):"
+          killproc -p /var/run/apcupsd-$inst.pid apcupsd
+          echo
+          rm -f /var/run/apcupsd-$inst.pid
+          rm -f /var/lock/subsys/apcupsd-$inst
+       done
        ;;
     restart|force-reload)
        $0 stop
@@ -38,14 +44,16 @@
        exit 3
        ;;
     status)
-       status apcupsd
-       RETVAL=$?
-       if [ $RETVAL -eq 0 ]
-       then
-          /sbin/apcaccess status
-       else
-          exit $RETVAL
-       fi
+       for conf in /etc/apcupsd/apcupsd.*.conf ; do
+          inst=`basename $conf`
+          status -p /var/run/apcupsd-$inst.pid apcupsd-$inst
+          RETVAL=$?
+          if [ $RETVAL -eq 0 ]
+          then
+             NISPORT=`grep ^NISPORT < $conf | sed -e "s/NISPORT *\([0-9]\)/\1/"`
+             /sbin/apcaccess status localhost:$NISPORT | egrep "(STATUS)|(UPSNAME)"
+          fi
+       done
        ;;
     *)
        echo "Usage: $0 {start|stop|restart|status}"

With the new init.d script in place, we can restart the daemon. This time, two instances will start, one for each of our configurations.

/etc/init.d/apcupsd start
Starting UPS monitoring (apcupsd.ups0.conf):               [  OK  ]
Starting UPS monitoring (apcupsd.ups1.conf):               [  OK  ]

Now confirm that both daemons actually started;

/etc/init.d/apcupsd status
apcupsd-apcupsd.ups0.conf (pid  12424) is running...
UPSNAME  : APCUPS
STATUS   : ONLINE 
apcupsd-apcupsd.ups1.conf (pid  12430) is running...
UPSNAME  : APCUPS
STATUS   : ONLINE

To check the states of each UPS will require calling apcaccess using the arguments needed to talk to the appropriate apcupsd daemon.

Check the first UPS;

apcaccess status localhost:3551
APC      : 001,050,1242
DATE     : 2012-08-19 21:33:09 -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 21:06:04 -0400  
MODEL    : Smart-UPS 1500
STATUS   : ONLINE 
LINEV    : 123.0 Volts
LOADPCT  :  17.0 Percent Load Capacity
BCHARGE  : 100.0 Percent
TIMELEFT :  75.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   : 31281168.0 Percent
ITEMP    : 25.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 : 31281168.0 Volts
HUMIDITY : 6519592.0 Percent
AMBTEMP  : 6519592.0 C
EXTBATTS : 31281168
BADBATTS : 6519592
FIRMWARE : UPS 08.3 / MCU 14.0
END APC  : 2012-08-19 21:33:19 -0400

Check the second UPS;

apcaccess status localhost:3552
APC      : 001,050,1240
DATE     : 2012-08-19 21:33:10 -0400  
HOSTNAME : pp-c01n01.plasticplus.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 21:06:04 -0400  
MODEL    : Smart-UPS 1500
STATUS   : ONLINE 
LINEV    : 123.0 Volts
LOADPCT  :  16.0 Percent Load Capacity
BCHARGE  : 100.0 Percent
TIMELEFT :  77.0 Minutes
MBATTCHG : 0 Percent
MINTIMEL : 0 Minutes
MAXTIME  : 0 Seconds
MAXLINEV : 123.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   : 35442704.0 Percent
ITEMP    : 23.0 C Internal
ALARMDEL : 30 seconds
BATTV    : 27.0 Volts
LINEFREQ : 60.0 Hz
LASTXFER : No transfers since turnon
NUMXFERS : 0
TONBATT  : 0 seconds
CUMONBATT: 0 seconds
XOFFBATT : N/A
SELFTEST : OK
STESTI   : OFF
STATFLAG : 0x07000008 Status Flag
MANDATE  : 06/08/2012
SERIALNO : yyyyyyyyyyyy
BATTDATE : 06/08/2012
NOMOUTV  : 120 Volts
NOMBATTV : 35442704.0 Volts
HUMIDITY : 6519592.0 Percent
AMBTEMP  : 6519592.0 C
EXTBATTS : 35442704
BADBATTS : 6519592
FIRMWARE : UPS 08.3 / MCU 14.0
END APC  : 2012-08-19 21:33:20 -0400

That's it! You can now check the status of each node.

 

Any questions, feedback, advice, complaints or meanderings are welcome.
Alteeve's Niche! Enterprise Support:
Alteeve Support
Community Support
© Alteeve's Niche! Inc. 1997-2024   Anvil! "Intelligent Availability®" Platform
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.