wiki:VmwareESX41ToSmartUPS
Last modified 9 years ago Last modified on 11/18/10 04:32:21

Running APC UPS Daemon on ESX 4.1 Host

1) Connect serial ports on ESX Host and Smart-UPS device with a Smart Signaling Cable (e.g. 940-0024C, or 940-1524C).

2) Install the apcupsd package built for the Enterprise Linux version corresponding to that of COS.

# cat /etc/*-release 
Red Hat Enterprise Linux Server release 5.1 (Tikanga)
VMware ESX 4.1 (Kandinsky)
# uname -i
x86_64
#
# rpm -i apcupsd-3.14.8-1.el5.x86_64.rpm
#

3) Modify the apcupsd run-control script to work around shared library version mismatch.

# ldd /sbin/apcupsd
/sbin/apcupsd: /usr/lib/vmware/lib64/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /sbin/apcupsd)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003926200000)
        libcrypto.so.6 => /lib64/libcrypto.so.6 (0x0000003925600000)
        libnetsnmp.so.10 => /usr/lib64/libnetsnmp.so.10 (0x0000003925a00000)
        libgcc_s.so.1 => /usr/lib/vmware/lib64/libgcc_s.so.1 (0x0000003926800000)
        libc.so.6 => /lib64/libc.so.6 (0x0000003924e00000)
        /lib64/ld-linux-x86-64.so.2 (0x0000003924a00000)
        libdl.so.2 => /lib64/libdl.so.2 (0x0000003925200000)
        libz.so.1 => /usr/lib/vmware/lib64/libz.so.1 (0x0000003926600000)
#
# strings /usr/lib/vmware/lib64/libgcc_s.so.1 |grep GCC_4
GCC_4.0.0
#
# LD_LIBRARY_PATH="/lib64:/usr/lib64:/lib:/usr/lib" ldd /sbin/apcupsd
        libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003926200000)
        libcrypto.so.6 => /lib64/libcrypto.so.6 (0x0000003925600000)
        libnetsnmp.so.10 => /usr/lib64/libnetsnmp.so.10 (0x0000003925a00000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00002aaaaf3eb000)
        libc.so.6 => /lib64/libc.so.6 (0x0000003924e00000)
        /lib64/ld-linux-x86-64.so.2 (0x0000003924a00000)
        libdl.so.2 => /lib64/libdl.so.2 (0x0000003925200000)
        libz.so.1 => /usr/lib64/libz.so.1 (0x00002aaaaf5fa000)
#
# strings /lib64/libgcc_s.so.1 |grep GCC_4
GCC_4.0.0
GCC_4.2.0
#
#
# cp -a /etc/rc.d/init.d/apcupsd /etc/rc.d/init.d/apcupsd.orig
# vi /etc/rc.d/init.d/apcupsd
# diff -U 2 /etc/rc.d/init.d/apcupsd.orig /etc/rc.d/init.d/apcupsd
--- /etc/rc.d/init.d/apcupsd.orig       2010-01-18 14:59:07.000000000 -0800
+++ /etc/rc.d/init.d/apcupsd    2010-11-15 14:26:19.000000000 -0800
@@ -7,4 +7,5 @@
 # description: apcupsd monitors power and takes action if necessary
 #
+LD_LIBRARY_PATH="/lib64:/usr/lib64:/lib:/usr/lib" ; export LD_LIBRARY_PATH
 APCPID=/var/run/apcupsd.pid
 
#

4) Configure the apcupsd daemon.

# cp -a /etc/apcupsd/apcupsd.conf /etc/apcupsd/apcupsd.conf.orig
# vi /etc/apcupsd/apcupsd.conf
# egrep '^(UPS|DEVICE)' /etc/apcupsd/apcupsd.conf
UPSNAME UPS-A
UPSCABLE 940-0024C
UPSTYPE apcsmart
DEVICE /dev/ttyS0
UPSCLASS standalone
UPSMODE disable
#

5) If need to configure UPS parameters (e.g. the UPSNAME), run the apctest utility.

