NUT is an open source network monitoring and control system. I use a Powershield Commander RT PSCRT1100 a 1100VA/880W, line interactive sinewave UPS. It turns out that this is a slightly modified version of the Voltronic Power Otima II 1.1K. Presumably the unit has been slightly modified for Powershield for the Australian market, mainly hardware plugs and presumably some firmware/software setup. In fact Voltronic Power, headquartered in Taiwan, even states they are a leading OEM/ODM manurfacturer of UPSs, AVRs and inverters. The software provided with the UPS is both propriety and bloated. I want a simple efficient command line / daemon based utility that can monitor performance, control as necessary and report on abnormal operation. Unfortunately the NUT project documentation is not simple to follow. I set this up quite some time ago, so this will not necessarily be up to date.
It turns out the nutdrv_qx driver is usually better suited for Voltronic Power UPSs than the Blazer_usb one. See NUT Voltronic Power UPS Protocol, it is also list under the Voltronic Power section, (various)USB of the NUT Hardware compatibility list
NUT can be installed by "sudo apt install nut". The configuration files are located at /etc/nut :
Ensure ownership and permissions are as follows: "sudo chown root:nut /etc/nut -R" and "sudo chmod 640 /etc/nut -R"
The output of "/bin/upsc KPBUPS@localhost", (or simply upsc KPBUPS):
Init SSL without certificate database battery.charge: 100 #calculated value battery.charge.low: 25 #Set value LB (Low Battery Alarm) battery.charge.restart: 30 #Set value battery.charge.warning: 60 #Set value battery.energysave: no battery.packs: 1 #Fix value battery.protection: yes battery.runtime: 1680 #calculated value battery.runtime.low: 420 #Set value battery.runtime.restart: 180 #Set value battery.voltage: 27.30 battery.voltage.high: 26.9 #Set value for calculation battery.voltage.low: 21.5 #Set value for calculation battery.voltage.nominal: 24.0 #nominal/design value device.model: LIHVX1K1 #Fix value device.type: ups #Fix value driver.name: nutdrv_qx driver.parameter.pollfreq: 30 driver.parameter.pollinterval: 2 driver.parameter.port: auto driver.version: 2.7.2 #Fix value driver.version.data: Voltronic 0.01 #Fix value driver.version.internal: 0.06 #Fix value input.current.nominal: 4.0 #nominal/design value input.frequency: 50.0 input.frequency.nominal: 50.0 #nominal/design value input.phases: 1 #nominal/design value input.voltage: 241.7 input.voltage.nominal: 230.0 #nominal/set value outlet.0.switchable: no output.current: 0.9 output.current.nominal: 4 #nominal/design value output.frequency: 50.0 output.frequency.nominal: 50.0 #nominal/design value output.phases: 1 #nominal/design value output.power.maximum.percent: 22 output.power.minimum.percent: 21 output.powerfactor: 0.8 #nominal/design value output.voltage: 241.6 output.voltage.nominal: 230.0 #nominal/set value ups.beeper.status: enabled ups.delay.shutdown: 30 ups.delay.start: 180 ups.firmware: 00303.05 #Fix value ups.firmware.aux: P00 #Fix value ups.load: 21 ups.power.nominal: 1100 #nominal/design value ups.productid: 5161 #Fix value ups.start.auto: yes ups.start.battery: yes ups.status: OL ups.temperature: 19.4 ups.type: line-interactive #nominal/design value ups.vendorid: 0665 #Fix value
I have been using NUT on my server and UPS now for about 4 years. In all that time I never got the upsmon part of it operational. This monitors the UPS and sends out messages and shutdown the server on UPS low battery.
The current NUT scripts seem to be based upon init.d (located in /etc/init.d), in particular /etc/init.d/nut-server and /etc/init.d/nut-client, (with /etc/init.d/nut-monitor being a link to /etc/init.d/nut-client). Systemd seems to have a method for legacy init.d scripts and creates scripts in /run/systemd/generator.late, in particular, ups-monitor.service.
To see running processes use: "sudo ps -e | grep nut*" and "sudo ps -e | grep ups*"
Turn off the existing legacy scripts and systemd handlers, as noted above; "sudo update-rc.d nut-client disable", "sudo update-rc.d nut-server disable" and "sudo systemctl disable ups-monitor.service"
The Kepstin blog gives a good NUT and Systemd discussion Network UPS Tools (nut) and systemd. However it is written for Fedora and there are some nuanaces required to work with Ubuntu. For a general understanding of Systemd see DigitalOcean references: Understanding Systemd Units and Unit Files, How To Use Systemctl to Manage Systemd Services and Units and Systemd Essentials: Working with Services, Units, and the Journal.
First we need to get the NUT driver running, "sudo vim /etc/systemd/system/nut-driver.service"
[Unit] Description=Network UPS Tools - power device driver controller After=network-online.target [Service] ExecStart=/sbin/upsdrvctl start ExecStop=/sbin/upsdrvctl stop Type=forking [Install] WantedBy=multi-user.target
My system takes a bit of time for the network system to fire up, so I delay the NUT driver startup until after the network is up, by adding the directive "After=network-online.target".
Unfortunately when this script is run, "sudo systemctl start nut-driver.service" it reports failure as it is unable to access the directory "/var/run/nut". So we can create the directory with: "sudo mkdir /var/run/nut sudo chown root:nut /var/run/nut sudo chmod 770 /var/run/nut". This allows nut-driver.service to run, but fails after a reboot. Further investigation shows that "/var/run" is a symlink to "/run" and the command "df -T" shows that /run is a temporary file system mounted in RAM that must be recreated every boot. Inspection of the init.d NUT files show they include creation of the /var/run/nut directory. In systemd .conf files must be created in the /usr/lib/tmpfiles.d that create these emphemeral directories, see "man tmpfiles.d". So we need to create the file: "sudo vim /usr/lib/tmpfiles.d/nut-driver.conf" and populate so:
#Type Path Mode UID GID Age Argument d /run/nut 0770 root nut - -
Next in order to ensure correct handling of emergency poweroffs and test reboots correctly, check the /lib/systemd/system-shutdown/nutshutdown file exists; "sudo vim /lib/systemd/system-shutdown/nutshutdown" and populate so:
#!/bin/sh /sbin/upsmon -K >/dev/null 2>&1 && /sbin/upsdrvctl shutdown
Next create the systemd nut server service for /sbin/upsd, configuration file, "sudo vim /etc/systemd/system/nut-server.service
[Unit] Description=Network UPS Tools - power devices information server After=nut-driver.service [Service] ExecStart=/sbin/upsd Type=forking [Install] WantedBy=multi-user.target
Next create the systemd nut monitor service, /sbin/upsmon, configuration file, "sudo vim /etc/systemd/system/nut-monitor.service
[Unit] Description=Network UPS Tools - power device monitor and shutdown controller After=nut-server.service [Service] ExecStart=/sbin/upsmon PIDFile=/run/nut/upsmon.pid Type=forking [Install] WantedBy=multi-user.target
The NUT binaries issue a SSL error to STDERR, so the addition of 2>/dev/null suppresses this.
The parameters set in ups.conf; default.battery.voltage.high and default.battery.voltage.low are used to calculate battery runtime and battery charge level and for low battery alarming. These values can be configured to account for varying battery performance, due mainly to type, age.