NUT

This is the the open source standard and while more complex than the APC tool, it much more powerful. It works with most models of UPS devices and can communicate over the network so that several systems can share a UPS and all handle events cleanly.

Installation

Ubuntu's LTS may have an older version that's not always compatible with newer UPS units, such as the Tripp Lite SmartPro (SMART500RT1U) for example. So check the available version at https://networkupstools.org/ and compare to what apt tells you below

$ apt-cache policy nut

If you want to install a newer version, add a repo like this one and install. Otherwise just install without adding the repo

sudo add-apt-repository ppa:clepple/nut 
sudo apt update
sudo apt install nut-server

Configuration

Define the UPS device and test.

The driver you choose below will depend on your device. For many, you can use the usbhid-ups driver. Others take a specific driver you can google for. A good test is to start with the basic and see if it works

sudo vim /etc/nut/ups.conf

# to the bottom add

[APC]
    driver=usbhid-ups
    port=auto

Test the device

sudo /lib/nut/usbhid-ups -a APC
        

If you get an error like

Can't claim USB device [051d:0002]: could not detach kernel driver from interface 0: Operation not permitted

You should try configuring USB rules next. Otherwise you can skip that part

Configure the USB rules

Assuming you're using a USB device, identity the vendor and product ID with the lsusb command

lsusb

Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 004: ID 051d:0002 American Power Conversion Uninterruptible Power Supply
Bus 001 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
Bus 001 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

Now, add a udev rule to allow access

sudo vim /etc/udev/rules.d/90-nut-ups.rules

# for APC UPS 051d:0002
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="051d", ATTR{idProduct}=="0002", MODE="0660", GROUP="nut"

And reboot - you can also restart udev and re-plug the devices, but you may not be near the system. Success will look something like this:

sudo /lib/nut/usbhid-ups -a APC

Network UPS Tools - Generic HID driver 0.41 (2.7.4)
USB communication driver 0.33
Using subdriver: APC HID 0.96

Lastly, start the UPS driver controller

sudo upsdrvctl start

Define the ups server users

Now that we know the UPS is responding to the driver and so can talk to the UPS network deamon, let's let's define a user account so we can talk to the UPS network daemon too.

sudo vim /etc/nut/upsd.users

[upsmon]
        password=XXXXX
        upsmon master

Configure client access

Now that we have a user account we can use upsmon to connect and take action when the server tells us something is up.

sudo vim /etc/nut/upsmon.conf

...
...
MONITOR APC@localhost 1 upsmon XXXXX master



Test

Enable the system

sudo vi /etc/nut/nut.conf

MODE=standalone

Start the ups daemon and monitor

sudo upsd
sudo service ups-monitor start

Get stats on the UPS

sudo upsc APC@localhost


Production

The ups deamon announces it's on battery power, then follows with a 'critical' warning when the UPS reaches 'low' state. It does this by comparing the UPS's current battery.charge and battery.runtime values to the UPS's battery.charge.low  and battery.runtime.low setpoints. The upsmon service will then issue a shutdown command.

If this isn't enough time to shut down, you should override that as described in the ignorelb at  https://networkupstools.org/docs/man/ups.conf.html

Don't forget to set the BIOS behavior for power restoration after power loss to 'restart'.

Troubleshooting

To see the various packages if the one above doesn't work, check

    https://launchpad.net/ubuntu/+ppas?name_filter=nut

Eaton and VMware issues

I was not able to get Eaton 3S series to work in a guest, despite them working on the same hardware non-virtualized and an APC unit worked fine in both.

https://nut-upsuser.alioth.debian.narkive.com/U2Kt6S5D/problem-connecting-to-eaton-ups-no-matching-hid-ups-found-driver-failed-to-start-exit-status-1



Comments