Skip to content

Support debug level passed via ups.conf and -F/-B explicit fore/back-grounding mode for NUT daemons#683

Merged
jimklimov merged 36 commits intonetworkupstools:masterfrom
jimklimov:debug_min
Feb 16, 2022
Merged

Support debug level passed via ups.conf and -F/-B explicit fore/back-grounding mode for NUT daemons#683
jimklimov merged 36 commits intonetworkupstools:masterfrom
jimklimov:debug_min

Conversation

@jimklimov
Copy link
Member

@jimklimov jimklimov commented Apr 1, 2019

There were previously attempts to arrange debugability of "production-mode" start-up of NUT daemons vs. their forced foregrounding in case of -D options present in command line. As I recently needed to inspect how driver services start and why they failed in my case, I took another attempt in this area, and came up with the proposed solution (just for drivers so far) to:

  • separate the -D CLI option vs. explicit option to foreground -F or background -B the daemon; if neither of the latter options is set, defaults are as before (go background unless debugged);

    ** Names/shortcuts/help-text of the options can be subject to peer review, to have some values acceptable for consistently named options across the board, if we extend this approach to other NUT daemons;

  • allow to set the default (driver) debugging level in either global or driver-level section of ups.conf; if both are set, the driver-level setting takes precedence; either of these may be set to a zero or positive integer;

    ** unlike command-line -D this setting does not require foregrounding (-F can be explicitly passed if desired) so the service daemons stay backgrounded by default as before;

    ** this allows to see debug messages in original service log, with the service units (access rights, environment, etc.) otherwise not modified - which often corrupts or complicates command-line troubleshooting;

    ** a more arguable corollary: since we do not currently have a way to disable debugging (set 0 level) I chose to require that the valid option in ups.conf (global section, or preferably driver-level value) specifies the minimum debugging level applied to the daemon -- if the command-line invocation specifies less -D flags, the practically applied level would be the one in the config.

    *** Per peer review, this design choice (and config option name) can be amended; at the very least with current implementation a CLI caller can easily set a minimum of -D (== 1) level instead, and something in CLI processing would need to be invented to reset a "-D == 0" level.

(see also #123 and #821 and #349)

@jimklimov jimklimov requested review from aquette, clepple and zykh April 1, 2019 10:03
@jimklimov jimklimov added the service/daemon start/stop General subject for starting and stopping NUT daemons (drivers, server, monitor); also BG/FG/Debug label Nov 14, 2021
@jimklimov
Copy link
Member Author

jimklimov commented Feb 15, 2022

Testing with ups.conf to the effect of:

debug_min = 6

[nutdev1]
        driver = "usbhid-ups"
        port = "auto"
        debug_min = 4

Here driver-level setting takes precedence over global-level one, and over the (lower) debug set on CLI (pass-through from upsdrvctl courtesy of #1287):

# ./drivers/upsdrvctl -DDDd start nutdev1
...
   0.006049     [D1] debug level is '4'
...

A higher level may still be specified on command line and takes effect:

# ./drivers/upsdrvctl -DDDDDd start nutdev1
...
   0.006818     [D1] debug level is '5'
...

With driver-level debug_min commented away, the global setting takes hold for the same runs, overriding smaller CLI values:

   0.005788     [D1] debug level is '6'

(and yielding to larger CLI values: 0.006607 [D1] debug level is '7')

@jimklimov
Copy link
Member Author

jimklimov commented Feb 15, 2022

Similarly, checked for other daemons, e.g. upsmon:

# /usr/local/ups/sbin/upsmon -F
Network UPS Tools upsmon 2.7.4-4660-gc31748b
fopen /var/run/upsmon.pid: No such file or directory
UPS: nutdev1 (primary) (power value 1)
Using power down flag file /etc/killpower
   0.000000     [D1] debug level is '3'
   0.000706     [D1] debug level is '3'
...

(second line probably comes from child process arrangements? though there shouldn't be a child in foreground mode? Just privilege drop - and maybe a re-parse?)

...and upsd when started as part of nut-server systemd unit:

-- Logs begin at Tue 2022-02-15 12:33:38 UTC, end at Tue 2022-02-15 13:41:56 UTC. --
Feb 15 12:33:49 mirabox systemd[1]: Starting Network UPS Tools - power devices information server...
Feb 15 12:33:49 mirabox systemd[1]: Started Network UPS Tools - power devices information server.
Feb 15 12:33:49 mirabox nut-server[1769]: fopen /var/state/ups/upsd.pid: No such file or directory
Feb 15 12:33:49 mirabox nut-server[1769]: /usr/local/ups/etc/upsd.conf is world readable
Feb 15 12:33:49 mirabox upsd[1769]: /usr/local/ups/etc/upsd.conf is world readable
>>> Feb 15 12:33:49 mirabox upsd[1769]: [D1] debug level is '2'
Feb 15 12:33:49 mirabox upsd[1769]: listening on 127.0.0.1 port 3493
Feb 15 12:33:49 mirabox upsd[1769]: listening on ::1 port 3493
...

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

Labels

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.

2 participants