Workaround for UPS false "replace battery" alert

Original topic is here: [Closed] Update NUT to the latest version

I’ve come up with a workaround for users that have a UPS affected by the old version of NUT that is used by TrueNAS which throws false alerts of a battery failure (“replace battery”). My workaround doesn’t require anything except to run a custom Docker app via YAML and to set the TrueNAS UPS service to “slave” mode to connect to the new (and updated) NUT “master” running in the container..

Best thing about this is:

  • doesn’t require disabling safety checks
  • persists across updates
  • easily reversible

The code along with instructions are at my repo here:

I hope someone finds this useful!

Admins: hope this doesn’t violate any rules as my implementation works completely within the confines of TrueNAS’s functionality without '“breaking” anything.

Tagging because the following expressed interest in the other thread:

@mikl @squirrel627 @S_R @Drew @shoulders @CursorBeat @Lance_Longreen @SmallBarky @Fleshmauler

edit: It’s been pointed out that if you require the UPS be powered off after the battery is low that this workaround will NOT work for you.

2 Likes

Additional tags:

@winnielinnie @munarkyu @buto13 @yorick @Lekynus @rs443

But if you turn off the system, the docker will be closed.

Yes, correct. I noted this in my Github repo. “On server restarts, you will receive a UPS communications lost error because the Docker container hasn’t started yet. Once it starts up, the error will be cleared.”

I feel it’s a small one time annoyance compared to constant false alarms or having to overwrite system files by hand every time there is an update. I rarely restart unless needed

I also built a docker container before, but it will be shut down when it is shut down. Ups can’t receive the signal to turn off ups. Now I use docker and the system kernel to build the UPS driver and specify the directory to start running through a script.

I’m confused. I don’t understand the issue. Maybe it is because of the translation.

Docker already solves part of the problem, but I’m talking about a deeper issue: when the system shuts down, the Docker containers are also terminated. At that point, because the container is already closed, it can no longer send the signal to the UPS to power it off.

1 Like

Ah, I understand now! Powering down the UPS isn’t something I do personally, so I didn’t consider this.

Let me think about if there is a way to resolve that. Thanks for pointing it out!

@invar I am just learning setting up docker etc.. but can I just say thanks for this workaround. I have an APC SMT1500IC which is not fully supported in the current TrueNAS version of NUT.

just some questions not in your instructions, or I cannot read :laughing:

  • I think you should mention how to get the driver name of the UPS being used in TrueNAS before making any changes. i.e. go to the ups section or add a link to the drivers section

  • Does your docker support updating. If a new version of NUT comes out I can just update the docker.

  • Do you you configure your UPS model in the docker yaml file only? I have never used slave mode.

And what docker image are you using?

Hi, to answer your questions:

The driver name is actually there in your screenshot. (usbhid-ups). A lot of devices are supported through that driver, even ones not from APC.

The image can be updated if you modify the YAML’s ARG nut_version variable, which is currently set to v2.8.5. It needs to match a release from the actual NUT repo.

Yes, once you put it the TrueNAS UPS service into slave mode, parts of the dialog disappear so you shouldn’t even be able to change the UPS model setting anymore.

1 Like

Alpine:3.23 with a bunch of packages installed by hand and NUT cloned via git and built from scratch.

that why I posted the picture :smiley: and I thought the links would be a useful quick reference for your instructions.

1 Like

UPDATE:

I am removing the docker-compose.yml that I made and am replacing it with a bash script that will:

-build the latest NUT drivers

-copy the new usbhid-ups driver into a specified directory

-automatically update the ups.conf to allow loading of the alternate driver

Changes are easily and completely reversible, and only one file (usbhid-ups) needs to be retained from the build. In fact, a restart reverts all the changes and that’s why a POSTINIT command (taken care of by the script) is necessary.

This retains full functionality, including power down.

3 Likes

Yes, you get the alert regarding the UPS not available, right after boot, when the proper way would be to wait a little for the network to be ready, etc!

This happens too when I put my TN secondary servers to sleep. You get that annoying alert regarding UPS not available, plus another alert for NTP servers not reachable!

Can IX not handle these common scenarios BETTER?

(Start those network dependant services AFTER the network is up!?).

Thank you for that script.

Good shell programming.

1 Like

The issue with receiving the alerts is a bit tricky. There are a ton of timing settings that can be tweaked but may have undesirable effects. (Failure to notify for short power-outage events, etc.)

All the options are documented here:

Of interest: POLLFREQ, DEADTIME, NOCOMMWARNTIME

But those settings would have to be manually placed into /etc/nut/upsmon.conf with a POSTINIT command, and a manual restart of /lib/nut/upsmon

Have made numerous updates to my script. If anyone has feedback, it is welcomed here or as a new issue opened in the github repo, thanks!

1 Like