Skip to content

Introduce a rootpidpath() method instead of direct use of PIDPATH macro (e.g. in upsmon) - #2407

Merged
jimklimov merged 25 commits into
networkupstools:masterfrom
jimklimov:nut-upsmon
Apr 18, 2024
Merged

jimklimov merged 25 commits into
networkupstools:masterfrom
jimklimov:nut-upsmon

Conversation

@jimklimov

@jimklimov jimklimov commented Apr 17, 2024 •

Copy link
Copy Markdown
Member

Also update the NIT script regarding upsmon.conf generation and friendliness to run NUT programs against the prepared testbed, and improve the ability to generate variants of upsmon configuration and to launch the daemon in tests (no particular tests added so far).

And bump (C) on C++ code, due to a few changes there and noticing some staleness in the file headings.

Also introduced value caching for this and other path-getting methods - so that subsequent calls return the same value quickly (less work, more reproducibility. Checked that no NUT C programs use setenv along the way (at all, and notably not for path-related envvars in particular), which could potentially impact this logic change.

Regarding the rootpidpath() - an envvar is now honoured:

:; ./clients/upsmon -DDDDDD
Network UPS Tools upsmon 2.8.2-80-g405031c5a
   0.000000     fopen /home/jim/nut/tmp/run/upsmon.pid: No such file or directory
   0.000054     Could not find PID file to see if previous upsmon instance is already running!
   0.000077     [D1:84462] loadconfig: Loading /home/jim/nut/tmp/etc/upsmon.conf
...

Before this change, upsmon insisted on fopen /run/upsmon.pid per (lack of) config from ci_build.sh

As of this posting, manual testing with NIT involved:

:; DEBUG_SLEEP=600 ./tests/NIT/nit.sh &

### Wait for tests to pass - until the message that it sleeps with daemons alive
### and the path of file with envvars to source, e.g.
### Wed Apr 17 09:41:42 UTC 2024 [INFO] Sleeping now as asked (for 600 seconds starting Wed Apr 17 09:41:42 UTC 2024), so you can play with the driver and server running
### Wed Apr 17 09:41:42 UTC 2024 [INFO] Populated environment variables for this run into a file so you can source them: . 
'/home/jim/nut/tmp/etc/NIT.env'
### (content printout follows)

:; . '/home/jim/nut/tmp/etc/NIT.env'

### Note that currently no test generated the file
### (or at least did not customize the PSU count)
:; cat "$NUT_CONFPATH/upsmon.conf"
cat: /home/jim/nut/tmp/etc/upsmon.conf: No such file or directory

:; NIT_CASE="generatecfg_upsmon_master 2" ./tests/NIT/nit.sh

:; cat "$NUT_CONFPATH/upsmon.conf"
MINSUPPLIES 2
SHUTDOWNCMD "echo \"`date`: TESTING_DUMMY_SHUTDOWN_NOW\" | tee \"$NUT_STATEPATH\"/upsmon.sd.log"
MONITOR 'dummy@localhost:35017' 2 'dummy-admin-m' 'P@ssW0rdAdm' master

:; ./clients/upsmon -DDDDDD
...

…ternal testing (notably with DEBUG_SLEEP and test daemons left running)

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
… customize power supply count (served by MONITOR, required by MINSUPPLIES)

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…record its attempts into a "$NUT_STATEPATH/upsmon.sd.log" file

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…ath(), dflt_statepath() on the first call

Speed up work upon subsequent calls, and be sure to return the same value consistently.

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…e-runs of the script

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
@jimklimov jimklimov added enhancement CI Entries related to continuous integration infrastructure (here CI = tools + scripts + recipes) service/daemon start/stop General subject for starting and stopping NUT daemons (drivers, server, monitor); also BG/FG/Debug upsmon labels Apr 17, 2024
@jimklimov jimklimov added this to the 2.8.3 milestone Apr 17, 2024
@jimklimov jimklimov added the C++ label Apr 17, 2024
…" settings as comments

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…ecfg_*|is*

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…neratecfg_*|is*

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…neratecfg_*|is*

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
@jimklimov

jimklimov commented Apr 17, 2024 •

Copy link
Copy Markdown
Member Author

Curiously, the test suggests a parser error about host and port handling in MONITOR line?..

:; ./clients/upsmon -DDDDDD
Network UPS Tools upsmon 2.8.2-80-g405031c5a
kill: No such process
   0.000000     [D1:42528] Just failed to send signal, no daemon was running
   0.000058     [D1:42528] loadconfig: Loading /home/jim/nut/tmp/etc/upsmon.conf
   0.000147     UPS: 'dummy@localhost:35017' (primary) (power value 2)
...
   0.002536     [D1:42542] Trying to connect to UPS ['dummy@localhost:35017']
   0.003025     Login on UPS ['dummy@localhost:35017'] failed - got [ERR UNKNOWN-UPS]
   0.003051     [D3:42542] Current power value: 2
   0.003073     [D3:42542] Minimum power value: 2
   5.491904     [D2:42542] pollups: 'dummy@localhost:35017'
   5.491975     [D3:42542] get_var: 'dummy@localhost:35017' / status
   5.492238     [D3:42542] pollups: Poll UPS ['dummy@localhost:35017'] after getvar(status) failed: upserror=4
   5.492277     Poll UPS ['dummy@localhost:35017'] failed - ['dummy] does not exist on server localhost
   5.492326     [D2:42542] do_notify: ntype 0x0005 (COMMBAD)
   5.492365     [D6:42542] notify: sending notification for ['dummy@localhost:35017']: type COMMBAD with flags 0x0006: Communications with UPS 'dummy@localhost:35017' lost
   5.492403     [D6:42542] notify: NOTIFY_SYSLOG (as LOG_NOTICE)
   5.492439     Communications with UPS 'dummy@localhost:35017' lost
...

While upsd knows about it:

:; upsc dummy@localhost:35017
device.mfr: Dummy Manufacturer
device.model: Dummy UPS
device.type: ups
driver.debug: 0
driver.flag.allow_killpower: 0
driver.name: dummy-ups
driver.parameter.mode: dummy-loop
driver.parameter.pollinterval: 2
driver.parameter.port: dummy.seq
driver.parameter.synchronous: auto
driver.state: quiet
driver.version: 2.8.2-80-g405031c5a
driver.version.internal: 0.19
ups.mfr: Dummy Manufacturer
ups.model: Dummy UPS
ups.status: OB

Also: kill: No such process should be quiet like fopen() nowadays. UPDATE: fixed

…PING value for nut_sendsignal_debug_level [networkupstools#1782]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
@jimklimov

jimklimov commented Apr 17, 2024 •

Copy link
Copy Markdown
Member Author

Quicker reproduction cycle:

:; NUT_DEBUG_LEVEL=6 NIT_CASE=testcase_sandbox_start_drivers_after_upsd DEBUG_SLEEP=600 ./tests/NIT/nit.sh & sleep 5 ; NIT_CASE="generatecfg_upsmon_master 2" ./tests/NIT/nit.sh

### Wait for test preparation to go to DEBUG_SLEEP mode
:; ./clients/upsmon -DDDDDD

...
   0.002320     [D1:8144] Trying to connect to UPS ['dummy@localhost:35017']
  16.018221     [D2:7940] Connect from 127.0.0.1
  16.018265     [D2:7940] mainloop: polling 6 filedescriptors
  16.018304     [D6:7940] Entering check_command: STARTTLS
  16.018337     [D6:7940] check_command: Calling command handler for STARTTLS
  16.018371     [D4:7940] Sending error [FEATURE-NOT-CONFIGURED] to client 127.0.0.1
  16.018437     [D2:7940] write: [destfd=8] [len=27] [ERR FEATURE-NOT-CONFIGURED]
  16.018479     [D2:7940] mainloop: polling 6 filedescriptors
  16.018528     [D6:7940] Entering check_command: USERNAME
  16.018567     [D6:7940] check_command: Calling command handler for USERNAME
  16.018644     [D2:7940] write: [destfd=8] [len=3] [OK]
  16.018685     [D2:7940] mainloop: polling 6 filedescriptors
  16.018731     [D6:7940] Entering check_command: PASSWORD
  16.018771     [D6:7940] check_command: Calling command handler for PASSWORD
  16.018848     [D2:7940] write: [destfd=8] [len=3] [OK]
  16.018889     [D2:7940] mainloop: polling 6 filedescriptors
  16.018937     [D6:7940] Entering check_command: LOGIN
  16.019011     [D6:7940] check_command: Calling command handler for LOGIN
  16.019052     [D4:7940] Sending error [UNKNOWN-UPS] to client 127.0.0.1
  16.019131     [D2:7940] write: [destfd=8] [len=16] [ERR UNKNOWN-UPS]
   0.003478     Login on UPS ['dummy@localhost:35017'] failed - got [ERR UNKNOWN-UPS]
   0.003488     [D3:8144] Current power value: 2
...

Active configs:

:; grep . $NUT_CONFPATH/u*
/home/jim/nut/tmp/etc/ups.conf:maxretry = 3
/home/jim/nut/tmp/etc/ups.conf:[dummy]
/home/jim/nut/tmp/etc/ups.conf:    driver = dummy-ups
/home/jim/nut/tmp/etc/ups.conf:    desc = "Crash Dummy"
/home/jim/nut/tmp/etc/ups.conf:    port = dummy.seq
/home/jim/nut/tmp/etc/ups.conf:    #mode = dummy-loop
/home/jim/nut/tmp/etc/ups.conf:[UPS1]
/home/jim/nut/tmp/etc/ups.conf:    driver = dummy-ups
/home/jim/nut/tmp/etc/ups.conf:    desc = "Example event sequence"
/home/jim/nut/tmp/etc/ups.conf:    port = evolution500.seq
/home/jim/nut/tmp/etc/ups.conf:[UPS2]
/home/jim/nut/tmp/etc/ups.conf:    driver = dummy-ups
/home/jim/nut/tmp/etc/ups.conf:    desc = "Example ePDU data dump"
/home/jim/nut/tmp/etc/ups.conf:    port = epdu-managed.dev
/home/jim/nut/tmp/etc/ups.conf:    mode = dummy-once

/home/jim/nut/tmp/etc/upsd.conf:STATEPATH "/home/jim/nut/tmp/run"
/home/jim/nut/tmp/etc/upsd.conf:LISTEN localhost 35017
/home/jim/nut/tmp/etc/upsd.conf:LISTEN 127.0.0.1 35017
/home/jim/nut/tmp/etc/upsd.conf:LISTEN ::1 35017
/home/jim/nut/tmp/etc/upsd.conf:ALLOW_NO_DEVICE true

/home/jim/nut/tmp/etc/upsd.users:[admin]
/home/jim/nut/tmp/etc/upsd.users:    password = mypass
/home/jim/nut/tmp/etc/upsd.users:    actions = SET
/home/jim/nut/tmp/etc/upsd.users:    instcmds = ALL
/home/jim/nut/tmp/etc/upsd.users:[tester]
/home/jim/nut/tmp/etc/upsd.users:    password = "pass words"
/home/jim/nut/tmp/etc/upsd.users:    instcmds = test.battery.start
/home/jim/nut/tmp/etc/upsd.users:    instcmds = test.battery.stop
/home/jim/nut/tmp/etc/upsd.users:[dummy-admin-m]
/home/jim/nut/tmp/etc/upsd.users:    password = "P@ssW0rdAdm"
/home/jim/nut/tmp/etc/upsd.users:    upsmon master
/home/jim/nut/tmp/etc/upsd.users:[dummy-admin]
/home/jim/nut/tmp/etc/upsd.users:    password = "P@ssW0rdAdm"
/home/jim/nut/tmp/etc/upsd.users:    upsmon primary
/home/jim/nut/tmp/etc/upsd.users:[dummy-user-s]
/home/jim/nut/tmp/etc/upsd.users:    password = "P@ssW0rd"
/home/jim/nut/tmp/etc/upsd.users:    upsmon slave
/home/jim/nut/tmp/etc/upsd.users:[dummy-user]
/home/jim/nut/tmp/etc/upsd.users:    password = "P@ssW0rd"
/home/jim/nut/tmp/etc/upsd.users:    upsmon secondary

/home/jim/nut/tmp/etc/upsmon.conf:MINSUPPLIES 2
/home/jim/nut/tmp/etc/upsmon.conf:SHUTDOWNCMD "echo \"`date`: TESTING_DUMMY_SHUTDOWN_NOW\" | tee \"$NUT_STATEPATH\"/upsmon.sd.log"
/home/jim/nut/tmp/etc/upsmon.conf:MONITOR 'dummy@localhost:35017' 2 'dummy-admin-m' 'P@ssW0rdAdm' master

…e the expanded NUT_STATEPATH value

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
@jimklimov

jimklimov commented Apr 17, 2024 •

Copy link
Copy Markdown
Member Author

Argh, the MONITOR line used wrong quotes:

  17.477533     [D3:46176] get_ups_ptr: not a valid UPS: 'dummy

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…DOWNFLAG setting [networkupstools#321]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…dbox_start_upsmon_master()

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
@jimklimov

jimklimov commented Apr 17, 2024 •

Copy link
Copy Markdown
Member Author

Fallout in C++ code builds in mingw/linux probably due to the added #include "common.h":

In file included from ../../../../include/common.h:89,
                 from ../../../../common/nutipc.cpp:28:
../../../../include/timehead.h:53:26: error: redefinition of 'tm* localtime_r(const time_t*, tm*)'
   53 | static inline struct tm *localtime_r( const time_t *timer, struct tm *buf ) {
      |                          ^~~~~~~~~~~
In file included from /usr/share/mingw-w64/include/sys/time.h:10,
                 from ../../../../include/timehead.h:32,
                 from ../../../../include/common.h:89,
                 from ../../../../common/nutipc.cpp:28:
/usr/share/mingw-w64/include/time.h:281:36: note: 'tm* localtime_r(const time_t*, tm*)' previously defined here
  281 | __forceinline struct tm *__CRTDECL localtime_r(const time_t *_Time, struct tm *_Tm) {
      |                                    ^~~~~~~~~~~
In file included from ../../../../include/common.h:89,
                 from ../../../../common/nutipc.cpp:28:
../../../../include/timehead.h:67:26: error: redefinition of 'tm* gmtime_r(const time_t*, tm*)'
   67 | static inline struct tm *gmtime_r( const time_t *timer, struct tm *buf ) {
      |                          ^~~~~~~~
In file included from /usr/share/mingw-w64/include/sys/time.h:10,
                 from ../../../../include/timehead.h:32,
                 from ../../../../include/common.h:89,
                 from ../../../../common/nutipc.cpp:28:
/usr/share/mingw-w64/include/time.h:284:36: note: 'tm* gmtime_r(const time_t*, tm*)' previously defined here
  284 | __forceinline struct tm *__CRTDECL gmtime_r(const time_t *_Time, struct tm *_Tm) {
      |                                    ^~~~~~~~

Native POSIX and Windows builds seem happy so far.

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
@jimklimov
jimklimov merged commit d865f3e into networkupstools:master Apr 18, 2024
@jimklimov
jimklimov deleted the nut-upsmon branch April 18, 2024 06:51
Challado pushed a commit to Challado/nut that referenced this pull request Oct 14, 2026
Introduce a `rootpidpath()` method instead of direct use of `PIDPATH` macro (e.g. in `upsmon`)

SVN-Git-Bridge: nut-3e341d2d9c-3fc79f1e8124 d865f3e
Bridge-Author: Jim Klimov <jimklimov+nut@gmail.com>
Bridge-Author-Date: 2024-04-18T08:51:23+02:00
Bridge-Committer: GitHub <noreply@github.com>
Bridge-Committer-Date: 2024-04-18T08:51:23+02:00
From: Jim Klimov <jimklimov+nut@gmail.com>

git-svn-id: file:///mnt/export/subversion/nut/trunk@3986 5f2f2009-99cd-4845-9af7-39d0aa6e3748
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C++ CI Entries related to continuous integration infrastructure (here CI = tools + scripts + recipes) enhancement service/daemon start/stop General subject for starting and stopping NUT daemons (drivers, server, monitor); also BG/FG/Debug upsmon

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant