Skip to content

Conversation

@danielfdickinson
Copy link
Contributor

📦 Package Details

Maintainer: @hnyman @s-hamann @drujd @tofurky @neheb @BKPepe @systemcrash @rpavlik

No maintainer, so spamming last 2.x years worth of folks who may be interested.

Description:
Updated configuration was not being applied after config change. This
was due to the means used to do the daemon reloads.

Closes #28298 "Drivers not restarted on config change"

Enable creating PID files for the server, driver, and monitor daemon
processes. This allows to use NUT's built-in facilities for signalling
the daemon's.

For server, when reloading:

  1. Check if upsd is running
    1. If not, start it.
    2. If it is send reload signal to upsd
  2. For each driver:
    1. Check if the driver is running
      1. If it is, send reload-or-exit signal to driver
      2. If driver is not running, start it
  3. Attempt to start server (upsd and drivers) if service was stopped.

For server, when stopping:

  1. Check if upsd is running
    1. If it is send stop signal to upsd
    2. Ensure it really is stopped
  2. For each driver:
    1. Check if the driver is running
      1. If it is, send stop signal to driver
      2. If driver is still running, stop it.
  3. If the server process is active (even with not upsd or drivers),
    stop it.

For monitor, send the reload signal on config change, with fallback to
stopping and starting the daemon.

In the process added linting (ignoring false positives) and fixed whitespace inconsistency.


🧪 Run Testing Details

  • OpenWrt Version: OpenWrt SNAPSHOT r32673-9d1f6ec49d
  • OpenWrt Target/Subtarget: bcm27xx/bcm2712
  • OpenWrt Device: aspberrypi,5-model-b

Only tested with dummy-ups so far. I have a spare UPS on order which should arrive this coming week.

Needs more testing and review.


✅ Formalities

  • I have reviewed the CONTRIBUTING.md file for detailed contributing guidelines.

@BKPepe BKPepe requested a review from Copilot January 19, 2026 04:45
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@danielfdickinson danielfdickinson force-pushed the pr-nut-fix-reload-on-change branch 2 times, most recently from 1df0cf7 to a6ad063 Compare January 20, 2026 03:41
@rpavlik
Copy link

rpavlik commented Jan 20, 2026

I did get this error (backported patches to 24.10, with a fixup for basing it on my patch - my branch called nut-backport-2 ):

Tue Jan 20 09:37:50 2026 daemon.err usbhid-ups[7928]: libusb1: Could not open any HID devices: insufficient permissions on everything
Tue Jan 20 09:37:50 2026 daemon.err usbhid-ups[7928]: libusb1: except 1 devices tried but not matching the requested criteria
Tue Jan 20 09:37:50 2026 daemon.err usbhid-ups[7928]: No matching HID UPS found

But removing and re-inserting xhci_mtk_hcd appears to have made it work. It did appear to find the ups automatically once I did that, though there was an error/warning?

Tue Jan 20 09:39:27 2026 kern.info kernel: [521378.778719] hid-generic 0003:0764:0601.0002: hiddev96,hidraw0: USB HID v1.11 Device [CPS CST135UC] on usb-11200000.usb-1/input0
Tue Jan 20 09:39:27 2026 daemon.err usbhid-ups[8551]: Using subdriver: CyberPower HID 0.84
Tue Jan 20 09:39:27 2026 daemon.info usbhid-ups[8551]: Defaulting 'pollfreq' to 12 for CPS devices
Tue Jan 20 09:39:27 2026 daemon.info usbhid-ups[8551]: Listening on socket /var/run/nut/usbhid-ups-networkups
Tue Jan 20 09:39:27 2026 daemon.warn usbhid-ups[8551]: Running as foreground process, but saving a PID file anyway
Tue Jan 20 09:39:27 2026 daemon.debug usbhid-ups[8551]: upsnotify: failed to notify about state NOTIFY_STATE_READY_WITH_PID: no notification tech defined, will not spam more about it
Tue Jan 20 09:39:27 2026 daemon.err usbhid-ups[8551]: Defaulting 'pollfreq' to 12 for CPS devices
Tue Jan 20 09:39:27 2026 daemon.err usbhid-ups[8551]: Listening on socket /var/run/nut/usbhid-ups-networkups
Tue Jan 20 09:39:27 2026 daemon.err usbhid-ups[8551]: Running as foreground process, but saving a PID file anyway
Tue Jan 20 09:39:27 2026 daemon.err usbhid-ups[8551]: upsnotify: failed to notify about state NOTIFY_STATE_READY_WITH_PID: no notification tech defined, will not spam more about it

