[HOW TO] Set up NUT netclient mode on your TNAS to monitor a UPS

Permissions, domain/LDAP, power, security, notification and more.
Locked
User avatar
justsimon
Posts: 69
Joined: 22 Sep 2020, 15:18

[HOW TO] Set up NUT netclient mode on your TNAS to monitor a UPS

Post by justsimon »

Background
After recently buying a UPS and learning about the possibilities with NUT, I quickly began going insane trying to configure the TNAS to run as either:
  1. The netserver, or;
  2. A netclient
It ended up being somewhat simple to get it going as a netclient, but this was only after learning how it works with 2 non-Terra-Master devices acting as netserver and netclient.
If you're unsure how to set up the netserver, here's the guide I followed to set it up with multiple raspberry pis. Though in my case I used a raspberry pi as the netserver, and an OPNsense router as the netclient.

This would be much easier if there was a text editor in TNAS' linux install, but alas, nano and other text editors I know of are missing. So I copy the config files to a network share and then edit them from my laptop.
It would be easier again if Terra-Master provided these options in the web GUI UPS section.

I use PuTTY for SSH, and Notepad++ to edit the config files.

DO THIS AT YOUR OWN RISK

Prerequisites
  • A device on the same network set up as a NUT netserver
  • IP address of the netserver
  • UPS name on the netserver
  • Username and password for the netclient
Steps
1. Log in as admin via SSH

2. Elevate to super user

Code: Select all

sudo su
3. Copy the required config files to a location you can access from your PC/Mac

Code: Select all

cp /etc/nut.conf /mnt/md0/<NETWORK-SHARE>/
cp /etc/upsmon.conf /mnt/md0/<NETWORK-SHARE>/
4. Rename the original config files to retain a backup

Code: Select all

mv /etc/nut.conf /etc/nut-old.conf
mv /etc/upsmon.conf /etc/upsmon-old.conf
5. Change permissions on the config files so you can edit them

Code: Select all

chmod 777 /mnt/md0/<NETWORK-SHARE>/nut.conf
chmod 777 /mnt/md0/<NETWORK-SHARE>/upsmon.conf
6. Open nut.conf and upsmon.conf in your text editor of choice

7. Update nut.conf
The second last line needs to be set to the right value (netclient). Mine was line 32, ymmv
Before:

Code: Select all

MODE=netserver
After:

Code: Select all

MODE=netclient
Save and close the file

8. Update upsmon.conf
Here you'll set the UPS name, netserver address, netclient username and password, and role of the TNAS as a slave.
Mine was line 88, ymmv
Before:

Code: Select all

MONITOR ups@localhost 1 monuser secret master
After:

Code: Select all

MONITOR <UPS-NAME>@<IP-ADDRESS-OF-NETSERVER> 1 <NETCLIENT-USERNAME> <NETCLIENT-PASSWORD> slave
eg.

Code: Select all

MONITOR myups@192.168.1.123 1 clientusername clientpassword slave
Save and close the file

9. Copy the updated config files to /etc

Code: Select all

cp /mnt/md0/<NETWORK-SHARE>/nut.conf /etc/
cp /mnt/md0/<NETWORK-SHARE>/upsmon.conf /etc/
10. Revert permissions on the config files

Code: Select all

chmod 644 /etc/nut.conf
chmod 644 /etc/upsmon.conf
11. Reboot your TNAS

Code: Select all

reboot
That's it!
When I turn off power to the UPS at the wall socket, the TNAS goes into hibernation/safe mode within a few seconds.
When I turn power back on to the UPS, the TNAS boots up within a few seconds.

Amazingly, my TNAS now reports that a UPS is connected:
ups-message.png
And weirdly, the UPS web GUI page says it's configured as a TNAS UPS server:
ups-settings.png
User avatar
justsimon
Posts: 69
Joined: 22 Sep 2020, 15:18

Re: [HOW TO] Set up NUT netclient mode on your TNAS to monitor a UPS

Post by justsimon »

Update
Doing some more testing, I've found that this doesn't properly get my TNAS to go into hibernation.
Docker is still running and accessing hard drives, including reading and writing.
I'll update again when I've worked out what additional commands are needed.
User avatar
justsimon
Posts: 69
Joined: 22 Sep 2020, 15:18

Re: [HOW TO] Set up NUT netclient mode on your TNAS to monitor a UPS

Post by justsimon »

After more testing, this seems normal behaviour for the TNAS.
I set the upsmon.conf and nut.conf files back to original and rebooted.
Connected my UPS directly to the TNAS via USB and rebooted again, UPS is detected, then I configured the safe mode.
I unplugged the UPS from the wall, then TNAS goes into safe mode, and Docker containers are still running and reachable*.

I'm satisfied with my setup from the original post.

*Docker contains running in Host are not reachable. Only containers that have their own IP addresses are reachable, and are reading/writing as normal.
Locked