Ubuntu Nut UPS (with Eaton 3s)
Nut / UPS
https://srackham.wordpress.com/2013/02/27/configuring-nut-for-the-eaton-3s-ups-on-ubuntu-linux/
https://networkupstools.org/docs/man/usbhid-ups.html
https://networkupstools.org/stable-hcl.html
Status Values
https://networkupstools.org/docs/man/genericups.html
- OL - On line (no power failure) (opposite of OB - on battery)
- LB - Low battery
- SD - Shutdown load
- CP - Cable power (must be present for cable to have valid reading)
- CTS - Clear to Send. Received from the UPS.
- RTS - Ready to Send. Sent by the PC.
- DCD - Data Carrier Detect. Received from the UPS.
- RNG - Ring indicate. Received from the UPS.
- DTR - Data Terminal Ready. Sent by the PC.
- ST - Send a BREAK on the transmit data line
A "-" in front of a signal name (like -RNG) means that the indicated condition is signaled with an active low signal. For example, [LB=-RNG] means the battery is low when the ring indicate line goes low, and that the battery is OK when that line is held high.
Installation
-
apt-get install nut
-
lsusb
-
0463:ffff MGE UPS Systems UPS
-
-
vi /etc/default/nut
-
START_UPSD=yes UPSD_OPTIONS="" START_UPSMON=yes UPSMON_OPTIONS=""
-
- vi /etc/nut/ups.conf
- https://networkupstools.org/docs/man/ups.conf.html
-
[eaton3s] driver=usbhid-ups port=auto desc="EATON UPS" #offdelay=60 #ondelay=70 # Power down the server at a higher battery charge level (40%) than default 20% # This should help with older, weaker batteries ignorelb = yes override.battery.charge.low = 40 # !!! Comment out, invalid for Ubuntu 18.04: #maxretry = 3
- More options: https://networkupstools.org/docs/man/ups.conf.html
- vi /etc/nut/upsmon.conf
-
MONITOR eaton3s@localhost 1 monuser pass master SHUTDOWNCMD "/etc/nut/shutdown"
-
- vi /etc/nut/nut.conf
-
MODE=standalone
-
- vi /etc/nut/upsd.users
-
[monuser] password=pass upsmon master actions = SET instcmds = ALL
-
- vi /etc/nut/shutdown
-
#!/bin/bash # UPS didn't shutdown, so we wrote this script upsdrvctl stop upsdrvctl shutdown poweroff
-
- chmod 750 /etc/nut/shutdown
- chown root:nut /etc/nut/shutdown
- Reboot
Mute Beeper
- upscmd -l eaton3s
- upscmd eaton3s beeper.mute
- username: monuser
- password: pass
Test / Troubleshooting
- Ubuntu 16.04 and older
- service upsd status
- service upsmon status
- The commands above do not exist in Ubuntu 18.04. Instead?
- service nut-driver status
- service nut-server status
- service nut-monitor status
- lsusb
- Bus 001 Device 004: ID 0463:ffff MGE UPS Systems UPS
- upsc eaton3s
- upsmon -c fsd
- simulates a ups shutdown event, power down, upc cuts power, restarts
Problem: Nut Driver does not start
https://networkupstools.org/docs/man/usbhid-ups.html
- upsc eaton3s
- service nut-server status
- service nut-server restart
Try manual start and look for errors
- /sbin/upsdrvctl start
This in turn executes
- /lib/nut/usbhid-ups -a eaton3s
Problem: Nut Driver does not start up correctly on reboot
Old solution:
vi /etc/rc.local-
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # Sometime UPS driver does not start up correctly sleep 300 service nut-driver restart exit 0
-
Still occasional problems, ups usb device not found
Try usb reset... (did not work)
lspci | grep XHCI | cut -d' ' -f100:10.0
echo -n "0000:00:10.0" | tee /sys/bus/pci/drivers/xhci_hcd/unbindecho -n "0000:00:10.0" | tee /sys/bus/pci/drivers/xhci_hcd/bindlspci | grep EHCI | cut -d' ' -f1-
00:12.0
-
-
echo -n "0000:00:12.0" | tee /sys/bus/pci/drivers/ehci-pci/unbind -
echo -n "0000:00:12.0" | tee /sys/bus/pci/drivers/ehci-pci/bind
---
https://github.com/networkupstools/nut/issues/515
service nut-driver restart;service nut-driver statuslsusb -vBus 001 Device 004: ID 0463:ffff MGE UPS Systems UPS
/lib/nut/usbhid-ups -a eaton3s -DDD/lib/nut/usbhid-ups -a eaton3s -DDD -x explore -x vendorid=0x0463
Cron Job
Eaton 3s has regular driver connection problems. Some times it takes multiple tries to connect to the UPS.
This cronjob checks the USP connection every five minutes and restarts the driver if necessary.
If it still does not work, try another USB port, a USB 2.0 port if available and finally a (better?) USB cable.
- vi /etc/cron.d/nutups
-
# check nut ups driver and force reload if failure */5 * * * * root upsc eaton3s ups.status > /dev/null 2>&1; if [ $? != 0 ]; then echo "UPS driver connection failed, trying restart..." >&2; systemctl restart nut-driver; fi
-
- chmod 755 /etc/cron.d/nutups
Power off another server
Goal: the master server with the UPS connected, should shutdown other server(s), e.g. "server1" in case of low UPS battery state. All commands as user "root".
On master server with UPS connected via USB:
- vi /etc/nut/shutdown.local
-
#!/bin/bash # For every target server add the following lines: # Pipe message to logger and stderr echo Shutting down server1, which is also using the master server UPS | tee /dev/stderr | logger ssh -p 2222 nutremote@server1.example.com sudo systemctl poweroff -i
-
- cat ~/.ssh/id_rsa.pub
-
ssh-rsa AAAAB3NzaC1yc2EAAA...
- Copy to clipboard/editor, we need this output later.
-
On server without UPS, e.g. "server1":
Server needs BIOS setting "Power on after power loss" to automatically turn on again after low battery shutdown!
- adduser nutremote
- adduser nutremote ssh-user
- optional, this group may not exist on your system
- passwd --lock nutremote
- Disable password login
- mkdir /home/nutremote/.ssh
- vi /home/nutremote/.ssh/authorized_keys
- restrict,command="sudo systemctl poweroff -i"
- Paste master server public ssh key from above (~/.ssh/id_rsa.pub)
The goal is a long single line of text separated by a space: -
restrict,command="sudo systemctl poweroff -i" ssh-rsa AAAAB3NzaC1yc2EAAA...
- chmod 600 /home/nutremote/.ssh/authorized_keys
- chown -R nutremote:nutremote /home/nutremote
- visudo
-
# Allow master server NUT UPS to power off this host nutremote ALL = NOPASSWD: /bin/systemctl poweroff -i
-
Testing the setup
On master server with UPS connected via USB:
- /etc/nut/shutdown.local
- The target server, e.g. "server1" should shut down.
Alternative Hardware
BlueWalker PowerWalker VI 600 SCL