# LD_LIBRARY_PATH="/lib64:/usr/lib64:/lib:/usr/lib" /sbin/apctest

6) Start the daemon. Make sure it will start again after reboot.

# service apcupsd start
Starting UPS monitoring:                                   [  OK  ]
#
# chkconfig apcupsd on
# chkconfig --list apcupsd 
apcupsd         0:off   1:off   2:on    3:on    4:on    5:on    6:off
#

7) Check the UPS status.

# service apcupsd status
apcupsd (pid 21893) is running...
APC      : 001,050,1203
DATE     : 2010-11-15 17:29:21 -0800  
HOSTNAME : esx41-1
VERSION  : 3.14.8 (16 January 2010) redhat
UPSNAME  : UPS-A
CABLE    : APC Cable 940-0024C
MODEL    : Smart-UPS 3000 XL
UPSMODE  : Stand Alone
STARTTIME: 2010-11-15 14:26:25 -0800  
STATUS   : ONLINE 
LINEV    : 119.5 Volts
LOADPCT  :  66.9 Percent Load Capacity
BCHARGE  : 100.0 Percent
TIMELEFT :  25.0 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 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    : 22.5 C Internal
ALARMDEL : 5 seconds
BATTV    : 55.4 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  : 03/09/10
SERIALNO : AS1011290020
BATTDATE : 03/09/10
NOMOUTV  : 120 Volts
NOMBATTV :  48.0 Volts
EXTBATTS : 0
FIRMWARE : 691.19.D
APCMODEL : FWD
END APC  : 2010-11-15 17:29:44 -0800  
# 

8) If there are slave APCUPSd servers on the the LAN (or want to run the multimon CGI script on a separate host/virtual machine), allow remote connections to the NIS service by creating an opening (tcp#3551) in the host firewall.

# esxcfg-firewall --ipruleAdd 10.4.8.32/27,3551,tcp,ACCEPT,"apcupsd"
#
# esxcfg-firewall -q |grep 3551
    4   168 ACCEPT     tcp  --  *      *       10.4.8.32/27         0.0.0.0/0           tcp dpt:3551 
        apcupsd             : host 10.4.8.32/27 cport 3551 ACCEPT tcp 
#

9) Install MTA (Postfix) and MUA (/bin/mail) for being able to get notifications about power failures, and such.

# rpm -i --nodeps postfix-2.3.3-2.1.el5_2.x86_64.rpm
# rpm -i mailx-8.1.1-44.2.2.x86_64.rpm

10) Create the doshutdown script that will attempt graceful shutdown of all active virtual machines, and then will put host into the Maintenance Mode.

# vi /etc/apcupsd/doshutdown
#
# pr -to3 /etc/apcupsd/doshutdown
   #!/bin/sh
   #
   # doshutdown - attempt graceful shutdown of all running VMs
   #
   SYSADMIN=root
   MAIL_CMD=/bin/mail
   VMWARE_CMD=/usr/bin/vmware-cmd
   #DO_CMD=echo
   DO_CMD=eval
   HOSTNAME=`uname -n | tr '[a-z]' '[A-Z]'`
   MSG="Initiating VM shutdown on the $HOSTNAME host"
   #
   ( echo "$MSG" ; echo ; /sbin/apcaccess status ) |\
     $MAIL_CMD -s "$MSG" $SYSADMIN
   
   $VMWARE_CMD -l |(while read vm; do
     vm="`echo $vm |sed -e 's/ /\\\\ /g'`"
     if [ -n "$vm" ]; then
       case `eval $VMWARE_CMD $vm getstate` in
         "getstate() = on") $DO_CMD "$VMWARE_CMD $vm stop trysoft" ;;
       esac
     fi
   done)
   /usr/bin/vmware-vim-cmd /hostsvc/maintenance_mode_enter
   exit 0
   
   ### End-Of-File
#
# chmod 744 /etc/apcupsd/doshutdown
#

See Also

http://www.apcupsd.org/
Apcupsd, a daemon for controlling APC UPSes