OPNsense Forum

Archive => 23.1 Legacy Series => Topic started by: RedVortex on January 26, 2023, 11:51:42 PM

Title: NUT (UPS) daemon is unable to start after upgrade
Post by: RedVortex on January 26, 2023, 11:51:42 PM
/usr/local/etc/rc.d/nut: WARNING: failed precmd routine for nut


I'm trying to figure out what is happening. I removed/reinstalled the plugin without luck so far. I'll keep you posted.
Title: Re: NUT (UPS) daemon is unable to start after upgrade
Post by: pyrodex on January 26, 2023, 11:56:37 PM
Same boat here, worked fine in 22.x series.


root@firewall:/var/db # /usr/local/etc/rc.d/nut restart
nut not running? (check /var/db/nut/upsd.pid).
Network UPS Tools - UPS driver controller 2.8.0
Network UPS Tools - Generic HID driver 0.47 (2.8.0)
USB communication driver (libusb 1.0) 0.43
Can't chdir to /var/db/nut: Permission denied
Driver failed to start (exit status=1)
/usr/local/etc/rc.d/nut: WARNING: failed precmd routine for nut
root@firewall:/var/db #



root@firewall:/var/db # ls -la nut/
total 12
drwxr-x---   2 uucp  uucp    512 Jan 26 17:53 .
drwxr-xr-x  24 root  wheel  1024 Jan 26 17:52 ..
-rw-r--r--   1 root  uucp      6 Jan 26 17:53 upsmon.pid
root@firewall:/var/db #


Also did a remove/install with no luck
Title: Re: NUT (UPS) daemon is unable to start after upgrade
Post by: RedVortex on January 27, 2023, 12:07:10 AM
Yep, exact same issue as you. I'll try to play with the permissions and see what's up.

I'll also try to remove the plugin again and this time get rid of everything as well (configs, folders, etc...)
Title: Re: NUT (UPS) daemon is unable to start after upgrade
Post by: carl76 on January 27, 2023, 12:21:05 AM
I've also done the uninstall/install and try again.  Same error as everyone else is posting.  I also went through before the reinstall and deleted everything related to nut that was left over and still getting the same error.
Title: Re: NUT (UPS) daemon is unable to start after upgrade
Post by: RedVortex on January 27, 2023, 12:24:09 AM
I removed os-nut and then I remove /var/db/nut and reinstalled os-nut.

The permissions where 740 and nut.nut after reinstall on /var/db/nut

After I tried to start nut, the permissions on the /var/db/nut were now uucp:uucp and 740

Upsmon is able to run but not ups daemon since /usr/local/sbin/upsdrvctl is unable to start with uucp:uucp on /var/db/nut

Changing to nut:nut (like right after the plugin installation is done) makes /usr/local/sbin/upsdrvctl work

Trying to see how to workaround this for now but it sound like a bug...
Title: Re: NUT (UPS) daemon is unable to start after upgrade
Post by: RedVortex on January 27, 2023, 12:44:51 AM
The right fix is likely that the owner:group of /var/db/nut remains nut:nut so that everything works. Unsure why this becomes uucp:uucp at some point.

Changing the permissions to 777 on /var/db/nut makes things work (DP is the UPS name)

root@*******:/var/log # ls -al /var/db/nut/
total 20
drwxrwxrwx   2 uucp  uucp    512 Jan 26 18:41 .
drwxr-xr-x  21 root  wheel  1536 Jan 26 18:37 ..
-rw-r--r--   1 nut   uucp      6 Jan 26 18:41 upsd.pid
-rw-r--r--   1 root  uucp      6 Jan 26 18:38 upsmon.pid
srw-rw----   1 nut   uucp      0 Jan 26 18:41 usbhid-ups-DP
-rw-r--r--   1 nut   uucp      6 Jan 26 18:41 usbhid-ups-DP.pid


This is definitely not a good fix in any way, it is very bad and insecure but it gets me going for now until the right solution is found or this is fixed.
Title: Re: NUT (UPS) daemon is unable to start after upgrade
Post by: RedVortex on January 27, 2023, 12:55:41 AM
I think this needs to become nut:nut instead of uucp:uucp

/usr/local/opnsense/scripts/OPNsense/Nut/setup.sh

root@********:/usr/local/opnsense # more scripts/OPNsense/Nut/setup.sh
#!/bin/sh
mkdir -p /var/db/nut

