Archive/XCP NUT

From Xen
Revision as of 10:38, 28 February 2012 by Angrygreenfrogs (talk | contribs) (Created page with "[http://www.networkupstools.org/ Network UPS Tools] are a handy set of tools for working with and managing and attached UPS (Uninterruptible Power Supply). The particular point …")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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