Archive/XCP NUT

From Xen

XCP 1.6 + EPEL 5 repo NUT setup (less file editing)

In this HOWTO I am using 2 Units rack-mounted UPS APC Smart-UPS SC1500 with COM-to-COM connection cable included with UPS. COM-to-USB seems to be more problematic in setup.

Check you COM port is available to OS

dmesg | grep ttyS
[   21.873093] serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[   21.873290] serial8250: ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A
[   21.874976] 00:09: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[   21.875207] 00:0a: ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A

If you can see this - seems like everything OK. If empty - check for disabled COM port at Integrated Peripherals in BIOS

Setup Epel repo

cat > /etc/yum.repos.d/epel.repo << EOF
[epel]
name=Extra Packages for Enterprise Linux 5 - $basearch
baseurl=http://dl.fedoraproject.org/pub/epel/5/i386/
failovermethod=priority
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
EOF

Install needed software from Epel repo

yum search nut --enablerepo=epel
yum install nut --enablerepo=epel,base

Check access to /dev/ttyS0 device file

ls -l /dev/ttyS0
crw-rw---- 1 root uucp 4, 64 Jan 22 14:21 /dev/ttyS0

In our case wee need to add nut user into group uucp

usermod -G uucp nut

Setup NUT

cat >> /etc/ups/ups.conf << EOF
[apc1500]
    driver = apcsmart
    port = /dev/ttyS0
    desc = "main UPS"
    sdtype = 1
EOF

Add into corresponding part of file:

cat >> /etc/ups/upsd.users << EOF
[admin]                                                                                                                                                                           
    password  = vVE69V_4vx                                                                                                                                                      
    actions = SET                                                                                                                                                                 
    instcmds = ALL                                                                                                                                                                
vi /etc/ups/upsmon.conf
MONITOR apc1500@localhost 1 admin vVE69V_4vx master

Change SHUTDOWNCMD in /etc/ups/upsmon.conf to

SHUTDOWNCMD "xe vm-shutdown --multiple power-state=running && /sbin/shutdown -h +0"

Start ups

/etc/init.d/ups start

Check UPS response

#upsc apc1500
battery.alarm.threshold: 0
battery.charge: 100.0
...

Old HOWTO

Network UPS Tools are a handy set of tools for working with and managing and attached UPS (Uninterruptible Power Supply).

The particular point of this howto is a simple example of how to configure NUT on a pair of Xen XCP dom0 hosts with the following assumptions:

host1 assumed to be attached via USB to the UPS device host2 on the same subnet as master, and is notified over TCP of changes in the power situation host1/host2 are assumed to be powered by the same UPS (e.g. as it was in our office when I wrote this example we had two servers plugged into the UPS) In the below example, host1's IP address is 192.168.41.21 The shutdown example below uses the "xe" command-line tool to shutdown any running XCP guests. I used a Powerware UPS, with the bcmxcp_usb USB driver included with NUT. You will certainly have to make adjustments as needed. This HowTo could definitely be improved by properly utilizing the 'nut' user account to run the management tools (my UPS had issues, so I gave up and ran everything as root), and also the init script could certainly be improved, it was written fairly quickly.

Install NUT on XCP host 1/2

wget http://download.alyseo.com:81/contrib/XenServer/v4.0.96/Nut/nut-2.2-1.i386.rpm
rpm -i nut-2.2-1.i386.rpm

Create a basic init script as there doesn't seem to be one in the NUT package I used.

vi /etc/init.d/nut

# Only on HOST2
# Comment out the start/stop lines for upsd and upsdrv, just leave upsmon
# Edit the driver 'bcmxcp_usb' below to match the driver from /usr/local/ups/bin/ that you'll be using.

#
#!/bin/bash
#
# chkconfig: - 80 20
# description: Nut
#
# processname: nut
# config: /usr/local/ups/etc/ups.conf
# pidfile: /var/run/nut

source /etc/rc.d/init.d/functions

RETVAL=0
prog="nut"
upsdrv="/usr/local/ups/bin/upsdrvctl"
drv="bcmxcp_usb"
upsd="/usr/local/ups/sbin/upsd"
ups="upsd"
upsmon="/usr/local/ups/sbin/upsmon"
mon="upsmon"
desc="NUT daemon"

start() {
        echo -n $"Starting $desc : "
        daemon $upsdrv -u root start
        $upsd -u root
        $upsmon -u root
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
        return $RETVAL
}

stop() {
        echo -n $"Shutting down $desc: "
        killproc $drv
        killproc $ups
        killproc $mon
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
        return $RETVAL
}

restart() {
        stop
        start
}

reload() {
        echo -n $"Reloading $desc: "
        killproc $drv -HUP
        killproc $ups -HUP
        killproc $mon -HUP
        RETVAL=$?
        echo
        return $RETVAL
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  reload)
        reload
        ;;
  condrestart)
        [ -e /var/lock/subsys/$prog ] && restart
        RETVAL=$?
        ;;
  status)
        status $prog
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
        RETVAL=1
esac

exit $RETVAL
#
chmod +x /etc/init.d/nut
chkconfig --add nut

Configure NUT on XCP host 1/2

vi /usr/local/ups/etc/ups.conf

# comment out everything, add this:
user=root
[Powerware5110]
driver = bcmxcp_usb
port = auto

vi /usr/local/ups/etc/upsd.conf
# comment out everything, add this:

#use the below on HOST1
LISTEN localhost 3493
LISTEN 192.168.41.21 3493
ACL all 0.0.0.0/0
ACL localhost 127.0.0.1/32
ACL office 192.168.41.0/24
ACCEPT localhost
ACCEPT office
REJECT all

#use the below on HOST2
ACL all 0.0.0.0/0
ACL localhost 127.0.0.1/32
ACCEPT localhost
REJECT all
#

vi /usr/local/ups/etc/upsd.users
# comment out everything, add this:
[local_mon]
password = MYPASSWORD 
allowfrom = localhost
upsmon master
[office_mon]
password = MYPASSWORD 
allowfrom = office
upsmon master
#

vi /usr/local/ups/etc/upsmon.conf
#
# HOST1 (master with UPS attached)
MONITOR Powerware5110@localhost 1 local_mon MYPASSWORD master
SHUTDOWNCMD "xe vm-shutdown --multiple power-state=running && /sbin/shutdown -h +0"
# HOST2 (slave just networked to master)
MONITOR Powerware5110@192.168.41.21 1 office_mon MYPASSWORD master
SHUTDOWNCMD "xe vm-shutdown --multiple power-state=running && /sbin/shutdown -h +0"
#

Start everything up, run on both host1/host2

#start the service
service nut start
#run this to get some stats from the UPS to check connectivity
/usr/local/ups/bin/upsc Powerware5110