Skip to content

Implement an INSTCMD driver.exit as alternative to PID files and signals#2393

Merged
jimklimov merged 10 commits intonetworkupstools:masterfrom
jimklimov:issue-2392
Apr 16, 2024
Merged

Implement an INSTCMD driver.exit as alternative to PID files and signals#2393
jimklimov merged 10 commits intonetworkupstools:masterfrom
jimklimov:issue-2392

Conversation

@jimklimov
Copy link
Member

When a NUT driver starts, by default it checks the PID file (if present) to kill off its earlier running instance, if any, to have the device connection available and no logical conflicts at run-time.

Problems can arise when the PID file is not available (e.g. not saved due to service unit set-up). Technically we have a fallback capability of checking for the old driver instance via Unix socket made for driver-server communications, and since #1903 and numerous later issues and PRs we can have driver instances (and upsdrvctl) interact over this channel.

This PR adds a new Unix socket protocol command, driver.exit which can be used similar to SIGTERM and so cleanly exit the NUT driver program (with the goal of a new instance being able to start). Note that if the deceased instance was managed by systemd, it would be restarted after a short throttling timeout.

At this time of initial posting, this was implemented and tested as a driver -a upscfg -c exit sort of CLI operation, and tested with usbhid-ups and with upsdrvctl vs. a driver running as a systemd unit.

Next step would be to add a similar call to where we check for PID files and ensure "clean-up" before starting the NUT driver for monitoring (as opposed to killpower, instant commands and other side activities).

Closes: #2392

@jimklimov jimklimov added enhancement service/daemon start/stop General subject for starting and stopping NUT daemons (drivers, server, monitor); also BG/FG/Debug NUT protocols labels Apr 12, 2024
@jimklimov jimklimov added this to the 2.8.3 milestone Apr 12, 2024
@jimklimov jimklimov requested review from aquette and clepple April 12, 2024 12:04
@jimklimov
Copy link
Member Author

  • driver -c exit :
:; make -j 20 && ./drivers/usbhid-ups -a eco650 -DDDDDD -c exit
...
   0.000234     [D1] Will send request for command 'exit' (internal code -15) to already-running driver usbhid-ups-eco650 (if any) and exit
...
   0.000592     [D1] Succeeded to become_user(nut): now UID=77 GID=77
   0.000601     [D1] Signalling UPS [eco650]: driver.exit
   0.000618     [D5] upsdrvquery_write: write to driver socket: NOBROADCAST

   0.000621     [D5] upsdrvquery_write: write to driver socket: PING

   0.000624     [D5] upsdrvquery_prepare: waiting for a while to flush server messages
   0.098642     [D5] upsdrvquery_read_timeout: received 5 bytes from driver socket: PONG

   0.098653     [D5] upsdrvquery_prepare: got expected PONG
   0.098658     [D5] upsdrvquery_prepare: ready for tracked commands
   0.098669     [D5] upsdrvquery_write: write to driver socket: INSTCMD driver.exit TRACKING 2DDC5036-F665-4D29-BE4C-0374D091D263

   0.098682     [D5] upsdrvquery_request: will wait up to 15.000000 sec for response to INSTCMD driver.exit

   0.098859     [D5] upsdrvquery_read_timeout: received 48 bytes from driver socket: TRACKING 2DDC5036-F665-4D29-BE4C-0374D091D263 0

   0.098871     [D5] upsdrvquery_request: parsed out command status: 0
   0.098883     Request for driver to exit returned code 0
   0.098893     [D5] send_to_all: SETINFO driver.state "cleanup.exit"
  • systemd unit:
Apr 12 14:05:07 pve nut-driver@eco650[1602120]: sock_connect: enabling asynchronous mode (auto)
Apr 12 14:05:07 pve nut-driver@eco650[1602120]: Signal -2: exiting
Apr 12 14:05:07 pve usbhid-ups[1602120]: sock_connect: enabling asynchronous mode (auto)
Apr 12 14:05:07 pve usbhid-ups[1602120]: Signal -2: exiting
Apr 12 14:05:07 pve systemd[1]: [email protected]: Succeeded.

