Skip to content

Commit

Permalink
Merge pull request #1777 from jimklimov/issue-1590
Browse files Browse the repository at this point in the history
Introduce optional `sd_notify()` support for READY, RELOADING and STOPPING states, and a WATCHDOG (if enabled)
  • Loading branch information
jimklimov authored Jan 8, 2023
2 parents c860d9d + ad70749 commit 0b487c0
Show file tree
Hide file tree
Showing 21 changed files with 714 additions and 28 deletions.
19 changes: 13 additions & 6 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -155,30 +155,30 @@ https://github.com/networkupstools/nut/milestone/8
this variable unless troubleshooting, although other systems rely on it)
[#805]

- the nut-scanner program was updated to fall back to loading unresolved
- The nut-scanner program was updated to fall back to loading unresolved
library filenames, hoping that `lt_dlopen()` implementation on the current
platform would find library files better [#805]

- detection of `libltdl` in `configure` script updated with fallback code to
- Detection of `libltdl` in `configure` script updated with fallback code to
find it on systems that deliver the library to `/usr/local/lib` (e.g. on
FreeBSD) [#1577]

- an explicit `configure --with-nut-scanner` toggle was added, specifically
- An explicit `configure --with-nut-scanner` toggle was added, specifically
so that build environments requesting `--with-all` but lack `libltdl` would
abort and require either to install the dependency or explicitly forfeit
the tool (some distro packages missed it quietly in the past) [#1560]

- existing openssl-1.1.0 support added for NUT v2.8.0 release was tested to
- Existing openssl-1.1.0 support added for NUT v2.8.0 release was tested to
be sufficient without deprecation warnings for builds against openssl-3.0.x
(but no real-time testing was done yet) [#1547]

- upslog: Added support for logging multiple devices with one call to the
program [#1604]

- some fixes applied to Solaris/illumos packaging and SMF service support
- Some fixes applied to Solaris/illumos packaging and SMF service support
[#1554, #1564]

- some fixes for builds on older OSes with less functional default system
- Some fixes for builds on older OSes with less functional default system
shell interpreters - now `autogen.sh` supports a `CONFIG_SHELL` envvar
to inject its value into generated `configure` script [#1736]
* Note that you may have to install additional tools (possibly from
Expand Down Expand Up @@ -222,6 +222,13 @@ https://github.com/networkupstools/nut/milestone/8
encouraged to pick optimal location for their distributions (which
remains mounted at least read-only late in shutdown) [#529]

- Extended Linux systemd support with optional notifications about daemon
state (READY, RELOADING, STOPPING) and watchdog keep-alive messages [#1590]

- Extended Linux systemd units with aliases named after the daemons:
`nut-server.service` as `upsd.service`, and `nut-monitor.service` as
`upsmon.service` (so simple `systemctl reload upsd` can work) [#1777]

- Further revision of public headers delivered by NUT was done, particularly
to address lack of common data types (`size_t`, `ssize_t`, `uint16_t`,
`time_t` etc.) in third-party client code that earlier sufficed to only
Expand Down
9 changes: 8 additions & 1 deletion UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Changes from 2.8.0 to 2.8.1
serial drivers in respective Makefile and configure script options - this
may impact packaging decisions on some distributions going forward [#1446]

- an explicit `configure --with-nut-scanner` toggle was added, specifically
- An explicit `configure --with-nut-scanner` toggle was added, specifically
so that build environments requesting `--with-all` but lacking `libltdl`
would abort and require the packager either to install the dependency
or explicitly forfeit building the tool (some distro packages missed it
Expand All @@ -66,6 +66,13 @@ Changes from 2.8.0 to 2.8.1
* Several other issues have been fixed related to this file and its content,
including #1030, #1037, #1117 and #1712

- Extended Linux systemd support with optional notifications about daemon
state (READY, RELOADING, STOPPING) and watchdog keep-alive messages.
Note that `WatchdogSec=` values are currently NOT pre-set into systemd
unit file templates provided by NUT, this is an exercise for end-users
based on sizing of their deployments and performance of monitoring station
[#1590, #1777]

- snmp-ups: some subdrivers (addressed using the driver parameter `mibs`)
were renamed: `pw` is now `eaton_pw_nm2`, and `pxgx_ups` is `eaton_pxg_ups`
[#1715]
Expand Down
8 changes: 8 additions & 0 deletions clients/upslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,11 @@ int main(int argc, char **argv)

compile_format();

upsnotify(NOTIFY_STATE_READY_WITH_PID, NULL);

while (exit_flag == 0) {
upsnotify(NOTIFY_STATE_WATCHDOG, NULL);

time(&now);

if (nextpoll > now) {
Expand All @@ -631,10 +635,12 @@ int main(int argc, char **argv)
}

if (reopen_flag) {
upsnotify(NOTIFY_STATE_RELOADING, NULL);
upslogx(LOG_INFO, "Signal %d: reopening log file",
reopen_flag);
reopen_log();
reopen_flag = 0;
upsnotify(NOTIFY_STATE_READY, NULL);
}

for (monhost_ups_current = monhost_ups_anchor;
Expand All @@ -657,6 +663,8 @@ int main(int argc, char **argv)
}

upslogx(LOG_INFO, "Signal %d: exiting", exit_flag);
upsnotify(NOTIFY_STATE_STOPPING, "Signal %d: exiting", exit_flag);

for (monhost_ups_current = monhost_ups_anchor;
monhost_ups_current != NULL;
monhost_ups_current = monhost_ups_current->next) {
Expand Down
13 changes: 12 additions & 1 deletion clients/upsmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,8 @@ static void doshutdown(void)

static void doshutdown(void)
{
upsnotify(NOTIFY_STATE_STOPPING, "Executing automatic power-fail shutdown");

/* this should probably go away at some point */
upslogx(LOG_CRIT, "Executing automatic power-fail shutdown");
wall("Executing automatic power-fail shutdown\n");
Expand Down Expand Up @@ -2580,6 +2582,7 @@ int main(int argc, char *argv[])
}

if (upscli_init(certverify, certpath, certname, certpasswd) < 0) {
upsnotify(NOTIFY_STATE_STOPPING, "Failed upscli_init()");
exit(EXIT_FAILURE);
}

Expand All @@ -2590,15 +2593,22 @@ int main(int argc, char *argv[])
closelog();
open_syslog(prog);

upsnotify(NOTIFY_STATE_READY_WITH_PID, NULL);

while (exit_flag == 0) {
utype_t *ups;

upsnotify(NOTIFY_STATE_WATCHDOG, NULL);

/* check flags from signal handlers */
if (userfsd)
forceshutdown();

if (reload_flag)
if (reload_flag) {
upsnotify(NOTIFY_STATE_RELOADING, NULL);
reload_conf();
upsnotify(NOTIFY_STATE_READY, NULL);
}

for (ups = firstups; ups != NULL; ups = ups->next)
pollups(ups);
Expand Down Expand Up @@ -2676,6 +2686,7 @@ int main(int argc, char *argv[])
}

upslogx(LOG_INFO, "Signal %d: exiting", exit_flag);
upsnotify(NOTIFY_STATE_STOPPING, "Signal %d: exiting", exit_flag);
upsmon_cleanup();

exit(EXIT_SUCCESS);
Expand Down
16 changes: 16 additions & 0 deletions common/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ endif
libcommon_la_LIBADD = libparseconf.la @LTLIBOBJS@ @NETLIBS@
libcommonclient_la_LIBADD = libparseconf.la @LTLIBOBJS@ @NETLIBS@

libcommon_la_CFLAGS = $(AM_CFLAGS)
libcommonclient_la_CFLAGS = $(AM_CFLAGS)

# Did the user request, and build env support, tighter integration with
# libsystemd methods such as sd_notify()?
if WITH_LIBSYSTEMD
libcommon_la_CFLAGS += $(LIBSYSTEMD_CFLAGS)
libcommon_la_LIBADD += $(LIBSYSTEMD_LIBS)

# A typical client should not need this,
# but just in case (and to simplify linking)...
# libcommonclient_la_CFLAGS += $(LIBSYSTEMD_CFLAGS)
# libcommonclient_la_LIBADD += $(LIBSYSTEMD_LIBS)
libcommonclient_la_CFLAGS += -DWITHOUT_LIBSYSTEMD=1
endif

MAINTAINERCLEANFILES = Makefile.in .dirstamp

# NOTE: Do not clean ".deps" in SUBDIRS of the main project,
Expand Down
Loading

0 comments on commit 0b487c0

Please sign in to comment.