Configure NUT for OPNsense and TrueNAS with the CyberPower PR750ERT2U UPS
For storage in my homelab, I use TrueNAS. Additionally, I run a couple of apps on top of it as jails. For over a year, I’ve been using an uninterruptible power supply (UPS) to protect my TrueNAS from possible data loss in case of a power failure. What I’ve been missing throughout that time are the monitoring and management tools to shut down everything gracefully when the battery of the UPS runs low. In the event of a power outage lasting longer than 30 minutes, the battery would run out of juice. Everything attached to the UPS would be powered off immediately, and data loss might occur. Luckily I live in an area where power outages rarely happen. I also have backups I could restore if my TrueNAS data gets corrupted. Still, doing this right and configuring Network UPS Tools (NUT) to orchestrate shutdowns has been on my to-do list for way too long. It’s time to tackle the issue!
As always, I’ll only mention settings deviating from the defaults.
My server rack contains the following hardware.
- OPNsense firewall and router
- TrueNAS storage and jail apps
- Mikrotik CRS328-24P-4S+RM core switch running SwOS
- CyberPower PR750ERT2U UPS
- ISP modem
Of the above, only OPNsense and TrueNAS are susceptible to data corruption in case of power loss. If a shutdown due to low battery power is required, I want to shut down TrueNAS first. After, OPNsense shuts down. To achieve this with NUT, I configure OPNsense as NUT master and TrueNAS as NUT slave. Only one master must exist. However, multiple slaves may exist.
The CyberPower PR750ERT2U has about everything I’d ever want from a UPS.
- HID-compliant USB port to connect OPNsense
- Fanless operation in utility mode. It isn’t apparent from the specifications, but the CyberPower support kindly provided me with this information
- 750VA capacity allowing me to add another server
- Pure sine wave output
- Line-interactive topology
- Energy-saving capabilities
Initially, I looked at similar used APC units on eBay. At the time, I couldn’t find any good deals on eBay meeting all of the requirements above. I then found the CyberPower unit selling new for under $400 and grabbed one. I’ve been a happy CyberPower customer ever since. To be clear, I don’t affiliate with CyberPower.
NUT on OPNsense
NUT Service Configuration
To configure the NUT service on OPNsense, we do the following.
- Install the
os-nutplugin under System → Firmware → Plugins
- Refresh the browser and enable the USB HID driver under Services → Nut → Configuration → UPS Type → USBHID-Driver
- Reboot OPNsense
- Connect the UPS to OPNsense via USB
- Set the Monitor Password and Admin Password under Services → Nut → Configuration → Nut Account Settings
- Set a Name (e.g.,
cyberpower) and Enable Nut under Services → Nut → Configuration → General Settings → General Nut Settings
We should see the data of the UPS under Services → Nut → Diagnostics.
driver.version.data: CyberPower HID 0.4
ups.test.result: No test initiated
To allow TrueNAS to communicate with the NUT server on OPNsense, we add the following port forward under Firewall → NAT → Port Forward. I assume that TrueNAS is part of the
|Destination port range
|Redirect target IP
|Redirect target port
Redirect NUT traffic to OPNsense
To see if it works, we SSH into TrueNAS and run the following to retrieve the UPS status from OPNsense.
upsc [email protected]
Set the following options under Services → UPS → Configure.
|The Name we earlier set in OPNsense, e.g.,
<IP or hostname of OPNsense>
UPS reaches low battery
|The Monitor Password we earlier set in OPNsense
Clicking Save returns us to the Services menu. We need to enable the UPS service and check Start Automatically to start the service at boot time.
We could disconnect the UPS from power and let the battery drain until the UPS reaches low battery status. At some point, it’s probably a good idea to do. But repeatedly doing that unnecessarily wears down the battery. Another way is to run the Force Shut Down command. SSH into the NUT master (OPNsense) and run the following.
upsmon -c fsd
If we configured everything correctly, TrueNAS and OPNsense shut down.