This guide explains how to install NUT on a client / server architecture with several clients accessing the UPS.
sudo apt-get install nut
lsusb output: Bus 001 Device 002: ID 051d:0003 American Power Conversion UPS
sudo vim /etc/udev/rules.d/90-nut-ups.rules ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="051d", ATTR{idProduct}=="0003", MODE="0660", GROUP="nut"
udevadm control --reload-rules udevadm trigger
[ups] driver = usbhid-ups port = auto pollonly desc = "ups"
The label in the square brackets can be anything. It identifies the UPS to upsd and upsmon. Find your UPS model on the NUT hardware compatibility list and substitute the corresponding driver for usbhid-ups above. If your UPS isn’t listed, find similar ones. They probably use the same driver. If you have a USB-based UPS, you can leave the port as auto; it’s ignored.
Note: if you are connecting a Synology NAS to your NUT setup, then the label in square brackets must be named ups.
Make sure that nut properly detects the UPS:
# upsdrvctl start
You should see something like the following:
Network UPS Tools - UPS driver controller 2.2.2 Network UPS Tools: 0.29 USB communication driver - core 0.33 (2.2.2) Using subdriver: APC HID 0.92
Now, we need to configure upsd and upsmon. upsd communicates with the UPS driver that we just started. upsmon communicates with upsd and actually shuts down the machine in the event of a power failure. Multiple instances of upsmon can be started on different machines. They can all share the same physical UPS. Create the file /etc/nut/upsd.conf as follows:
LISTEN 127.0.0.1 [<port>] # default, default port is 3493 LISTEN 192.168.x.x [<port>] # server IP address to access from other machines
On machines where the network interface comes up after nut started, you can use (the less secure)
LISTEN 0.0.0.0
Don't forget to open the port in a zone rule, if you access upsd from another machine through a firewall.
[local_mon] password = <pwd> allowfrom = localhost # optional upsmon master
You should add multiple users if you are monitoring from multiple machines. See the man page for upsd.users for more information. Now we need to configure upsmon.
Note: if you are connecting a Synology NAS to your NUT setup, then you must add the Synology NAS user like so:
[monuser] password = secret upsmon slave
MONITOR apc@localhost 1 local_mon <pwd> master POWERDOWNFLAG /etc/killpower SHUTDOWNCMD "/sbin/shutdown -h +1"
Replace apc with the name you have your UPS in /etc/nut/ups.conf and <pwd> with the password you set in /etc/nut/upsd.users. Since these files contain sensitive data, we should fix the permissions:
# chown root:nut /etc/nut/* # chmod 640 /etc/nut/*
Make sure the shutdown command for the host contains a delay, if you run VMs on this host.
MODE=netserver
Finally, edit /etc/default/nut so that upsd and upsmon will start at system boot:
# vim /etc/default/nut START_UPSD=yes START_UPSMON=yes
Start NUT:
# /etc/init.d/nut-server start
Check the end of /var/log/daemon.log to make sure everything started up. Also, you can run the following command which should print out some statistics:
$ upsc apc
Replace apc with whatever you named your UPS.
If you rely on the UPS to shutdown your systems in case of mains failure and to restart them when the power returns, you must test this. You can do so by running
upsmon -c fsd
With the mains present, this should bring your systems down and then cycle the power to restart them again. If you do the same without mains present, it should do the same, but in this case, the outputs shall remain off until mains power is applied again.
If you get a “data stale” error message check that UPS is connected and visible through the USB connection:
lsusb Bus 005 Device 003: ID 051d:0003 American Power Conversion UPS
# apt-get install nut
Installing the nut package, should add the nut user and group. If it doesn’t, you have to add those manually. Next, create or edit the necessary configuration files, which are located in /etc/nut.
MONITOR apc@<server> 1 remote_mon <pwd> slave POWERDOWNFLAG /etc/killpower SHUTDOWNCMD "/sbin/shutdown -h +0"
Replace apc with the name you have your UPS in /etc/nut/ups.conf, <server> with the server name or IP address upsd is running on, and <pwd> with the password you set in /etc/nut/upsd.users, on the server.
MODE=netclient
Finally, edit /etc/default/nut so that upsmon will start at system boot:
# vim /etc/default/nut START_UPSMON=yes
Start NUT:
# /etc/init.d/nut-client start
Check the end of /var/log/daemon.log to make sure everything started up. Also, you can run the following command which should print out some statistics:
$ upsc apc@<server>
Replace apc with whatever you named your UPS, and <server> with the server name or IP address upsd is running on.
# apt-get install nut nut-cgi
Install the Client as described above in NUT Client.
Alias /nut /usr/share/nut/www
Make sure you have named your ups as described in section ups.conf, and added the Synology NAS user to upsd.users.
Login to DSM and navigate to Control Panel –> Hardware & Power –> UPS. Enable UPS support and enter the Network UPS server IP.
You can then click [Device Information] to verify the UPS is connected. Should Synology ever change the defaults, log into your Diskstation via SSH and check the configuration files at /usr/syno/etc/ups.
The Synology DSM and NAS hardware cannot start automatically when power is restored. That's why the default beviour is for the NAS to go into safe mode, which means it switches off disk access and other services to protect the NAS from taking damage if the power goes out. When the battery is fully drained and the power goes out, the NAS will completely switch off, from which it can recover when the power comes back on.
One other way would be to completely shut down the NAS, and then reboot it once the power comes back. Note that once the power has been disconnected form the NAS, then wake-on-lan would not work anymore. For a complete shut down and recovery, you would need to power the shut down NAS independently, so the NICs never loose complete power. This could be done with a secondary battery which powers only the NAS and which maintains enough battery power to supply a shut down NAS for hours or days… not an easy setup.
If you want to completely switch off the NAS, shut it down from the machine where the UPS is connected to (e.g. the “server”) via SSH, and restart it with a wake-on-lan command.
wakeonlan <mac>
ssh root@<nas> "shutdown -h +0" /sbin/shutdow -h +0
You also must configure the UPS hardware correctly for all of this to work. For an APC Smart-UPS 2200VA, for example, you would need to set the following in advanced settings to make sure it cooperates with your NUT setup:
In an unstable power environment, I would recommend the following additional measures:
You might need to increase the battery.charge.low value in the NUT settings to allow enough battery power to shut down all hosts.
[admin] password = supersecretpassword actions = set instcmds = all
$ upsc <ups>
upsrw -s battery.charge.low=30 -u admin -p supersecretpassword <ups>