Apr 12 14:05:22 pve systemd[1]: [email protected]: Scheduled restart job, restart counter is at 3.
Apr 12 14:05:22 pve systemd[1]: Stopped Network UPS Tools - device driver for NUT device 'eco650'.
Apr 12 14:05:22 pve systemd[1]: Starting Network UPS Tools - device driver for NUT device 'eco650'...
Apr 12 14:05:22 pve nut-driver@eco650[1681936]: Network UPS Tools - UPS driver controller 2.8.2-50-g233a9bd3c
Apr 12 14:05:22 pve nut-driver@eco650[1681936]: Network UPS Tools - Generic HID driver 0.53 (2.8.2-50-g233a9bd3c)
Apr 12 14:05:22 pve nut-driver@eco650[1681936]: USB communication driver (libusb 1.0) 0.47
Apr 12 14:05:26 pve nut-driver@eco650[1681936]: Using subdriver: MGE HID 1.46
Apr 12 14:05:28 pve nut-driver@eco650[1681936]: Running as foreground process, but saving a PID file anyway
Apr 12 14:05:28 pve usbhid-ups[1681936]: Running as foreground process, but saving a PID file anyway
Apr 12 14:05:28 pve systemd[1]: Started Network UPS Tools - device driver for NUT device 'eco650'.
Apr 12 14:05:28 pve nut-driver@eco650[1681936]: upsnotify: logged the systemd watchdog situation once, will not spam more about it
Apr 12 14:05:28 pve usbhid-ups[1681936]: upsnotify: logged the systemd watchdog situation once, will not spam more about it
Apr 12 14:05:29 pve nut-driver@eco650[1681936]: sock_connect: enabling asynchronous mode (auto)
Apr 12 14:05:29 pve usbhid-ups[1681936]: sock_connect: enabling asynchronous mode (auto)

(note that signals and exit-flags have different numbering, so while SIGCMD_EXIT is -SIGTERM (-15) on POSIX builds, the ultimately raised exit code is -2 to cause a clean EXIT_SUCCESS)

  • Similarly for upsdrvctl:
:; make -j 20 && ./drivers/upsdrvctl -DDDDDD -c exit eco650
Network UPS Tools - UPS driver controller 2.8.2-37-g942863741
   0.000000     [D1] Will send request for command 'exit' (internal code -15) to already-running driver (if any) and exit
...
   0.000059     [D1] upsdrvctl commanding one driver (eco650): exit
   0.000062     [D1] Signalling UPS [eco650]: driver.exit
   0.000087     [D5] upsdrvquery_write: write to driver socket: NOBROADCAST

   0.000095     [D5] upsdrvquery_write: write to driver socket: PING

   0.000103     [D5] upsdrvquery_prepare: waiting for a while to flush server messages
   0.000136     [D5] upsdrvquery_read_timeout: received 5 bytes from driver socket: PONG

   0.000139     [D5] upsdrvquery_prepare: got expected PONG
   0.000141     [D5] upsdrvquery_prepare: ready for tracked commands
   0.000145     [D5] upsdrvquery_write: write to driver socket: INSTCMD driver.exit TRACKING 2DDC5036-F665-4D29-BE4C-0374D091D263

   0.000150     [D5] upsdrvquery_request: will wait up to 15.000000 sec for response to INSTCMD driver.exit

   0.000162     [D5] upsdrvquery_read_timeout: received 48 bytes from driver socket: TRACKING 2DDC5036-F665-4D29-BE4C-0374D091D263 0

   0.000166     [D5] upsdrvquery_request: parsed out command status: 0
   0.000172     Request for driver to exit returned code 0
   0.000175     [D1] upsdrvctl: successfully finished
   0.000177     [D1] Completed the job of upsdrvctl tool, cleaning up and exiting now
   0.000179     [D1] Completed the job of upsdrvctl tool, clean-up finished, exiting now
  • systemd unit:
