Network UPS Tools (NUT) as Ubuntu 22.04 LXC Container

heywhatsup1235

New Member
Jul 21, 2024
1
0
1
I wanted to setup an LXC Container to support 3 different UPS devices that control different systems. The end goal was to monitor these in Home Assistant for notifications and easy review. I ran into some issues and I'm sure there are better ways to do this but this is what I found worked. Network UPS Tools (NUT) configuration credit goes to: https://www.kreaweb.be/diy-home-server-2021-software-proxmox-ups/#a_Create_LXC_container


I created an LXC Container using the following settings:
ubuntu-22.04
Privileged - true

You need to find the Bus and Device # of the APC USB in order to passthrough to the container.

On the proxmox host, run:
lsusb​

Log the Bus # and Device #.
In my case it was "Bus 001 Device 013"

In LXC settings, go to resources and click "Add" -> "Device Passthrough" and enter the path by including the bus and device number from the host console.
Using the template: "/dev/bus/usb/{BUS#}/{Device#}" enter the bus and device from the host. In my case it was: "/dev/bus/usb/001/013"

Start the container and log in as root.

Run the following commands:
apt-get update​
apt-get upgrade​
apt install nut -y​

After the install completes, run the nut-scanner command to output the UPS info and confirm that that USB passthrough is working correctly:
nut-scanner -U​

Next, setup the configuration files. Here is the bare minimum needed for this to work:
nano /etc/nut/nut.conf​
MODE=netserver​
Using info from nut-scanner -U, highlighted in bold:

nano /etc/nut/ups.conf​
pollinterval = 15​
maxretry = 3​
[apc]​
# APC Back-UPS​
#nut-scanner: Enter the driver name​
driver = usbhid-ups
port = auto​
desc = "APC Back-UPS"​
#nut-scanner: Enter the vendorid, productid, and serial from the output​
vendorid = 051D
productid = 0002
serial = xxxxxxxxxxxx

Save the changes and run this command to check the config:
upsdrvctl start​

Mine returned the error:
Network UPS Tools - UPS driver controller 2.7.4​
Network UPS Tools - Generic HID driver 0.41 (2.7.4)​
USB communication driver 0.33​
No matching HID UPS found​
Driver failed to start (exit status=1)​

I found that adding nut to the root group resolved it. I'm sure there are more elegant ways to do this but I could not find any.
adduser nut root​

Re-running this command again showed a successful connection without error:
upsdrvctl start​
Network UPS Tools - UPS driver controller 2.7.4​
Network UPS Tools - Generic HID driver 0.41 (2.7.4)​
USB communication driver 0.33​
Using subdriver: APC HID 0.96​

Continue setting up the nut configuration.
nano /etc/nut/upsd.conf​
LISTEN 0.0.0.0 3493​
LISTEN :: 3493​

nano /etc/nut/upsd.users​
[upsadmin]​
# Administrative user​
password = ********​
actions = SET​
actions = FSD​
instcmds = ALL​
upsmon master​
[upsuser]​
# Normal user​
password = ********​
upsmon slave​

After that, reboot container.

Running this command should return battery details. Use the template {APCNAME}@{MACHINENAME} where the {APCNAME} comes from the name used in ups.config.
upsc apc@localhost

That should return details from the UPS. To add multiple, just include those in the container passthrough devices and edit the config to include the additional UPS details.

Hopefully this helps someone else but I'm no expert here and I'm open to any feedback!
 
Nice post!
Though, I had to start over once after the "Device Passthrough". It wasn't working at first. Searching around I found that in Proxmox when passing through, in the advanced section I needed to set "Access mode" to 0666. Hereafter everything went smoothly.

Now I only need to figure out how to setup the clients and that every client shuts down on a set battery level or after certain time has passed.

Thank you again for this post!
 
Thank you for the post. I followed the steps with some changes and it worked initially. But later, I found an issue I don't know how to fix. Let me start with the configuration I've done:

1. I'm using proxmox 8.4.1
2. The container is unpriviledged!
3. The device I passthrough was created using the GUI so I assigned the path /dev/bus/usb/001/006 , the GID in the container to 57 (the nut group) and access mode 0660.

Everything works, until the moment where, for an unkown reason (I believe it is a programmed backup) the device was renumbered on the host computer from /dev/bus/usb/001/006 to /dev/bus/usb/001/004. The LXC didn't start at all, so, I managed to find alternatives.

I can use udev on the host to create a symlink from /dev/bus/usb/xxx/yyy to /dev/my_ups_name using the vendorId and modelId. I also managed to passthrough the new "fixed" device name to the container, also using the desired group and permissions. The problem is that I've been unable to configure usbhid-ups to access a device under /dev/my_ups_name it always tries to read /dev/bus/usb/xxx/yyy so no way. Also, the documentation about dev[n] lines in the {containerid}.conf file Documentation is here, scroll down a bit does not allows us to rename the device on the container that would solve the problem.

I'm out of ideas so any help will be appreciated!