chown uucp:uucp /var/db/nut
Title: Re: NUT (UPS) daemon is unable to start after upgrade
Post by: pyrodex on January 27, 2023, 01:00:17 AM
Quote from: RedVortex on January 27, 2023, 12:44:51 AM
The right fix is likely that the owner:group of /var/db/nut remains nut:nut so that everything works. Unsure why this becomes uucp:uucp at some point.

Changing the permissions to 777 on /var/db/nut makes things work (DP is the UPS name)

root@*******:/var/log # ls -al /var/db/nut/
total 20
drwxrwxrwx   2 uucp  uucp    512 Jan 26 18:41 .
drwxr-xr-x  21 root  wheel  1536 Jan 26 18:37 ..
-rw-r--r--   1 nut   uucp      6 Jan 26 18:41 upsd.pid
-rw-r--r--   1 root  uucp      6 Jan 26 18:38 upsmon.pid
srw-rw----   1 nut   uucp      0 Jan 26 18:41 usbhid-ups-DP
-rw-r--r--   1 nut   uucp      6 Jan 26 18:41 usbhid-ups-DP.pid


This is definitely not a good fix in any way, it is very bad and insecure but it gets me going for now until the right solution is found or this is fixed.

Changing to 777 allowed for it to start. Least that is a work around for now.
Title: Re: NUT (UPS) daemon is unable to start after upgrade
Post by: RedVortex on January 27, 2023, 01:26:50 AM
I brought the permissions back to 750 and modified the /usr/local/opnsense/scripts/OPNsense/Nut/setup.sh file instead to have nut:nut, I prefer it this way, more secure and it works.

Now, I think we need to open a bug to update this file with nut:nut instead of uucp:uucp.
Title: Re: NUT (UPS) daemon is unable to start after upgrade
Post by: RedVortex on January 27, 2023, 01:43:22 AM
Sorry I corrected my above 2 posts to reflect the right file I'm talking about

/usr/local/opnsense/scripts/OPNsense/Nut/setup.sh

Title: Re: NUT (UPS) daemon is unable to start after upgrade
Post by: RedVortex on January 27, 2023, 02:35:21 AM
To be more precise, I'm talking about adapting this

https://github.com/opnsense/plugins/blob/master/sysutils/nut/src/opnsense/scripts/OPNsense/Nut/setup.sh

so that it fixes our current issue. Likely by changing this script so that the permissions and/or owner/groups fit what nut and upsdrvctl need it to be to work properly. In my situation, it means nut:nut instead of uucp:uucp. I'm just not sure why this changed for 23.x and was working properly in 22.x and if nut:nut is the right fix or permissions.
Title: Re: NUT (UPS) daemon is unable to start after upgrade
Post by: mimugmail on January 27, 2023, 07:38:07 AM
The port owner changed permissions, not a fault by opnsense,  I will fix it
Title: Re: NUT (UPS) daemon is unable to start after upgrade
Post by: franco on January 27, 2023, 09:10:25 AM
Does this do the job? https://github.com/opnsense/plugins/commit/16cbe99ebf

# opnsense-patch -c plugins 16cbe99ebf


Cheers,
Franco
Title: Re: NUT (UPS) daemon is unable to start after upgrade
Post by: The_Dave on January 27, 2023, 10:25:47 AM
Quote from: franco on January 27, 2023, 09:10:25 AM
Does this do the job? https://github.com/opnsense/plugins/commit/16cbe99ebf
# opnsense-patch -c plugins 16cbe99ebf

Unfortunately it doesn't change anything for me
Title: Re: NUT (UPS) daemon is unable to start after upgrade
Post by: franco on January 27, 2023, 10:46:38 AM
An error message would be helpful ;)
Title: Re: NUT (UPS) daemon is unable to start after upgrade
Post by: The_Dave on January 27, 2023, 11:11:46 AM
root@OPNsense:/var/db # /usr/local/etc/rc.d/nut restart
nut not running? (check /var/db/nut/upsd.pid).
Network UPS Tools - UPS driver controller 2.8.0
Network UPS Tools - Generic HID driver 0.47 (2.8.0)
USB communication driver (libusb 1.0) 0.43
Can't chdir to /var/db/nut: Permission denied
Driver failed to start (exit status=1)
/usr/local/etc/rc.d/nut: WARNING: failed precmd routine for nut


Exact same as above