Apr 12 14:09:57 pve nut-driver@eco650[1742175]: sock_connect: enabling asynchronous mode (auto)
Apr 12 14:09:57 pve nut-driver@eco650[1742175]: Signal -2: exiting
Apr 12 14:09:57 pve usbhid-ups[1742175]: sock_connect: enabling asynchronous mode (auto)
Apr 12 14:09:57 pve usbhid-ups[1742175]: Signal -2: exiting
Apr 12 14:09:57 pve systemd[1]: [email protected]: Succeeded.
Apr 12 14:10:12 pve systemd[1]: [email protected]: Scheduled restart job, restart counter is at 5.
Apr 12 14:10:12 pve systemd[1]: Stopped Network UPS Tools - device driver for NUT device 'eco650'.
Apr 12 14:10:12 pve systemd[1]: Starting Network UPS Tools - device driver for NUT device 'eco650'...
Apr 12 14:10:12 pve nut-driver@eco650[1756121]: Network UPS Tools - UPS driver controller 2.8.2-50-g233a9bd3c
Apr 12 14:10:12 pve nut-driver@eco650[1756121]: Network UPS Tools - Generic HID driver 0.53 (2.8.2-50-g233a9bd3c)
Apr 12 14:10:12 pve nut-driver@eco650[1756121]: USB communication driver (libusb 1.0) 0.47
Apr 12 14:10:16 pve nut-driver@eco650[1756121]: Using subdriver: MGE HID 1.46
Apr 12 14:10:18 pve nut-driver@eco650[1756121]: Running as foreground process, but saving a PID file anyway
Apr 12 14:10:18 pve usbhid-ups[1756121]: Running as foreground process, but saving a PID file anyway
Apr 12 14:10:18 pve systemd[1]: Started Network UPS Tools - device driver for NUT device 'eco650'.
Apr 12 14:10:18 pve nut-driver@eco650[1756121]: upsnotify: logged the systemd watchdog situation once, will not spam more about it
Apr 12 14:10:18 pve usbhid-ups[1756121]: upsnotify: logged the systemd watchdog situation once, will not spam more about it
Apr 12 14:10:19 pve nut-driver@eco650[1756121]: sock_connect: enabling asynchronous mode (auto)
Apr 12 14:10:19 pve usbhid-ups[1756121]: sock_connect: enabling asynchronous mode (auto)

@jimklimov
Copy link
Member Author

jimklimov commented Apr 12, 2024

If the command is sent when a driver is not running, it does not take long:

....
   0.000278     [D1] Will send request for command 'exit' (internal code -15) to already-running driver usbhid-ups-eco650 (if any) and exit
   0.000281     [D1] Network UPS Tools version 2.8.2-37-g942863741 (release/snapshot of 2.8.2.1) built with gcc (Debian 10.2.1-6) 10.2.1 20210110 and configured with flags: --with-user=nut --with-group=nut --with-all --with-docs=man --sysconfdir=/etc/nut --enable-silent-rules
   0.000285     [D1] debug level is '6'
   0.000288     [D5] send_to_all: SETINFO driver.debug "6"
   0.000290     [D5] send_to_all: SETFLAGS driver.debug RW NUMBER
   0.000714     [D1] Succeeded to become_user(nut): now UID=77 GID=77
   0.000725     [D1] Signalling UPS [eco650]: driver.exit
   0.000731     Can't open /var/state/ups/usbhid-ups-eco650: No such file or directory
   0.000733     Socket dialog with the other driver instance: No such file or directory
   0.000736     [D5] send_to_all: SETINFO driver.state "cleanup.exit"

NOTE: Similarly to PR #2384 we do not want "scary noise" when we preemptively try to stop a sibling and can't because none is running - goal achieved, nothing to complain about.

@AppVeyorBot

This comment was marked as resolved.

@AppVeyorBot
Copy link

@jimklimov
Copy link
Member Author

Screenshots from a build of this PR merged with #2384 for quieter logs (anyhow they will soon be together in master branch):

  • systemd journal of a driver restart:
:; systemctl restart nut-driver@eco650
Apr 13 18:15:21 pve systemd[1]: Stopping Network UPS Tools - device driver for NUT device 'eco650'...
Apr 13 18:15:21 pve nut-driver@eco650[974784]: Network UPS Tools - UPS driver controller 2.8.2-57-g2eee28ce9
Apr 13 18:15:21 pve nut-driver@eco650[928515]: Signal 15: exiting
Apr 13 18:15:21 pve usbhid-ups[928515]: Signal 15: exiting
Apr 13 18:15:22 pve systemd[1]: [email protected]: Succeeded.
Apr 13 18:15:22 pve systemd[1]: Stopped Network UPS Tools - device driver for NUT device 'eco650'.

