I have a few machines around the place on separate networks with their own UPS. This is my guide to remind me how to setup a system to correctly interface with the UPS so that when there is a power outage it will send me an email to let me know and after a little time gently shutdown the machine.
Install your favourite flavour of Ubuntu
I'm using 16.04 LTS server but any recent version should do the job
I've used a number of guides to get NUT to work to my liking. I've taken the good bits from these guides:
http://tedfelix.com/software/nut-network-ups-tools.html
http://rogerprice.org/NUT/ConfigExamples.A5.pdf
https://srackham.wordpress.com/2013/02/27/configuring-nut-for-the-eaton-3s-ups-on-ubuntu-linux/
Install NUT:
sudo apt install nut
Figure out what UPS you have:
lsusb
I got:
Bus 003 Device 002: ID 0764:0501 Cyber Power System, Inc. CP1500 AVR UPS
Edit ups.conf
sudo vi /etc/nut/ups.conf
Configure file as follows:
xretry = 5
pollinterval = 5
[serverups]
driver = usbhid-ups
port = auto
desc = "Server UPS"
Configure udev rules for usbhid-ups
sudo cp /lib/udev/rules.d/52-nut-usbups.rules /etc/udev/rules.d/
reboot machine in order to load these rules
The driver service upsdrvctl needs a /var/run/nut directory:
sudo mkdir /var/run/nut
sudo chown root:nut /var/run/nut
sudo chmod 770 /var/run/nut
Test the ups.conf file:
sudo upsdrvctl start
You should see something like:
Network UPS Tools upsd 2.6.3
listening on 127.0.0.1 port 3493
listening on ::1 port 3493
Connected to UPS [serverups]: usbhid-ups-serverups
or maybe if you are using a APS UPS:
Network UPS Tools - UPS driver controller 2.7.2
Network UPS Tools - Generic HID driver 0.38 (2.7.2)
USB communication driver 0.32
Using subdriver: APC HID 0.95
configure /etc/nut/upsd.users as follows:
[monuser]
password = yourpassword
actions = SET
instcmds = ALL
upsmon master
configure /etc/nut/upsmon.conf as follows:
MONITOR [email protected] 1 local_mon yourpassword master
MINSUPPLIES 1
SHUTDOWNCMD "/sbin/shutdown -h +0"
POLLFREQ 5
POLLFREQALERT 5
HOSTSYNC 15
DEADTIME 15
POWERDOWNFLAG /etc/killpower
#
NOTIFYMSG ONLINE "UPS %s on line power"
NOTIFYMSG ONBATT "UPS %s on battery"
NOTIFYMSG LOWBATT "UPS %s battery is low"
NOTIFYMSG FSD "UPS %s: forced shutdown in progress"
NOTIFYMSG COMMOK "Communications with UPS %s established"
NOTIFYMSG COMMBAD "Communications with UPS %s lost"
NOTIFYMSG SHUTDOWN "Auto logout and shutdown proceeding"
NOTIFYMSG REPLBATT "UPS %s battery needs to be replaced"
NOTIFYMSG NOCOMM "UPS %s is unavailable"
NOTIFYMSG NOPARENT "upsmon parent process died - shutdown impossible"
#
NOTIFYFLAG ONBATT SYSLOG+WALL
NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC
NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
NOTIFYFLAG COMMBAD SYSLOG+EXEC
NOTIFYFLAG COMMOK SYSLOG+EXEC
NOTIFYFLAG REPLBATT SYSLOG+WALL
NOTIFYFLAG FSD SYSLOG+WALL+EXEC
NOTIFYFLAG NOCOMM SYSLOG+WALL
NOTIFYFLAG NOPARENT SYSLOG+WALL
#
RBWARNTIME 43200
NOCOMMWARNTIME 300
FINALDELAY 5
#
NOTIFYCMD /usr/local/bin/nut-notify.sh NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC
configure /etc/nut/nut.conf to set the mode:
MODE=standalone
*Assuming you have postfix configured (see my postfix and smartmontools post for some clues )
create a nut-notify script to allow you to be emailed of a power failure:
sudo vim /usr/local/bin/nut-notify.sh
insert something like this:
#!/bin/sh
echo "[email protected]" | mail -s "NUT Notice" [email protected]
Then, make the script executable:
sudo chmod +x /usr/local/bin/nut-notify.sh