Overview
Proposed Architecture
For this setup, we will be setting up our UPS master on a raspberry pi with slaves setup on a QNAP NAS and a Ubuntu Server.
Master Setup on Raspberry Pi
Connect UPS using USP cable
Installation
$ sudo apt-get install nut
Configuring the UPS/UPSD
$ vi /etc/nut/ups.conf
Add the following config
[qnapups] driver = usbhid-ups port = auto desc = "Back-UPS ES 750"
Configure upsd.conf
$ sudo vi /etc/nut/upsd.conf
Add the following config:
LISTEN 0.0.0.0 3493
Update Credentials
$ sudo vi /etc/nut/upsd.users
[admin] password = 123456 actions = SET instcmds = ALL [upsmon] password = 123456 upsmon master [deepthought] password = 123456 upsmon slave
Update Nut.Conf
$ sudo vi /etc/nut/nut.conf
Set Mode=netserver
MODE=netserver
Configuring UPS Monitor
$ vi /etc/nut/upsmon.conf
Add the following line
MONITOR qnapups@localhost 1 upsmon 123456 master FINALDELAY 300
Here we are setting FINALDELAY to a bit larger value large value in an attempt to keep the master up until the battery is depleted. We are doing this to ensure that the low power consuming equipment (router, modem, raspberry pi) can run for as long as possible.
FINALDELAY seconds
When running in master mode, upsmon waits this long after sending the NOTIFY_SHUTDOWN to warn the users. After the timer elapses, it then runs your SHUTDOWNCMD. By default this is set to 5 seconds.
If you need to let your users do something in between those events, increase this number. Remember, at this point your UPS battery is almost depleted, so don’t make this too big.
Alternatively, you can set this very low so you don’t wait around when it’s time to shut down. Some UPSes don’t give much warning for low battery and will require a value of 0 here for a safe shutdown.
Verify Hardware Config
$ sudo upsdrvctl start
Restart the Service
$ sudo service nut-server restart
Get Status
$ sudo service nut-server status ● nut-server.service - Network UPS Tools - power devices information server Loaded: loaded (/lib/systemd/system/nut-server.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2021-08-24 20:28:53 EDT; 7s ago Process: 12995 ExecStart=/sbin/upsd (code=exited, status=0/SUCCESS) Main PID: 12996 (upsd) Tasks: 1 (limit: 877) CGroup: /system.slice/nut-server.service └─12996 /lib/nut/upsd Aug 24 20:28:53 pihole systemd[1]: Starting Network UPS Tools - power devices information server... Aug 24 20:28:53 pihole upsd[12995]: fopen /var/run/nut/upsd.pid: No such file or directory Aug 24 20:28:53 pihole upsd[12995]: listening on 127.0.0.1 port 3493 Aug 24 20:28:53 pihole upsd[12995]: listening on ::1 port 3493 Aug 24 20:28:53 pihole upsd[12995]: listening on 127.0.0.1 port 3493 Aug 24 20:28:53 pihole upsd[12995]: Connected to UPS [homeups]: usbhid-ups-homeups Aug 24 20:28:53 pihole upsd[12995]: listening on ::1 port 3493 Aug 24 20:28:53 pihole upsd[12995]: Connected to UPS [homeups]: usbhid-ups-homeups Aug 24 20:28:53 pihole systemd[1]: Started Network UPS Tools - power devices information server. Aug 24 20:28:53 pihole upsd[12996]: Startup successful
Query the UPS
$ upsc qnapups@localhost $ upsc qnapups@192.168.1.52 battery.charge: 100 battery.charge.low: 10 ... ups.vendorid: 051d
Client Setup QNAP
From the QNAP UI, open the control panel and navigate to External Sevices → UPS
Select Remote UPS Slave and enter the IP address of the master.
Click apply. The UPS information should now be updated. See screenshots below.
From a shell connection on the QNAP server, you can verify connection via the following command: (not required)
$ upsc qnapups@192.168.1.52 battery.charge: 100 ... ups.vendorid: 051d
Client Setup (Ubuntu)
Installation
Install nut-client
$ sudo apt-get install nut-client
Configure
Update nut-config
$ vi /etc/nut/nut.conf
Set mode to netclient
MODE=netclient
Update upsmon.conf
$ vi /etc/nut/upsmon.conf
RUN_AS_USER root MONITOR qnapups@192.168.1.52 1 deepthought 123456 slave
On our master we created a slave user called deepthought.
- upsname = qnapups
- user = deepthought
- password = 123456
Restart Nut Client
Restart nut client:
$ systemctl restart nut-client
Get Status of Nut Client
Get Status:
$ systemctl status nut-client
● nut-monitor.service - Network UPS Tools - power device monitor and shutdown controller Loaded: loaded (/lib/systemd/system/nut-monitor.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2021-08-25 13:11:09 EDT; 2s ago Process: 376582 ExecStart=/sbin/upsmon (code=exited, status=0/SUCCESS) Main PID: 376585 (upsmon) Tasks: 2 (limit: 19043) Memory: 1.1M CGroup: /system.slice/nut-monitor.service ├─376583 /lib/nut/upsmon └─376585 /lib/nut/upsmon Aug 25 13:11:09 deepthought systemd[1]: Starting Network UPS Tools - power device monitor and shutdown controller... Aug 25 13:11:09 deepthought upsmon[376582]: fopen /run/nut/upsmon.pid: No such file or directory Aug 25 13:11:09 deepthought upsmon[376582]: Using power down flag file /etc/killpower Aug 25 13:11:09 deepthought upsmon[376582]: UPS: qnapups@192.168.1.52 (slave) (power value 1) Aug 25 13:11:09 deepthought systemd[1]: nut-monitor.service: Can't open PID file /run/nut/upsmon.pid (yet?) after start: Operati> Aug 25 13:11:09 deepthought upsmon[376583]: Startup successful Aug 25 13:11:09 deepthought systemd[1]: nut-monitor.service: Supervising process 376585 which is not our child. We'll most likel> Aug 25 13:11:09 deepthought systemd[1]: Started Network UPS Tools - power device monitor and shutdown controller.
Check connection
Check Connection:
$ upsc qnapups@192.168.1.52
References
Reference | URL |
---|---|
UPSMON Man Page | https://networkupstools.org/docs/man/upsmon.conf.html |
NUT Introduction to Network UPS Tools - Configuration Examples | http://rogerprice.org/NUT/ConfigExamples.A5.pdf |
Raspberry Pi Home Server v2: Network UPS Tools | https://melgrubb.com/2016/12/11/rphs-v2-ups/ |