Apr 13 18:15:22 pve systemd[1]: Starting Network UPS Tools - device driver for NUT device 'eco650'...
Apr 13 18:15:22 pve nut-driver@eco650[975293]: Network UPS Tools - UPS driver controller 2.8.2-57-g2eee28ce9
Apr 13 18:15:22 pve nut-driver@eco650[975293]: Network UPS Tools - Generic HID driver 0.53 (2.8.2-57-g2eee28ce9)
Apr 13 18:15:22 pve nut-driver@eco650[975293]: USB communication driver (libusb 1.0) 0.47
Apr 13 18:15:26 pve nut-driver@eco650[975293]: Using subdriver: MGE HID 1.46
Apr 13 18:15:28 pve nut-driver@eco650[975293]: Running as foreground process, but saving a PID file anyway
Apr 13 18:15:28 pve usbhid-ups[975293]: Running as foreground process, but saving a PID file anyway
Apr 13 18:15:28 pve systemd[1]: Started Network UPS Tools - device driver for NUT device 'eco650'.
Apr 13 18:15:28 pve nut-driver@eco650[975293]: upsnotify: logged the systemd watchdog situation once, will not spam more about it
Apr 13 18:15:28 pve usbhid-ups[975293]: upsnotify: logged the systemd watchdog situation once, will not spam more about it
Apr 13 18:15:29 pve nut-driver@eco650[975293]: sock_connect: enabling asynchronous mode (auto)
Apr 13 18:15:29 pve usbhid-ups[975293]: sock_connect: enabling asynchronous mode (auto)
  • restart (no debug) from command line: new instance asks the systemd unit wrapped old instance to stop... and then systemd restarts it back after a few seconds, asking the command-line driver to stop; journal entries are prefixed with timestamps (otherwise ordered as posted to the same terminal session); note the CLI copy of the driver detached so does not print end-of-life logs:
:; make -ks -j 20 >/dev/null 2>&1 && ./drivers/usbhid-ups  -a eco650
Network UPS Tools - Generic HID driver 0.53 (2.8.2-57-g2eee28ce9)
USB communication driver (libusb 1.0) 0.47
Duplicate driver instance detected (local Unix socket exists)! Asking other driver to self-terminate!
Apr 13 18:19:45 pve nut-driver@eco650[975293]: sock_connect: enabling asynchronous mode (auto)
Apr 13 18:19:45 pve nut-driver@eco650[975293]: Signal -2: exiting
Apr 13 18:19:45 pve usbhid-ups[975293]: sock_connect: enabling asynchronous mode (auto)
Apr 13 18:19:45 pve usbhid-ups[975293]: Signal -2: exiting
Apr 13 18:19:45 pve systemd[1]: [email protected]: Succeeded.
Using subdriver: MGE HID 1.46

Apr 13 18:20:00 pve systemd[1]: [email protected]: Scheduled restart job, restart counter is at 1.
Apr 13 18:20:00 pve systemd[1]: Stopped Network UPS Tools - device driver for NUT device 'eco650'.
Apr 13 18:20:00 pve systemd[1]: Starting Network UPS Tools - device driver for NUT device 'eco650'...
Apr 13 18:20:00 pve nut-driver@eco650[992755]: Network UPS Tools - UPS driver controller 2.8.2-57-g2eee28ce9
Apr 13 18:20:00 pve nut-driver@eco650[992755]: Network UPS Tools - Generic HID driver 0.53 (2.8.2-57-g2eee28ce9)
Apr 13 18:20:00 pve nut-driver@eco650[992755]: USB communication driver (libusb 1.0) 0.47
Apr 13 18:20:01 pve nut-driver@eco650[992755]: Duplicate driver instance detected (local Unix socket exists)! Asking other driver to self-terminate!
Apr 13 18:20:10 pve nut-driver@eco650[992755]: Using subdriver: MGE HID 1.46
Apr 13 18:20:12 pve nut-driver@eco650[992755]: Running as foreground process, but saving a PID file anyway
Apr 13 18:20:12 pve usbhid-ups[992755]: Running as foreground process, but saving a PID file anyway
Apr 13 18:20:12 pve systemd[1]: Started Network UPS Tools - device driver for NUT device 'eco650'.
Apr 13 18:20:12 pve nut-driver@eco650[992755]: upsnotify: logged the systemd watchdog situation once, will not spam more about it
Apr 13 18:20:12 pve usbhid-ups[992755]: upsnotify: logged the systemd watchdog situation once, will not spam more about it
Apr 13 18:20:13 pve nut-driver@eco650[992755]: sock_connect: enabling asynchronous mode (auto)
Apr 13 18:20:13 pve usbhid-ups[992755]: sock_connect: enabling asynchronous mode (auto)
  • restart (with debug for the CLI instance of the driver, truncated for logs of actual driver work):