I also got this a few minutes later which looked unfamiliar:

Tue Jan 20 09:48:32 2026 daemon.debug usbhid-ups[8551]: nut_libusb_get_string: Pipe error
Tue Jan 20 09:48:32 2026 daemon.err usbhid-ups[8551]: nut_libusb_get_string: Pipe error

@danielfdickinson
Copy link
Contributor Author

But removing and re-inserting xhci_mtk_hcd appears to have made it work

To clarify, did it not work after a reboot, or did you do one of the following?

  1. Add the package and not reboot or hotplug the USB for the UPS?

    • In this case the device ownership would not be set correctly as the package was not in place for it to set the ownership on boot, and until hotplug (which also occurs on boot) there is no means to know which USB device should have its ownership updated.
  2. Add the ups definition to ups.conf after boot, with the UPS already attached?

    • This may also affect the hotplug script's ability to identify which device needs updated ownership.

@danielfdickinson
Copy link
Contributor Author

Tue Jan 20 09:39:27 2026 daemon.warn usbhid-ups[8551]: Running as foreground process, but saving a PID file anyway
Tue Jan 20 09:39:27 2026 daemon.debug usbhid-ups[8551]: upsnotify: failed to notify about state NOTIFY_STATE_READY_WITH_PID: no notification tech defined, will not spam more about it

These are both harmless. The second message is slated to be removed or made suppressable as it only systemd has a notification tech that is applicable. The first is just letting you now that process is running under a supervisor rather than as a standalone daemon.

@danielfdickinson
Copy link
Contributor Author

Tue Jan 20 09:48:32 2026 daemon.debug usbhid-ups[8551]: nut_libusb_get_string: Pipe error
Tue Jan 20 09:48:32 2026 daemon.err usbhid-ups[8551]: nut_libusb_get_string: Pipe error

This I am not sure about. Maybe a delayed reaction to unplugging and plugging back in? Does they also appear in the bootlogs if you reboot with the UPS attached?

@danielfdickinson danielfdickinson force-pushed the pr-nut-fix-reload-on-change branch from 0802764 to cf3ebaa Compare January 21, 2026 02:50
@danielfdickinson
Copy link
Contributor Author

danielfdickinson commented Jan 21, 2026

@BKPepe Any chance of another Copilot run? I tried a GitLab Duo review, but it keeps giving an error and saying "please request a new review", so I am not able to do it there.

@danielfdickinson danielfdickinson force-pushed the pr-nut-fix-reload-on-change branch from cf3ebaa to 997e24e Compare January 21, 2026 03:19
@BKPepe BKPepe requested a review from Copilot January 21, 2026 03:46
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@danielfdickinson
Copy link
Contributor Author