root@OPNsense:/var/db # ls -la nut/
total 19
drwxr-x---   2 uucp  uucp    6 Jan 19 04:44 .
drwxr-xr-x  23 root  wheel  34 Jan 27 10:23 ..
-rw-r--r--   1 nut   nut     6 Jan 18 10:00 upsd.pid
-rw-r--r--   1 nut   nut     6 Jan 27 10:23 upsmon.pid
srw-rw----   1 nut   nut     0 Jan 18 10:00 usbhid-ups-ups
-rw-r--r--   1 nut   nut     6 Jan 18 10:00 usbhid-ups-ups.pid
Title: Re: NUT (UPS) daemon is unable to start after upgrade
Post by: franco on January 27, 2023, 11:22:31 AM
I don't know, nut rc.d could be botching the restart command.

# cat /usr/local/opnsense/scripts/OPNsense/Nut/setup.sh
# /usr/local/opnsense/scripts/OPNsense/Nut/setup.sh

And try again ;)

(cat to see if the content is correct)


Cheers,
Franco
Title: Re: NUT (UPS) daemon is unable to start after upgrade
Post by: The_Dave on January 27, 2023, 11:39:46 AM
Ok, strange thing. I used the cat command and realized that the script hasn't been changed to reflect the changes to nut:nut. So I applied the patch a third time and now it just works as intended. No idea why it didn't work before but it seems to be working just fine now, even after a reboot.
Title: Re: NUT (UPS) daemon is unable to start after upgrade
Post by: franco on January 27, 2023, 11:41:02 AM
Third time? Applying patch twice adds and removes it :)


Thanks,
Franco
Title: Re: NUT (UPS) daemon is unable to start after upgrade
Post by: RedVortex on January 27, 2023, 02:53:10 PM
Quote from: franco on January 27, 2023, 09:10:25 AM
Does this do the job? https://github.com/opnsense/plugins/commit/16cbe99ebf

# opnsense-patch -c plugins 16cbe99ebf

I reverted my changes (put back uucp:uucp both in the setup.sh and the folder) and I emptied the folder but kept the folder to make sure things would change for people already having it existing, not just new installs.

root@*****:/usr/local/opnsense # ls -al /var/db/nut/
total 8
drwxr-x---   2 uucp  uucp    512 Jan 27 08:45 .
drwxr-xr-x  21 root  wheel  1536 Jan 27 03:40 ..


Then applied the patch and started the services through the UI (that does trigger the file to run I believe, unlike the command line rc).

Everything started properly and the files, folders and all seem happy


root@*****:/usr/local/opnsense # ls -al /var/db/nut/
total 20
drwxr-x---   2 nut   nut     512 Jan 27 08:45 .
drwxr-xr-x  21 root  wheel  1536 Jan 27 03:40 ..
-rw-r--r--   1 nut   nut       6 Jan 27 08:45 upsd.pid
-rw-r--r--   1 root  nut       6 Jan 27 08:45 upsmon.pid
srw-rw----   1 nut   nut       0 Jan 27 08:45 usbhid-ups-DP
-rw-r--r--   1 nut   nut       6 Jan 27 08:45 usbhid-ups-DP.pid


I'm also seeing the changes in the /etc/group file

before

uucp:*:66:
dialer:*:68:
network:*:69:


after

uucp:*:66:
dialer:*:68:nut
network:*:69:


Thanks a lot for the super quick fix franco !  :)
Title: Re: NUT (UPS) daemon is unable to start after upgrade
Post by: carl76 on January 27, 2023, 04:34:50 PM
The patch worked for me as well.  Thanks Franco!
Title: Re: NUT (UPS) daemon is unable to start after upgrade
Post by: hdholm on January 29, 2023, 08:55:28 PM
Quote from: franco on January 27, 2023, 09:10:25 AM
Does this do the job? https://github.com/opnsense/plugins/commit/16cbe99ebf

# opnsense-patch -c plugins 16cbe99ebf


Cheers,
Franco

This worked to fix the problem for me.
Title: Re: NUT (UPS) daemon is unable to start after upgrade
Post by: gromit on January 29, 2023, 09:12:23 PM
Quote from: franco on January 27, 2023, 09:10:25 AM
Does this do the job? https://github.com/opnsense/plugins/commit/16cbe99ebf

# opnsense-patch -c plugins 16cbe99ebf


Cheers,
Franco

This patch fixes the problem for me and allows NUT to start up.