:;  make -ks -j 20 >/dev/null 2>&1 && ./drivers/usbhid-ups -DDDDDD -a eco650
   0.000000     [D5] send_to_all: SETINFO driver.state "init.starting"
Network UPS Tools - Generic HID driver 0.53 (2.8.2-57-g2eee28ce9)
USB communication driver (libusb 1.0) 0.47
   0.000039     [D1] upsdrv_makevartable...
   0.000053     [D5] send_to_all: SETINFO driver.version.usb "libusb-1.0.24 (API: 0x1000108)"
   0.000057     [D1] Using USB implementation: libusb-1.0.24 (API: 0x1000108)
   0.000083     [D5] do_upsconf_args: confupsname=(null), var=debug_min, val=0
   0.000086     [D5] do_upsconf_args: call do_global_args()
...
   0.000275     [D3] main_arg: var='debug_min' val='0'
   0.000281     [D1] Network UPS Tools version 2.8.2-57-g2eee28ce9 (release/snapshot of 2.8.2.1) built with gcc (Debian 10.2.1-6) 10.2.1 20210110 and configured with flags: --with-user=nut --with-group=nut --with-all --with-docs=man --sysconfdir=/etc/nut --enable-silent-rules --enable-Werror
   0.000285     [D1] debug level is '6'
   0.000288     [D5] send_to_all: SETINFO driver.debug "6"
   0.000290     [D5] send_to_all: SETFLAGS driver.debug RW NUMBER
   0.000748     [D1] Succeeded to become_user(nut): now UID=77 GID=77
   0.000760     [D1] Signalling UPS [eco650]: driver.exit (quietly, no fuss if no driver is running or responding)
   0.000774     [D5] upsdrvquery_write: write to driver socket: NOBROADCAST

   0.000778     [D5] upsdrvquery_write: write to driver socket: PING

   0.000780     [D5] upsdrvquery_prepare: waiting for a while to flush server messages
   0.000849     [D5] upsdrvquery_read_timeout: received 5 bytes from driver socket: PONG

   0.000851     [D5] upsdrvquery_prepare: got expected PONG
   0.000853     [D5] upsdrvquery_prepare: ready for tracked commands
   0.000857     [D5] upsdrvquery_write: write to driver socket: INSTCMD driver.exit TRACKING 2DDC5036-F665-4D29-BE4C-0374D091D263

   0.000861     [D5] upsdrvquery_request: will wait up to 15.000000 sec for response to INSTCMD driver.exit

   0.000882     [D5] upsdrvquery_read_timeout: received 48 bytes from driver socket: TRACKING 2DDC5036-F665-4D29-BE4C-0374D091D263 0

   0.000886     [D5] upsdrvquery_request: parsed out command status: 0
   0.000890     [D1] Request for other driver to exit returned code 0
   0.000891     Duplicate driver instance detected (local Unix socket exists)! Asking other driver to self-terminate!
Apr 13 18:23:20 pve nut-driver@eco650[992755]: sock_connect: enabling asynchronous mode (auto)
Apr 13 18:23:20 pve nut-driver@eco650[992755]: Signal -2: exiting
Apr 13 18:23:20 pve usbhid-ups[992755]: sock_connect: enabling asynchronous mode (auto)
Apr 13 18:23:20 pve usbhid-ups[992755]: Signal -2: exiting
Apr 13 18:23:20 pve systemd[1]: [email protected]: Succeeded.

### NOTE: Here we do retry PID-based checks for competing other drivers as we did before
### The message appears because we have debug log enabled (see #2384) :

   5.000979     Can't open /var/state/ups/usbhid-ups-eco650: No such file or directory
   5.000997     [D1] Subsequent request for other driver to exit returned code -1
   5.001006     [D5] send_to_all: SETINFO device.type "ups"
   5.001011     [D5] send_to_all: SETINFO driver.state "init.device"
   5.001015     [D1] upsdrv_initups (non-SHUT)...
   5.001020     [D2] Initializing an USB-connected UPS with library libusb-1.0.24 (API: 0x1000108) (NUT subdriver name='USB communication driver (libusb 1.0)' ver='0.47')
...

 Apr 13 18:23:35 pve systemd[1]: [email protected]: Scheduled restart job, restart counter is at 2.