@BKPepe FYI I was able to get GitLab Duo to do a review by setting its prompt injection protection settings to log only instead of interrupt. Apparently something in this PR, or in the OpenWrt codebase triggers its (and maybe Copilot's as well, which is why I mention it) prompt injection protection when doing code review.

@BKPepe BKPepe requested a review from Copilot January 22, 2026 05:45
@danielfdickinson danielfdickinson force-pushed the pr-nut-fix-reload-on-change branch from a7eef34 to 99e6a9a Compare January 22, 2026 05:48
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 14 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@danielfdickinson danielfdickinson force-pushed the pr-nut-fix-reload-on-change branch from 1ed68b9 to b8cb282 Compare January 22, 2026 12:08
@danielfdickinson danielfdickinson force-pushed the pr-nut-fix-reload-on-change branch from b8cb282 to e4555ff Compare January 22, 2026 12:24
@danielfdickinson
Copy link
Contributor Author

More work is needed; I realized that when a ups driver is deconfigured, it is not being stopped.

@danielfdickinson
Copy link
Contributor Author

Ok, resolved that. All going well, once I test on real hardware, it should be ready.

@danielfdickinson danielfdickinson force-pushed the pr-nut-fix-reload-on-change branch 2 times, most recently from 9ac3a81 to eec808c Compare January 23, 2026 05:14
danielfdickinson added a commit to danielfdickinson/luci that referenced this pull request Jan 25, 2026
Some driver options were noted as '(Diplay)' even though they are
added to the `ups.conf` configuration file (this is because the drivers
use them in the messages they emit). Since not all drivers support these
options and it is quite a large job to manage the which options apply
to which of the many drivers for nut, for now we add informational
text to inform the user of the situation.

Discussed in openwrt#8200 mfr, model fields not valid on usbhid-ups driver
and openwrt/packages#28382 .

As noted in the latter's comments, more than one driver uses the
problematic options, so the solution is not as simple as hiding the
options for any driver except that one.

Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
@danielfdickinson danielfdickinson force-pushed the pr-nut-fix-reload-on-change branch from eec808c to bdec640 Compare January 28, 2026 11:51
@danielfdickinson
Copy link
Contributor Author

My test device is slated to arrive early next week, so I look forward to final testing and merging soon.

@BKPepe BKPepe requested a review from Copilot January 30, 2026 06:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@danielfdickinson
Copy link
Contributor Author

My hardware has been slow to arrive. I opened a ticket with the vendor a day or two ago, so hopefully it'll not be too much longer.

@danielfdickinson danielfdickinson marked this pull request as ready for review February 10, 2026 12:29
@danielfdickinson
Copy link
Contributor Author

As I am still waiting for hardware, taking off draft, though would prefer it be tested on real hardware before being merged.

shellcheck is a useful linter if a bit pedantic and overzealous so
add overrides to silence false positives

Also, fix issues found by the linting.

* misspelling meant initscript could skip updating configuration in
  certain circumstances
* minor: assignment of the result of execution as the time of creating
  local. This has been separated.

Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
This is a noop, but since we are here.

Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
Updated configuration was not being applied after config change. This
was due to the means used to do the daemon reloads.

Closes openwrt#28298 "Drivers not restarted on config change"

Enable creating PID files for the server, driver, and monitor daemon
processes. This allows to use NUT's built-in facilities for signalling
the daemon's.

For server, when reloading:
1. Check if upsd is running
   1. If not, start it.
   2. If it is send reload signal to upsd
2. For each driver:
   1. Check if the driver is running
      1. If it is, send reload-or-exit signal to driver
      2. If driver is not running, start it
3. Attempt to start server (upsd and drivers) if service was stopped.

For server, when stopping:
1. Check if upsd is running
   1. If it is send stop signal to upsd
   2. Ensure it really is stopped
2. For each driver:
   1. Check if the driver is running
      1. If it is, send stop signal to driver
      2. If driver is still running, stop it.
3. If the server process is active (even with not upsd or drivers),
   stop it.

For monitor, send the reload signal on config change, with fallback to
stopping and starting the daemon.

Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
Change the names of variables and functions to make it more clear what
is being acted on, configured, or otherwise touched.

NUT is complicated and making it easier to follow the plot is important.

Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
Avoid attempting to remove a procd server instance that does not exist,
as doing so results in confusing/scary messages in syslog, such as:

Command failed: ubus call service delete { "name": "nut-server", "instance": "upsd" } (Not found)

Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
In NUT some models of UPS use shutdown_delay rather than offdelay, and
yet others use usd for the same purpose. shutdown_delay and usd were
previously not available in the list of available driver options, so
add them.

Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
Ensure that when a ups is removed from the configuration that its
driver instance is stopped.

Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
This is cosmetic, but user-facing (for users building via SDK or
buildroot).

Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
@danielfdickinson danielfdickinson force-pushed the pr-nut-fix-reload-on-change branch from bdec640 to 9ae7b42 Compare February 10, 2026 12:57
Attempt to de-mystify the nut-server initscript by adding comments
and factoring out some common code that adds to complexity of the
functions of which it is part.

Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
@danielfdickinson
Copy link
Contributor Author

Expect to have hardware to work with tomorrow evening, so should be able test with this weekend at the latest.

@danielfdickinson
Copy link
Contributor Author

Looks like buildbots are hitting missing files due to rc5 builds?

@efahl
Copy link
Contributor

efahl commented Feb 12, 2026

Yeah, there's a sporadic failure to create the package index files in 25.12/snapshot right now: openwrt/openwrt#21986

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nut-server: Drivers not restarted on config change

5 participants