From d513847e47f8eeeadbf13ac6e6c464d9ebfa421a Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 28 May 2021 16:36:50 +0200 Subject: [PATCH 1/9] [Issue #1030] Deliver systemd-tmpfiles config to pre-create runtime locations --- Makefile.am | 1 + configure.ac | 13 +++++++++++++ docs/configure.txt | 21 +++++++++++++++++++++ docs/nut.dict | 5 ++++- scripts/systemd/.gitignore | 1 + scripts/systemd/Makefile.am | 6 +++++- scripts/systemd/nut-common.tmpfiles.in | 7 +++++++ 7 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 scripts/systemd/nut-common.tmpfiles.in diff --git a/Makefile.am b/Makefile.am index 0c3dbceb7c..b8ae11fafb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -24,6 +24,7 @@ DISTCHECK_VALGRIND_FLAGS = --with-all=auto --with-ssl=auto --with-doc=skip --wit DISTCHECK_CONFIGURE_FLAGS = ${DISTCHECK_FLAGS} \ --with-systemdsystemunitdir='$${prefix}/lib/systemd/system' \ --with-systemdshutdowndir='$${prefix}/lib/systemd/system-shutdown' \ + --with-systemdtmpfilesdir='$${prefix}/usr/lib/tmpfiles.d' \ --with-augeas-lenses-dir='$${prefix}/usr/share/augeas/lenses' \ --with-hotplug-dir='$${prefix}/etc/hotplug' \ --with-udev-dir='$${prefix}/etc/udev' \ diff --git a/configure.ac b/configure.ac index 3103903714..4277ae26cf 100644 --- a/configure.ac +++ b/configure.ac @@ -1472,6 +1472,7 @@ AM_CONDITIONAL(HAVE_SYSTEMD, test "$systemdsystemunitdir" != "") dnl This option is only provided so that make distcheck can override it, dnl otherwise we ask pkg-config whenever --with-systemdsystemunitdir is dnl given + AC_ARG_WITH([systemdshutdowndir], AS_HELP_STRING([--with-systemdshutdowndir=DIR], [Directory for systemd shutdown scripts (auto)]), [systemdshutdowndir=${withval}]) @@ -1482,6 +1483,16 @@ if test -n "${systemdsystemunitdir}"; then esac fi +AC_ARG_WITH([systemdtmpfilesdir], + AS_HELP_STRING([--with-systemdtmpfilesdir=DIR], [Directory for systemd tmpfiles scripts (auto)]), + [systemdtmpfilesdir=${withval}]) +if test -n "${systemdsystemunitdir}"; then + case "${systemdtmpfilesdir}" in + yes|auto|"") + systemdtmpfilesdir=`$PKG_CONFIG --variable=tmpfilesdir systemd` + esac +fi + dnl dnl Tests for CppUnit availability and usability (will be built if we can, dnl and if valgrind is enabled for this configuration - reported below). @@ -1909,6 +1920,7 @@ AC_SUBST(htmldir) AC_SUBST(pkgconfigdir) AC_SUBST(systemdsystemunitdir) AC_SUBST(systemdshutdowndir) +AC_SUBST(systemdtmpfilesdir) AC_SUBST(auglensdir) AC_SUBST(hotplugdir) AC_SUBST(udevdir) @@ -2058,6 +2070,7 @@ AC_OUTPUT([ scripts/upsdrvsvcctl/nut-driver-enumerator.sh scripts/upsdrvsvcctl/upsdrvsvcctl scripts/systemd/Makefile + scripts/systemd/nut-common.tmpfiles scripts/systemd/nut-driver@.service scripts/systemd/nut-monitor.service scripts/systemd/nut-server.service diff --git a/docs/configure.txt b/docs/configure.txt index e8530c6469..5b16676f50 100644 --- a/docs/configure.txt +++ b/docs/configure.txt @@ -337,6 +337,27 @@ Use --with-systemdsystemunitdir to detect the settings using pkg-config. Use --with-systemdsystemunitdir=no to disable this feature altogether. + --with-systemdshutdowndir=PATH + +Where to install Linux systemd unit definitions for shutdown handling. +Useless and harmless on other OSes, including Linux distributions +without systemd, just adding a little noise to configure script output. + +Use --with-systemdshutdowndir to detect the settings using pkg-config. + +Use --with-systemdshutdowndir=no to disable this feature altogether. + + --with-systemdtmpfilesdir=PATH + +Where to install Linux systemd configuration for tmpfiles handling (the +automatically created locations for PID, state and similar run-time files). +Useless and harmless on other OSes, including Linux distributions +without systemd, just adding a little noise to configure script output. + +Use --with-systemdtmpfilesdir to detect the settings using pkg-config. + +Use --with-systemdtmpfilesdir=no to disable this feature altogether. + --with-augeas-lenses-dir=PATH Where to install Augeas configuration-management lenses. Only useful and valid diff --git a/docs/nut.dict b/docs/nut.dict index 2ceb7f8f63..826038aefc 100644 --- a/docs/nut.dict +++ b/docs/nut.dict @@ -1,4 +1,4 @@ -personal_ws-1.1 en 2549 utf-8 +personal_ws-1.1 en 2556 utf-8 AAS ACFAIL ACFREQ @@ -2322,7 +2322,9 @@ sysconfig syslog systemctl systemd +systemdshutdowndir systemdsystemunitdir +systemdtmpfilesdir systemhours systemmode systemtest @@ -2354,6 +2356,7 @@ timername tiocm tios tmp +tmpfiles toolchain topbot tport diff --git a/scripts/systemd/.gitignore b/scripts/systemd/.gitignore index a08b94f5ef..4c06f648e9 100644 --- a/scripts/systemd/.gitignore +++ b/scripts/systemd/.gitignore @@ -1,3 +1,4 @@ +/nut-common.tmpfiles /nut-driver.service /nut-driver@.service /nut-driver.target diff --git a/scripts/systemd/Makefile.am b/scripts/systemd/Makefile.am index c7c7a9f3c9..4e8303828f 100644 --- a/scripts/systemd/Makefile.am +++ b/scripts/systemd/Makefile.am @@ -11,6 +11,9 @@ systemdsystemunit_DATA = \ nut-driver.target \ nut.target +systemdtmpfiles_DATA = \ + nut-common.tmpfiles + EXTRA_DIST += nut-driver.target nut.target systemdshutdown_SCRIPTS = nutshutdown @@ -20,7 +23,8 @@ libexec_SCRIPTS = ../upsdrvsvcctl/nut-driver-enumerator.sh sbin_SCRIPTS = ../upsdrvsvcctl/upsdrvsvcctl else -EXTRA_DIST += nut-driver@.service.in nut-monitor.service.in \ +EXTRA_DIST += \ + nut-common.tmpfiles.in nut-driver@.service.in nut-monitor.service.in \ nut-server.service.in nutshutdown.in nut-driver.target nut.target \ nut-driver-enumerator.path.in nut-driver-enumerator.service.in endif diff --git a/scripts/systemd/nut-common.tmpfiles.in b/scripts/systemd/nut-common.tmpfiles.in new file mode 100644 index 0000000000..e98dfb8893 --- /dev/null +++ b/scripts/systemd/nut-common.tmpfiles.in @@ -0,0 +1,7 @@ +# State file (e.g. upsd to driver) and pidfile location for NUT: +d @runbasedir@/nut 0770 @RUN_AS_USER@ @RUN_AS_GROUP@ - - +X @runbasedir@/nut +d @statepath@/nut 0770 @RUN_AS_USER@ @RUN_AS_GROUP@ - - +X @statepath@/nut +d @pidpath@/nut 0770 @RUN_AS_USER@ @RUN_AS_GROUP@ - - +X @pidpath@/nut From e06bc6fa250cf3330f7ba381f36c2b0a64a14b58 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 28 May 2021 16:58:11 +0200 Subject: [PATCH 2/9] configure.ac: typo fix in comment --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 4277ae26cf..cd61faf16d 100644 --- a/configure.ac +++ b/configure.ac @@ -2023,7 +2023,7 @@ AS_CASE(["${nut_enable_Werror}"], ) AC_MSG_RESULT(["${nut_enable_Werror}"]) -dnl Finally restore warnings setings that the caller might have provided in CFLAGS etc +dnl Finally restore warnings settings that the caller might have provided in CFLAGS etc NUT_POP_WARNINGS AC_OUTPUT([ From 65958072f06f731385c70777776d9ce8546c310b Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 28 May 2021 16:58:35 +0200 Subject: [PATCH 3/9] configure.ac: generate scripts/systemd/nut-common.in based on current config --- autogen.sh | 4 +++ configure.ac | 45 +++++++++++++++++++++++--- scripts/systemd/.gitignore | 2 ++ scripts/systemd/nut-common.tmpfiles.in | 7 ---- 4 files changed, 47 insertions(+), 11 deletions(-) delete mode 100644 scripts/systemd/nut-common.tmpfiles.in diff --git a/autogen.sh b/autogen.sh index 83367f3286..99d8a9bf96 100755 --- a/autogen.sh +++ b/autogen.sh @@ -39,6 +39,10 @@ then fi fi +if [ ! -e scripts/systemd/nut-common.tmpfiles.in ]; then + echo '# autoconf requires this file exists before generating configure script' > scripts/systemd/nut-common.tmpfiles.in +fi + # now we can safely call autoreconf echo "Calling autoreconf..." autoreconf -iv && { diff --git a/configure.ac b/configure.ac index cd61faf16d..1c2d25e2d4 100644 --- a/configure.ac +++ b/configure.ac @@ -1483,14 +1483,27 @@ if test -n "${systemdsystemunitdir}"; then esac fi +dnl Note: if (systemd-)tmpfiles tech is present, it can be useful even for +dnl daemons starting not as systemd units +AC_MSG_CHECKING([whether to install systemd tmpfiles files (${systemdtmpfilesdir})]) AC_ARG_WITH([systemdtmpfilesdir], AS_HELP_STRING([--with-systemdtmpfilesdir=DIR], [Directory for systemd tmpfiles scripts (auto)]), - [systemdtmpfilesdir=${withval}]) -if test -n "${systemdsystemunitdir}"; then - case "${systemdtmpfilesdir}" in + [systemdshutdowndir=${withval}]) +case "${systemdtmpfilesdir}" in yes|auto|"") systemdtmpfilesdir=`$PKG_CONFIG --variable=tmpfilesdir systemd` - esac + ;; + no) + systemdtmpfilesdir="" + ;; + *) + systemdtmpfilesdir="${withval}" + ;; +esac +if test -n "${systemdtmpfilesdir}"; then + AC_MSG_RESULT(using ${systemdtmpfilesdir}) +else + AC_MSG_RESULT(no) fi dnl @@ -2026,6 +2039,30 @@ AC_MSG_RESULT(["${nut_enable_Werror}"]) dnl Finally restore warnings settings that the caller might have provided in CFLAGS etc NUT_POP_WARNINGS +dnl Due to possibly repetitive content, generate unique settings: +AS_IF([test -n "$systemdtmpfilesdir"], + [cat > scripts/systemd/nut-common.tmpfiles.in << EOF +# State file (e.g. upsd to driver) and pidfile location for NUT: +d @STATEPATH@/nut 0770 @RUN_AS_USER@ @RUN_AS_GROUP@ - - +X @STATEPATH@/nut +EOF + AS_IF([test "$STATEPATH" != "$PIDPATH"], + [cat >> scripts/systemd/nut-common.tmpfiles.in << EOF +d @PIDPATH@/nut 0770 @RUN_AS_USER@ @RUN_AS_GROUP@ - - +X @PIDPATH@/nut +EOF]) + AS_IF([test -n "$ALTPIDPATH" && test "$STATEPATH" != "$ALTPIDPATH" && test "$PIDPATH" != "$ALTPIDPATH"], + [cat >> scripts/systemd/nut-common.tmpfiles.in << EOF +d @ALTPIDPATH@/nut 0770 @RUN_AS_USER@ @RUN_AS_GROUP@ - - +X @ALTPIDPATH@/nut +EOF]) + AS_IF([test -n "$ALTSTATEPATH" && test "$STATEPATH" != "$ALTSTATEPATH" && test "$ALTSTATEPATH" != "$ALTPIDPATH" && test "$PIDPATH" != "$ALTSTATEPATH"], + [cat >> scripts/systemd/nut-common.tmpfiles.in << EOF +d @ALTSTATEPATH@/nut 0770 @RUN_AS_USER@ @RUN_AS_GROUP@ - - +X @ALTSTATEPATH@/nut +EOF]) +]) + AC_OUTPUT([ clients/Makefile common/Makefile diff --git a/scripts/systemd/.gitignore b/scripts/systemd/.gitignore index 4c06f648e9..aca233407d 100644 --- a/scripts/systemd/.gitignore +++ b/scripts/systemd/.gitignore @@ -1,3 +1,5 @@ +# Note: nut-common.tmpfiles.in is also generated, by configure script +/nut-common.tmpfiles.in /nut-common.tmpfiles /nut-driver.service /nut-driver@.service diff --git a/scripts/systemd/nut-common.tmpfiles.in b/scripts/systemd/nut-common.tmpfiles.in deleted file mode 100644 index e98dfb8893..0000000000 --- a/scripts/systemd/nut-common.tmpfiles.in +++ /dev/null @@ -1,7 +0,0 @@ -# State file (e.g. upsd to driver) and pidfile location for NUT: -d @runbasedir@/nut 0770 @RUN_AS_USER@ @RUN_AS_GROUP@ - - -X @runbasedir@/nut -d @statepath@/nut 0770 @RUN_AS_USER@ @RUN_AS_GROUP@ - - -X @statepath@/nut -d @pidpath@/nut 0770 @RUN_AS_USER@ @RUN_AS_GROUP@ - - -X @pidpath@/nut From e38750284d9b5e45e2d0261fbec6c22f4cfee9c2 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 28 May 2021 17:31:54 +0200 Subject: [PATCH 4/9] configure.ac: improve reporting of systemd options processing --- configure.ac | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 1c2d25e2d4..c5f6c60009 100644 --- a/configure.ac +++ b/configure.ac @@ -1447,7 +1447,7 @@ fi AC_MSG_RESULT([${solarispkg_ips}]) AM_CONDITIONAL(WITH_SOLARIS_PKG_IPS, test x"$solarispkg_ips" = x"yes") -AC_MSG_CHECKING(whether to install systemd files) +AC_MSG_CHECKING(whether to install systemd unit files) AC_ARG_WITH([systemdsystemunitdir], AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files (auto)]), [ @@ -1473,6 +1473,7 @@ dnl This option is only provided so that make distcheck can override it, dnl otherwise we ask pkg-config whenever --with-systemdsystemunitdir is dnl given +AC_MSG_CHECKING(whether to install systemd shutdown files) AC_ARG_WITH([systemdshutdowndir], AS_HELP_STRING([--with-systemdshutdowndir=DIR], [Directory for systemd shutdown scripts (auto)]), [systemdshutdowndir=${withval}]) @@ -1482,6 +1483,11 @@ if test -n "${systemdsystemunitdir}"; then systemdshutdowndir=`$PKG_CONFIG --variable=systemdshutdowndir systemd` esac fi +if test -n "${systemdshutdowndir}"; then + AC_MSG_RESULT(using ${systemdshutdowndir}) +else + AC_MSG_RESULT(no) +fi dnl Note: if (systemd-)tmpfiles tech is present, it can be useful even for dnl daemons starting not as systemd units From a7833c68c871c2e47b423d087c8d72c391c41672 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 30 May 2021 17:19:55 +0200 Subject: [PATCH 5/9] configure.ac: update comments for systemd related options --- configure.ac | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/configure.ac b/configure.ac index c5f6c60009..c58c9154a7 100644 --- a/configure.ac +++ b/configure.ac @@ -1447,6 +1447,11 @@ fi AC_MSG_RESULT([${solarispkg_ips}]) AM_CONDITIONAL(WITH_SOLARIS_PKG_IPS, test x"$solarispkg_ips" = x"yes") +dnl Note: Currently there is no automatic detection enabled - +dnl users have to ask they want systemd units installed. +dnl It may be changed based on popular demand to just always +dnl run the "case" below for ${systemdsystemunitdir} values, +dnl like we do for systemdtmpfilesdir further below. AC_MSG_CHECKING(whether to install systemd unit files) AC_ARG_WITH([systemdsystemunitdir], AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files (auto)]), @@ -1477,6 +1482,7 @@ AC_MSG_CHECKING(whether to install systemd shutdown files) AC_ARG_WITH([systemdshutdowndir], AS_HELP_STRING([--with-systemdshutdowndir=DIR], [Directory for systemd shutdown scripts (auto)]), [systemdshutdowndir=${withval}]) +dnl Note: this option is enabled only if systemdsystemunitdir is not trivial if test -n "${systemdsystemunitdir}"; then case "${systemdshutdowndir}" in yes|auto|"") From 0cb697cae6629f9fed27319f7e1b0586fd5d5bc3 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 30 May 2021 17:20:47 +0200 Subject: [PATCH 6/9] configure.ac: just in case, double-quote to single-tokenize detected systemd related options --- configure.ac | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index c58c9154a7..de05def066 100644 --- a/configure.ac +++ b/configure.ac @@ -1458,7 +1458,7 @@ AC_ARG_WITH([systemdsystemunitdir], [ case "${withval}" in yes|auto|"") - systemdsystemunitdir=`$PKG_CONFIG --variable=systemdsystemunitdir systemd` + systemdsystemunitdir="`$PKG_CONFIG --variable=systemdsystemunitdir systemd`" ;; no) systemdsystemunitdir="" @@ -1486,7 +1486,7 @@ dnl Note: this option is enabled only if systemdsystemunitdir is not trivial if test -n "${systemdsystemunitdir}"; then case "${systemdshutdowndir}" in yes|auto|"") - systemdshutdowndir=`$PKG_CONFIG --variable=systemdshutdowndir systemd` + systemdshutdowndir="`$PKG_CONFIG --variable=systemdshutdowndir systemd`" esac fi if test -n "${systemdshutdowndir}"; then @@ -1503,7 +1503,7 @@ AC_ARG_WITH([systemdtmpfilesdir], [systemdshutdowndir=${withval}]) case "${systemdtmpfilesdir}" in yes|auto|"") - systemdtmpfilesdir=`$PKG_CONFIG --variable=tmpfilesdir systemd` + systemdtmpfilesdir="`$PKG_CONFIG --variable=tmpfilesdir systemd`" ;; no) systemdtmpfilesdir="" From fee464c0430d69e7dac0a3fdbe4ce3bcff1dbbe8 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 30 May 2021 17:21:27 +0200 Subject: [PATCH 7/9] configure.ac: process other values for systemdshutdowndir option --- configure.ac | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/configure.ac b/configure.ac index de05def066..ca09b55404 100644 --- a/configure.ac +++ b/configure.ac @@ -1487,6 +1487,13 @@ if test -n "${systemdsystemunitdir}"; then case "${systemdshutdowndir}" in yes|auto|"") systemdshutdowndir="`$PKG_CONFIG --variable=systemdshutdowndir systemd`" + ;; + no) + systemdshutdowndir="" + ;; + *) + systemdshutdowndir="${withval}" + ;; esac fi if test -n "${systemdshutdowndir}"; then From 6069eaa763231117a096b5d8630e2c11bf5a0df5 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 30 May 2021 17:21:48 +0200 Subject: [PATCH 8/9] configure.ac: do not make noise with yet empty systemdtmpfilesdir --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index ca09b55404..4928419e0d 100644 --- a/configure.ac +++ b/configure.ac @@ -1504,7 +1504,7 @@ fi dnl Note: if (systemd-)tmpfiles tech is present, it can be useful even for dnl daemons starting not as systemd units -AC_MSG_CHECKING([whether to install systemd tmpfiles files (${systemdtmpfilesdir})]) +AC_MSG_CHECKING([whether to install systemd tmpfiles files]) AC_ARG_WITH([systemdtmpfilesdir], AS_HELP_STRING([--with-systemdtmpfilesdir=DIR], [Directory for systemd tmpfiles scripts (auto)]), [systemdshutdowndir=${withval}]) From 21d3e23bd4f1bb4ec6d31b3dfcce3cfea11631e0 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 30 May 2021 17:22:18 +0200 Subject: [PATCH 9/9] configure.ac: bugfix - populate systemdtmpfilesdir in its option, not systemdshutdowndir --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 4928419e0d..fd64c90d06 100644 --- a/configure.ac +++ b/configure.ac @@ -1507,7 +1507,7 @@ dnl daemons starting not as systemd units AC_MSG_CHECKING([whether to install systemd tmpfiles files]) AC_ARG_WITH([systemdtmpfilesdir], AS_HELP_STRING([--with-systemdtmpfilesdir=DIR], [Directory for systemd tmpfiles scripts (auto)]), - [systemdshutdowndir=${withval}]) + [systemdtmpfilesdir=${withval}]) case "${systemdtmpfilesdir}" in yes|auto|"") systemdtmpfilesdir="`$PKG_CONFIG --variable=tmpfilesdir systemd`"