Apr 13 18:23:35 pve systemd[1]: Stopped Network UPS Tools - device driver for NUT device 'eco650'.
Apr 13 18:23:35 pve systemd[1]: Starting Network UPS Tools - device driver for NUT device 'eco650'...
Apr 13 18:23:35 pve nut-driver@eco650[998478]: Network UPS Tools - UPS driver controller 2.8.2-57-g2eee28ce9
Apr 13 18:23:35 pve nut-driver@eco650[998478]: Network UPS Tools - Generic HID driver 0.53 (2.8.2-57-g2eee28ce9)
Apr 13 18:23:35 pve nut-driver@eco650[998478]: USB communication driver (libusb 1.0) 0.47

  15.167175     sock_connect: enabling asynchronous mode (auto)
  15.167191     [D3] new connection on fd 11
  15.167203     [D6] Driver on /var/state/ups/usbhid-ups-eco650 is now handling NOBROADCAST with 1 args
  15.167207     [D1] sock_arg: socket 11 requested NOBROADCAST mode
  15.167210     [D6] Driver on /var/state/ups/usbhid-ups-eco650 is now handling PING with 1 args
  15.167214     [D2] send_to_one: sending PONG
  15.167216     [D5] send_to_one: PONG
  15.167223     [D6] send_to_one: write 5 bytes to socket 11 succeeded (ret=5): PONG

  15.167251     [D6] Driver on /var/state/ups/usbhid-ups-eco650 is now handling INSTCMD with 4 args
  15.167255     [D3] sock_arg: TRACKING = 2DDC5036-F665-4D29-BE4C-0374D091D263
  15.167259     [D2] entering main_instcmd(driver.exit, (null)) for [eco650] on socket 11
  15.167262     [D1] set_exit_flag: raising exit flag due to signal -2
  15.167265     [D2] send_to_one: sending TRACKING 2DDC5036-F665-4D29-BE4C-0374D091D263 0
  15.167267     [D5] send_to_one: TRACKING 2DDC5036-F665-4D29-BE4C-0374D091D263 0
  15.167272     [D6] send_to_one: write 48 bytes to socket 11 succeeded (ret=48): TRACKING 2DDC5036-F665-4D29-BE4C-0374D091D263 0

  15.167275     Signal -2: exiting
  15.167284     [D5] send_to_all: SETINFO driver.state "cleanup.upsdrv"
  15.167289     [D6] send_to_all: write 38 bytes to socket 10 succeeded (ret=38): SETINFO driver.state "cleanup.upsdrv"

  15.167292     [D1] upsdrv_cleanup...
  15.167396     [D5] send_to_all: SETINFO driver.state "cleanup.exit"
  15.167403     [D6] send_to_all: write 36 bytes to socket 10 succeeded (ret=36): SETINFO driver.state "cleanup.exit"

Apr 13 18:23:35 pve nut-driver@eco650[998478]: Duplicate driver instance detected (local Unix socket exists)! Asking other driver to self-terminate!
Apr 13 18:23:43 pve nut-driver@eco650[998478]: Using subdriver: MGE HID 1.46
Apr 13 18:23:45 pve nut-driver@eco650[998478]: Running as foreground process, but saving a PID file anyway
Apr 13 18:23:45 pve usbhid-ups[998478]: Running as foreground process, but saving a PID file anyway
Apr 13 18:23:45 pve systemd[1]: Started Network UPS Tools - device driver for NUT device 'eco650'.
Apr 13 18:23:45 pve nut-driver@eco650[998478]: upsnotify: logged the systemd watchdog situation once, will not spam more about it
Apr 13 18:23:45 pve usbhid-ups[998478]: upsnotify: logged the systemd watchdog situation once, will not spam more about it
Apr 13 18:23:46 pve nut-driver@eco650[998478]: sock_connect: enabling asynchronous mode (auto)
Apr 13 18:23:46 pve usbhid-ups[998478]: sock_connect: enabling asynchronous mode (auto)

TODO: "Asking" => "Asked"

@jimklimov
Copy link
Member Author

Screenshots again, with updated messages:

