Using NUT with a UPS
From CLUG Wiki
This is a new page, and might contain technically incorrect information. Please use at your own risk. If you are able to correct any errors or expand this document, please do so.
Warning: This is a Debian-centric page
This page is written by a Debian user with Debian in mind. Thus, he liberally uses apt-get, and assumes that
everything will work exactly the same for you.
If you don't run Debian (or something based on it like Ubuntu), it won't, so please find the differences and add them to this page.
Network UPS Tools (NUT) is software that can be used to monitor a UPS and also interact with it. (Note that APC UPSs have their own monitoring daemon, apcupsd). This is a HowTo about my experiences with the Powercom Black Knight UPS. I still have one issue left, but there is a little work around. Maybe someone can point me in the right direction.
First off:
apt-get install nut
Here is my copy and paste solution for NUT. Just make sure that ttyS? is pointing to the right serial port. The permissions for the serial port I put in /etc/init.d/ups-monitor under the start) section to set it on every boot. The important change here is shutdownArguments in ups.conf. This is to force the UPS to power down after your shutdown. If you don't power down the UPS, it will trickle feed the motherboard while on battery. This means that the Power On after AC failure set in the Bios will never kick in when the power gets restored.
chown nut:nut /dev/ttyS0
chmod 0600 /dev/ttyS0
### Set defaults to on
echo "START_UPSD=yes" > /etc/default/nut
echo "START_UPSMON=yes" >> /etc/default/nut
### Set up UPS on current PC
echo "[me]" > /etc/nut/ups.conf
echo " driver = powercom" >> /etc/nut/ups.conf
echo " port = /dev/ttyS0" >> /etc/nut/ups.conf
echo " shutdownArguments = {{0,10},y}" >> /etc/nut/ups.conf
echo " type = KIN1500AP" >> /etc/nut/ups.conf
### Set upsd.conf
echo "ACL all 0.0.0.0/0" > /etc/nut/upsd.conf
echo "ACL localhost 127.0.0.1/32" >> /etc/nut/upsd.conf
echo "ACCEPT localhost" >> /etc/nut/upsd.conf
echo "REJECT all" >> /etc/nut/upsd.conf
### Make empty upsd.users
echo "[monuser]" > /etc/nut/upsd.users
echo " password = pass" >> /etc/nut/upsd.users
echo " allowfrom = mybox" >> /etc/nut/upsd.users
echo " upsmon master" >> /etc/nut/upsd.users
### Set upsmon.conf
echo "POWERDOWNFLAG /etc/killpower" > /etc/nut/upsmon.conf
echo "MONITOR me@localhost 1 monuser pass master" >> /etc/nut/upsmon.conf
echo "SHUTDOWNCMD /opt/shutdown" >> /etc/nut/upsmon.conf
echo "#!/bin/bash" > /opt/shutdown
echo "" >> /opt/shutdown
echo "/sbin/shutdown -h -P now" >> /opt/shutdown
chmod 755 /opt/shutdown
One thing I did was to edit /etc/init.d/halt. I commented out the two lines above and the 1 line below /etc/init.d/ups-monitor poweroff I still need to figure how to get the UPS to shutdown without changing the init scripts.
# if [ "$INIT_HALT" = "POWEROFF" ] && [ -x /etc/init.d/ups-monitor ]
# then
/etc/init.d/ups-monitor poweroff
# fi
The reason I went for a shutdown script, instead of just calling shutdown, is that you can add some extra tasks to the script before power down. Something like mailing eskom and telling them that you suspect that there is a problem with the power.
To test that everything is working fine. Run upsdrvctl start. This will start the driver and start talking to the UPS. Any errors here could be wrong serial port, wrong permissions on serial port, driver settings. If all is fine you can run upsc me@localhost. This should print out all kinds of info from the UPS.
Hope this helps. Please edit this page to pieces and report on other UPS models.
