Configuring NUT for the Eaton 3S UPS on Ubuntu Linux

Feb 27, 2013 LinuxNUTUbuntuUPS

Note: Since this post was published I’ve installed and tests on Ubuntu Server 14.04 and have highlighted the difference between Ubuntu 14.04 and 12.04 at the end of this post.

This post explains how to configure Network UPS Tools (NUT) to work with an Eaton 3S UPS on a stand-alone Ubuntu 12.04 PC (Nut version 2.6.3).

Network UPS Tools (NUT) seems to be the most widely supported and used UPS management package for Linux. It is extremely flexible and caters for a wide range of UPS makes, models and deployment scenarios. The sheer scope and flexibility of NUT makes UPS selection and configuration daunting. The purpose of this article is to illustrate a minimal configuration to achieve stand-alone UPS management of a single Ubuntu 12.04 based PC.

NUT configuration

Here’s how this configuration works: when power has dropped out for more than 3 minutes NUT triggers a shutdown. The shutdown sequence closes down Ubuntu; commands the UPS to commence shutdown; and then turns off the PC. Once the PC is off the UPS turns off to conserve the UPS battery. When power is reestablished the UPS powers up and reapplies power to the PC (whether your PC turns on automatically at power resumption is determined by it’s BIOS settings).

Here are the minimal NUT configuration files:

/etc/nut/nut.conf

# Set MODE=none to disable UPS monitoring, MODE=standalone to enable UPS monitoring.
MODE=standalone

/etc/nut/ups.conf

[eaton3s]
driver=usbhid-ups
port=auto

/etc/nut/upsd.conf



/etc/nut/upsmon.conf

MONITOR eaton3s@localhost 1 monuser pass master
SHUTDOWNCMD "/sbin/shutdown -P now"
POWERDOWNFLAG /etc/killpower

NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC
NOTIFYCMD "/etc/nut/notifycmd"

/etc/nut/upssched.conf



/etc/nut/upsd.users

[monuser]
password=pass
upsmon master

The following notifycmd bash script handles NUT ONBATT and ONLINE events. Put it in /etc/nut, it is executed when NUT detects power resumption (prior to the 3 minute timeout) and when NUT detects the UPS has switched to battery (power outage). Don’t forget to make this script executable (sudo chmod +x /etc/nut/notifycmd).

/etc/nut/notifycmd

#!/bin/bash
#
# NUT NOTIFYCMD script

PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin

trap "exit 0" SIGTERM

if [ "$NOTIFYTYPE" = "ONLINE" ]
then
        echo $0: power restored | wall
        # Cause all instances of this script to exit.
        killall -s SIGTERM `basename $0`
fi

if [ "$NOTIFYTYPE" = "ONBATT" ]
then
        echo $0: 3 minutes till system powers down... | wall
        # Loop with one second interval to allow SIGTERM reception.
        let "n = 180"
        while [ $n -ne 0 ]
        do
                sleep 1
                let "n--"
        done
        echo $0: commencing shutdown | wall
        upsmon -c fsd
fi

Testing the UPS

UPS selection

The key to using a UPS with NUT is getting a UPS that is fully supported by the NUT version you are using (Ubuntu 12.04 has NUT 2.6.3). Here’s why I chose the Eaton 3S:

  1. It is fully supported by NUT UPS Tools 2.6.3 on Unbuntu 12.04 with the usbhid-ups driver.
  2. The vendor has a Linux commitment – they provide their own Intelligent Power Protector (IPP) software for Linux (I didn’t use it, choosing NUT instead).
  3. Readily available replacement battery.
  4. Other users report it works with Ubuntu 12.04.

Ubuntu 14.04

Since this post was originally published I’ve installed and tested Nut on Ubuntu Server 14.04 (Nut version 2.7.1) where I encountered an intermittent startup error viz. about one boot in six the UPS driver failed to connect leaving the following error in the syslog:

Poll UPS [eaton3s@localhost] failed - Driver not connected

I tried unsuccessfully to find the root of the problem by changing the startup order, in the end I worked around it by starting the Nut server at the end of the boot from /etc/rc.local:

# If UPS server driver is not connected then restart the server.
/bin/upsc eaton3s || /usr/sbin/service nut-server restart

NOTE: NUT in 14.04 has two startup services (replacing the single nut in 12.04): nut-client and nut-server – they are both started at reboot, aside from the startup error I have encountered no other differences in the move from Ubuntu 12.04 to 14.04.

« Previous Next »