:; make -ks -j 20 >/dev/null 2>&1 && ./drivers/usbhid-ups -a eco650
Network UPS Tools - Generic HID driver 0.53 (2.8.2-60-gdeba0a96a)
USB communication driver (libusb 1.0) 0.47
Duplicate driver instance detected (local Unix socket exists)! Asked the other driver nicely to self-terminate!
Apr 13 18:42:35 pve nut-driver@eco650[1180015]: sock_connect: enabling asynchronous mode (auto)
Apr 13 18:42:35 pve nut-driver@eco650[1180015]: Signal -2: exiting
Apr 13 18:42:35 pve usbhid-ups[1180015]: sock_connect: enabling asynchronous mode (auto)
Apr 13 18:42:35 pve usbhid-ups[1180015]: Signal -2: exiting
Apr 13 18:42:35 pve systemd[1]: [email protected]: Succeeded.
Using subdriver: MGE HID 1.46

Apr 13 18:42:50 pve systemd[1]: [email protected]: Scheduled restart job, restart counter is at 1.
Apr 13 18:42:50 pve systemd[1]: Stopped Network UPS Tools - device driver for NUT device 'eco650'.
Apr 13 18:42:50 pve systemd[1]: Starting Network UPS Tools - device driver for NUT device 'eco650'...
Apr 13 18:42:50 pve nut-driver@eco650[1182821]: Network UPS Tools - UPS driver controller 2.8.2-60-gdeba0a96a
Apr 13 18:42:50 pve nut-driver@eco650[1182821]: Network UPS Tools - Generic HID driver 0.53 (2.8.2-60-gdeba0a96a)
Apr 13 18:42:50 pve nut-driver@eco650[1182821]: USB communication driver (libusb 1.0) 0.47
Apr 13 18:42:51 pve nut-driver@eco650[1182821]: Duplicate driver instance detected (local Unix socket exists)! Asked the other driver nicely to self-terminate!
Apr 13 18:42:59 pve nut-driver@eco650[1182821]: Using subdriver: MGE HID 1.46
Apr 13 18:43:01 pve nut-driver@eco650[1182821]: Running as foreground process, but saving a PID file anyway
Apr 13 18:43:01 pve usbhid-ups[1182821]: Running as foreground process, but saving a PID file anyway
Apr 13 18:43:01 pve systemd[1]: Started Network UPS Tools - device driver for NUT device 'eco650'.
Apr 13 18:43:01 pve nut-driver@eco650[1182821]: upsnotify: logged the systemd watchdog situation once, will not spam more about it
Apr 13 18:43:01 pve usbhid-ups[1182821]: upsnotify: logged the systemd watchdog situation once, will not spam more about it
Apr 13 18:43:03 pve nut-driver@eco650[1182821]: sock_connect: enabling asynchronous mode (auto)
Apr 13 18:43:03 pve usbhid-ups[1182821]: sock_connect: enabling asynchronous mode (auto)
  • Behavior when no competition is running is quick (5s to detect and walk the USB device) and quiet:
:; systemctl stop nut-driver@eco650
Apr 13 18:44:13 pve systemd[1]: Stopping Network UPS Tools - device driver for NUT device 'eco650'...
Apr 13 18:44:13 pve nut-driver@eco650[1234303]: Network UPS Tools - UPS driver controller 2.8.2-60-gdeba0a96a
Apr 13 18:44:13 pve nut-driver@eco650[1182821]: Signal 15: exiting
Apr 13 18:44:13 pve usbhid-ups[1182821]: Signal 15: exiting
Apr 13 18:44:14 pve systemd[1]: [email protected]: Succeeded.
Apr 13 18:44:14 pve systemd[1]: Stopped Network UPS Tools - device driver for NUT device 'eco650'.

:; make -ks -j 20 >/dev/null 2>&1 && time ./drivers/usbhid-ups -a eco650
Network UPS Tools - Generic HID driver 0.53 (2.8.2-60-gdeba0a96a)
USB communication driver (libusb 1.0) 0.47
Using subdriver: MGE HID 1.46

real    0m5.888s
user    0m0.000s
sys     0m0.007s
  • Behavior when some competition is running (copy from the earlier test) - note the at least +5 sec waiting for the sibling to disappear:
:; make -ks -j 20 >/dev/null 2>&1 && time ./drivers/usbhid-ups -a eco650
Network UPS Tools - Generic HID driver 0.53 (2.8.2-60-gdeba0a96a)
USB communication driver (libusb 1.0) 0.47
Duplicate driver instance detected (local Unix socket exists)! Asked the other driver nicely to self-terminate!
Using subdriver: MGE HID 1.46

