How to add FINALDELAY to NUT upsmon.conf?

scurrier

Patron
Joined
Jan 2, 2014
Messages
297
I'd like to add the FINALDELAY parameter to the NUT config file upsmon.conf. The web GUI does not allow this. What is the best way to work around it?

Ultimately, I am trying to prevent TrueNAS, which is working as a NUT primary, from shutting down before the VM's that depend on it in a NUT secondary, Proxmox.

Thank you!
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
Isn't that what the HOSTSYNC parameter does (which is set by the Host Sync field in the UPS service)? The tooltip says:

Help: Host Sync​
Upsmon will wait up to this many seconds in master mode for the slaves to disconnect during a shutdown situation.​
 

scurrier

Patron
Joined
Jan 2, 2014
Messages
297
I wish NUT worked like that.

I have host sync set to 120 in the GUI, but TrueNAS shuts down before 120 seconds. The reason is that HOSTSYNC is only for how long it will wait for the other machine to respond as expected before deciding that something's wrong and it should continue without them.

In the case of a primary waiting for the secondary, all the primary waits for is the secondary to disconnect. Problem is, that will happen before Proxmox shuts down the VM's, which then takes a long time to finish.

In contrast, FINALDELAY is how long the machine will wait after the HOSTSYNC period.
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
I don't think the middleware has any hooks to set this. I looked through the configuration database and the middleware Python source. Just as a wild guess, could you add it directly to /usr/local/etc/nut/upsmon.conf? I don't think the middleware will molest this between reboots, only during upgrades.

It also occurs to me that you could create a post-init script under Tasks->Init/Shutdown Scripts to append your FINALDELAY line to /usr/local/etc/nut/upsmon.conf if the file has just the default number of lines for your system (mine has 14) just before the UPS service starts.
 
Last edited:

scurrier

Patron
Joined
Jan 2, 2014
Messages
297
I will look into the init script. Thanks!
 

scurrier

Patron
Joined
Jan 2, 2014
Messages
297
I think I got it working well now. I added a pre-init command grep -qF 'FINALDELAY' /usr/local/etc/nut/upsmon.conf || echo 'FINALDELAY 120' >> /usr/local/etc/nut/upsmon.conf to create a 120 s delay before shutdown.

Curiously, running this command only seemed to have an effect on NUT when it was invoked by rebooting the system. Simply running the command (like after making a GUI change that wipes out the FINALDELAY line) and then restarting the service (service nut restart) without rebooting didn't work. The delay didn't work.

Anyway, I hope that helps someone. Ultimately, I think the upsmon.conf auxillary options should be added to the web GUI.
 

scurrier

Patron
Joined
Jan 2, 2014
Messages
297
I've rebooted several times and it's working great. I haven't been messing in the web GUI.

Now I just need to figure out how to get Proxmox to not try to mount network filesystems before TrueNAS finishes its long boot process from USB drive.
 

scurrier

Patron
Joined
Jan 2, 2014
Messages
297
Quick follow-up. The solution to the proxmox problem mentioned above was to set an NFS-needing container/VM to first in the VM boot order. This VM waits for NFS indefinitely before it boots. This VM will hold back other VMs, like CIFS-needing ones, until the NAS is up. A delay can be set on the first VM that will specify how long to wait after that VM boots before booting the next one. I set it to 10 seconds in case the CIFS service needs a little time to come up after NFS is up.
 

Jatrabari

Contributor
Joined
Sep 23, 2017
Messages
100
I think I got it working well now. I added a pre-init command grep -qF 'FINALDELAY' /usr/local/etc/nut/upsmon.conf || echo 'FINALDELAY 120' >> /usr/local/etc/nut/upsmon.conf to create a 120 s delay before shutdown.

Curiously, running this command only seemed to have an effect on NUT when it was invoked by rebooting the system. Simply running the command (like after making a GUI change that wipes out the FINALDELAY line) and then restarting the service (service nut restart) without rebooting didn't work. The delay didn't work.

Anyway, I hope that helps someone. Ultimately, I think the upsmon.conf auxillary options should be added to the web GUI.

Why do you have to grep it first before echo? I am trying to solve this same problem.
 

scurrier

Patron
Joined
Jan 2, 2014
Messages
297
The grep makes sure that FINALDELAY isn't already in the file to avoid endlessly appending to the file. Grep's return value will determine whether or not the next command runs.
Why do you have to grep it first before echo? I am trying to solve this same problem.
 

Jatrabari

Contributor
Joined
Sep 23, 2017
Messages
100
Ok, tried it on my server and works great. Also files a bug report to correct the GUI problem as it should work also from there.
 

CacheMeIfYouCan

Dabbler
Joined
Oct 23, 2023
Messages
23
I think I got it working well now. I added a pre-init command grep -qF 'FINALDELAY' /usr/local/etc/nut/upsmon.conf || echo 'FINALDELAY 120' >> /usr/local/etc/nut/upsmon.conf to create a 120 s delay before shutdown.

Curiously, running this command only seemed to have an effect on NUT when it was invoked by rebooting the system. Simply running the command (like after making a GUI change that wipes out the FINALDELAY line) and then restarting the service (service nut restart) without rebooting didn't work. The delay didn't work.

Anyway, I hope that helps someone. Ultimately, I think the upsmon.conf auxillary options should be added to the web GUI.
Well done @scurrier With TrueNAS Scale 23.10 that I'm using, the pre-init command needed a little bit of tweaking. The issue is that the /etc/nut is entirely reconstructed by TrueNAS when the GUI is modified, and the upsmon.conf is unwritable. Here's what worked for me:
Code:
chmod u+w /etc/nut/upsmon.conf && grep -qF "FINALDELAY" /etc/nut/upsmon.conf || echo "FINALDELAY 180" >> /etc/nut/upsmon.conf && chmod u-w /etc/nut/upsmon.conf
 
Top