real    0m11.344s
user    0m0.008s
sys     0m0.000s

@jimklimov
Copy link
Member Author

jimklimov commented Apr 13, 2024

Calling commands on the driver is not compromised by the new feature, e.g.:

:; make -ks -j 20 >/dev/null 2>&1 && time ./drivers/usbhid-ups -a eco650 -c reload
Network UPS Tools - Generic HID driver 0.53 (2.8.2-60-gdeba0a96a)
USB communication driver (libusb 1.0) 0.47
Request for driver to reload-or-error returned code 0
upsnotify: notify about state 4 with libsystemd: was requested, but not running as a service unit now, will not spam more about it
upsnotify: failed to notify about state 4: no notification tech defined, will not spam more about it

real    0m0.003s
user    0m0.000s
sys     0m0.002s


Apr 13 19:34:11 pve nut-driver@eco650[2610940]: sock_connect: enabling asynchronous mode (auto)
Apr 13 19:34:11 pve nut-driver@eco650[2610940]: Handling requested live reload of NUT driver configuration for [eco650]
Apr 13 19:34:11 pve nut-driver@eco650[2610940]: Applying debug_min=0 from ups.conf driver section (overriding global 0)
Apr 13 19:34:11 pve nut-driver@eco650[2610940]: Applying debug level 0 from original command line arguments
Apr 13 19:34:11 pve nut-driver@eco650[2610940]: Completed requested live reload of NUT driver configuration for [eco650]: 0
Apr 13 19:34:11 pve usbhid-ups[2610940]: sock_connect: enabling asynchronous mode (auto)
Apr 13 19:34:11 pve usbhid-ups[2610940]: Handling requested live reload of NUT driver configuration for [eco650]
Apr 13 19:34:11 pve usbhid-ups[2610940]: Applying debug_min=0 from ups.conf driver section (overriding global 0)
Apr 13 19:34:11 pve usbhid-ups[2610940]: Applying debug level 0 from original command line arguments
Apr 13 19:34:11 pve usbhid-ups[2610940]: Completed requested live reload of NUT driver configuration for [eco650]: 0
:; make -ks -j 20 >/dev/null 2>&1 && time ./drivers/upsdrvctl -c reload eco650
Network UPS Tools - UPS driver controller 2.8.2-60-gdeba0a96a
Request for driver to reload-or-error returned code 0

real    0m0.001s
user    0m0.001s
sys     0m0.000s


Apr 13 19:35:23 pve nut-driver@eco650[2610940]: sock_connect: enabling asynchronous mode (auto)
Apr 13 19:35:23 pve nut-driver@eco650[2610940]: Handling requested live reload of NUT driver configuration for [eco650]
Apr 13 19:35:23 pve nut-driver@eco650[2610940]: Applying debug_min=0 from ups.conf driver section (overriding global 0)
Apr 13 19:35:23 pve nut-driver@eco650[2610940]: Applying debug level 0 from original command line arguments
Apr 13 19:35:23 pve nut-driver@eco650[2610940]: Completed requested live reload of NUT driver configuration for [eco650]: 0
Apr 13 19:35:23 pve usbhid-ups[2610940]: sock_connect: enabling asynchronous mode (auto)
Apr 13 19:35:23 pve usbhid-ups[2610940]: Handling requested live reload of NUT driver configuration for [eco650]
Apr 13 19:35:23 pve usbhid-ups[2610940]: Applying debug_min=0 from ups.conf driver section (overriding global 0)
Apr 13 19:35:23 pve usbhid-ups[2610940]: Applying debug level 0 from original command line arguments
Apr 13 19:35:23 pve usbhid-ups[2610940]: Completed requested live reload of NUT driver configuration for [eco650]: 0

@jimklimov jimklimov added the ready / code review Author (and CI) consider the PR worthy of human rewievers' time label Apr 13, 2024
@clepple clepple removed their request for review April 13, 2024 20:53
@jimklimov jimklimov merged commit b488693 into networkupstools:master Apr 16, 2024
@jimklimov jimklimov deleted the issue-2392 branch April 16, 2024 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement NUT protocols ready / code review Author (and CI) consider the PR worthy of human rewievers' time service/daemon start/stop General subject for starting and stopping NUT daemons (drivers, server, monitor); also BG/FG/Debug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Driver main.c: use Unix socket protocol to kill off "Duplicate other instance"

2 participants