From dfffd24a1f9441ca55c176b59f7bde80c0f03341 Mon Sep 17 00:00:00 2001 From: Michal Hrusecky Date: Fri, 21 Aug 2015 10:41:14 +0200 Subject: [PATCH 001/165] Use target for drivers in systemd This allows much better granularity and better monitoring in case of multiple UPSes. --- configure.ac | 2 +- scripts/systemd/Makefile.am | 9 +++++---- scripts/systemd/nut-driver.service.in | 10 ---------- scripts/systemd/nut-driver.target | 3 +++ scripts/systemd/nut-driver@.service.in | 12 ++++++++++++ scripts/systemd/nut-server.service.in | 4 ++-- 6 files changed, 23 insertions(+), 17 deletions(-) delete mode 100644 scripts/systemd/nut-driver.service.in create mode 100644 scripts/systemd/nut-driver.target create mode 100644 scripts/systemd/nut-driver@.service.in diff --git a/configure.ac b/configure.ac index 93a2d33dba..1f86456a21 100644 --- a/configure.ac +++ b/configure.ac @@ -1634,7 +1634,7 @@ AC_OUTPUT([ scripts/HP-UX/postinstall scripts/python/Makefile scripts/systemd/Makefile - scripts/systemd/nut-driver.service + scripts/systemd/nut-driver@.service scripts/systemd/nut-monitor.service scripts/systemd/nut-server.service scripts/systemd/nutshutdown diff --git a/scripts/systemd/Makefile.am b/scripts/systemd/Makefile.am index 72e9a1c0cd..34d2264de7 100644 --- a/scripts/systemd/Makefile.am +++ b/scripts/systemd/Makefile.am @@ -3,14 +3,15 @@ EXTRA_DIST = README if HAVE_SYSTEMD systemdsystemunit_DATA = \ - nut-driver.service \ + nut-driver@.service \ nut-monitor.service \ - nut-server.service + nut-server.service \ + nut-driver.target systemdshutdown_SCRIPTS = nutshutdown else -EXTRA_DIST += nut-driver.service.in nut-monitor.service.in \ - nut-server.service.in nutshutdown.in +EXTRA_DIST += nut-driver@.service.in nut-monitor.service.in \ + nut-server.service.in nutshutdown.in nut-driver.target endif diff --git a/scripts/systemd/nut-driver.service.in b/scripts/systemd/nut-driver.service.in deleted file mode 100644 index f81ac6996f..0000000000 --- a/scripts/systemd/nut-driver.service.in +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Network UPS Tools - power device driver controller -After=local-fs.target network.target -StopWhenUnneeded=yes - -[Service] -ExecStart=@SBINDIR@/upsdrvctl start -ExecStop=@SBINDIR@/upsdrvctl stop -Type=forking - diff --git a/scripts/systemd/nut-driver.target b/scripts/systemd/nut-driver.target new file mode 100644 index 0000000000..b743f5ced7 --- /dev/null +++ b/scripts/systemd/nut-driver.target @@ -0,0 +1,3 @@ +[Unit] +Description=Network UPS Tools - power device driver controller +After=local-fs.target network.target diff --git a/scripts/systemd/nut-driver@.service.in b/scripts/systemd/nut-driver@.service.in new file mode 100644 index 0000000000..b3533ac469 --- /dev/null +++ b/scripts/systemd/nut-driver@.service.in @@ -0,0 +1,12 @@ +[Unit] +Description=Network UPS Tools - device driver for %I +After=local-fs.target network.target +PartOf=nut-driver.target + +[Service] +ExecStart=@SBINDIR@/upsdrvctl start %i +ExecStop=@SBINDIR@/upsdrvctl stop %i +Type=forking + +[Install] +WantedBy=multi-user.target nut-driver.target diff --git a/scripts/systemd/nut-server.service.in b/scripts/systemd/nut-server.service.in index 7a786701f8..ed6a454218 100644 --- a/scripts/systemd/nut-server.service.in +++ b/scripts/systemd/nut-server.service.in @@ -1,10 +1,10 @@ [Unit] Description=Network UPS Tools - power devices information server -After=local-fs.target network.target nut-driver.service +After=local-fs.target network.target nut-driver.target # We don't Require drivers to be successfully started! This would be # a change of behavior compared to init SysV, and could prevent from # accessing successfully started, at least to audit a system. -Wants=nut-driver.service +Wants=nut-driver.target Before=nut-monitor.service [Service] From 746d2a09303b14b89e492829c3392d1267981a6f Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 10 Oct 2016 14:25:50 +0200 Subject: [PATCH 002/165] nut-driver.target improvements suggested by @peterhoeg in PR#229 --- scripts/systemd/nut-driver.target | 3 +++ scripts/systemd/nut-driver@.service.in | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/systemd/nut-driver.target b/scripts/systemd/nut-driver.target index b743f5ced7..2679a7f088 100644 --- a/scripts/systemd/nut-driver.target +++ b/scripts/systemd/nut-driver.target @@ -1,3 +1,6 @@ [Unit] Description=Network UPS Tools - power device driver controller After=local-fs.target network.target + +[Install] +WantedBy=multi-user.target diff --git a/scripts/systemd/nut-driver@.service.in b/scripts/systemd/nut-driver@.service.in index b3533ac469..65acc3b523 100644 --- a/scripts/systemd/nut-driver@.service.in +++ b/scripts/systemd/nut-driver@.service.in @@ -9,4 +9,4 @@ ExecStop=@SBINDIR@/upsdrvctl stop %i Type=forking [Install] -WantedBy=multi-user.target nut-driver.target +WantedBy=nut-driver.target From b1f3d2491b7f0c5691ab4aa5ca5e398aa4688c1c Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 10 Oct 2016 14:28:19 +0200 Subject: [PATCH 003/165] systemd units dependencies revised and commented --- scripts/systemd/nut-driver@.service.in | 11 +++++++++++ scripts/systemd/nut-monitor.service.in | 6 ++++++ scripts/systemd/nut-server.service.in | 3 +++ 3 files changed, 20 insertions(+) diff --git a/scripts/systemd/nut-driver@.service.in b/scripts/systemd/nut-driver@.service.in index 65acc3b523..0b2f65ea4a 100644 --- a/scripts/systemd/nut-driver@.service.in +++ b/scripts/systemd/nut-driver@.service.in @@ -2,6 +2,17 @@ Description=Network UPS Tools - device driver for %I After=local-fs.target network.target PartOf=nut-driver.target +# Note: The choice of "network.target" allows to schedule this unit +# roughly when the network stack of this OS is ready (e.g. that the +# subsequent `upsd` will have a `0.0.0.0` or a `localhost` to bind +# to); however this target does not ensure availability of a real +# connection or final IP addresses. Drivers that require network as +# a media for interaction with UPSes (snmp-ups, netxml-ups, ipmi etc.) +# may want a clone of this unit with `Requires=network-online.target` +# instead. Also note that *generally* this should not be a problem, +# since the drivers have a few retries with timeouts during startup, +# and typically by the time the box gets an IP address, the driver +# is still retrying to start and will succeed. [Service] ExecStart=@SBINDIR@/upsdrvctl start %i diff --git a/scripts/systemd/nut-monitor.service.in b/scripts/systemd/nut-monitor.service.in index 8429bf280c..f3840256d6 100644 --- a/scripts/systemd/nut-monitor.service.in +++ b/scripts/systemd/nut-monitor.service.in @@ -1,6 +1,12 @@ [Unit] Description=Network UPS Tools - power device monitor and shutdown controller After=local-fs.target network.target nut-server.service +# Note: We do not specify Requires nut-server.service because +# the `upsd` daemon(s) may be running on a different machine +# (connected to the UPSes) than the `upsmon` shutdown protector. +# The "Wants" directive would try to start the nut-server but +# would not abort if that attempt fails for whatever reason. +Wants=nut-server.service [Service] ExecStart=@SBINDIR@/upsmon diff --git a/scripts/systemd/nut-server.service.in b/scripts/systemd/nut-server.service.in index ed6a454218..dd1e88931a 100644 --- a/scripts/systemd/nut-server.service.in +++ b/scripts/systemd/nut-server.service.in @@ -5,6 +5,9 @@ After=local-fs.target network.target nut-driver.target # a change of behavior compared to init SysV, and could prevent from # accessing successfully started, at least to audit a system. Wants=nut-driver.target +# The `upsd` is a networked service (even if bound to a `localhost`) +# so it requres that the OS has some notion of networking already. +Requires=network.target Before=nut-monitor.service [Service] From ef6fb0f5c22dc43efb65b37f8a773d5037bb477b Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 10 Oct 2016 16:27:22 +0200 Subject: [PATCH 004/165] nut-driver-enumerator.sh initial commit --- scripts/systemd/nut-driver-enumerator.sh | 139 +++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100755 scripts/systemd/nut-driver-enumerator.sh diff --git a/scripts/systemd/nut-driver-enumerator.sh b/scripts/systemd/nut-driver-enumerator.sh new file mode 100755 index 0000000000..ec644469f8 --- /dev/null +++ b/scripts/systemd/nut-driver-enumerator.sh @@ -0,0 +1,139 @@ +#!/bin/sh + +# This script allows to enumerate UPSes in order to produce the +# individual service unit instances for each defined configuration. +# It assumes the user has adequate permissions to inspect and create +# services (e.g. is a root or has proper RBAC profiles to do so). +# TODO: Complete the sample basic support for Solaris SMF (needs the +# service definitions similar to systemd NUT units to be added first). +# +# \Author: Jim Klimov + +[ -z "${UPSCONF-}" ] && \ + UPSCONF="@sysconfdir@/ups.conf" + +if [ -z "${SERVICE_FRAMEWORK-}" ] ; then + [ -x /usr/sbin/svcadm ] && [ -x /usr/sbin/svccfg ] && [ -x /usr/bin/svcs ] && \ + SERVICE_FRAMEWORK="smf" + [ -z "${SERVICE_FRAMEWORK-}" ] && \ + [ -x /bin/systemctl ] && \ + SERVICE_FRAMEWORK="systemd" +fi + +# List of configured UPSes in the config-file +UPSLIST_FILE="" +# List of configured service instances for UPS drivers +UPSLIST_SVCS="" +hook_registerInstance="" +hook_unregisterInstance="" +hook_listInstances="" + +case "${SERVICE_FRAMEWORK-}" in + smf) + hook_registerInstance="smf_registerInstance" + hook_unregisterInstance="smf_unregisterInstance" + hook_listInstances="smf_listInstances" + ;; + systemd) + hook_registerInstance="systemd_registerInstance" + hook_unregisterInstance="systemd_unregisterInstance" + hook_listInstances="systemd_listInstances" + ;; + "") + echo "Error detecting the service-management framework on this OS" >&2 + exit 1 + ;; + *) + echo "Error: User provided an unknown service-management framework '$SERVICE_FRAMEWORK'" >&2 + exit 1 + ;; +esac + +common_isFiled() { + [ -n "$UPSLIST_FILE" ] && \ + for UPSF in $UPSLIST_FILE ; do + [ "$1" = "$UPSF" ] && return 0 + done + return 1 +} + +common_isRegistered() { + [ -n "$UPSLIST_SVCS" ] && \ + for UPSS in $UPSLIST_SVCS ; do + [ "$1" = "$UPSS" ] && return 0 + done + return 1 +} + +smf_registerInstance() { + echo "Solaris SMF support was recognized but currently is not implemented" >&2 +} +smf_unregisterInstance() { + echo "Solaris SMF support was recognized but currently is not implemented" >&2 +} +smf_listInstances() { + /usr/bin/svcs -a -H -o fmri | egrep '/nut-driver:' | sed 's/^.*://' | sort -n +} + +systemd_registerInstance() { + /bin/systemctl enable 'nut-driver@'"$1" +} +systemd_unregisterInstance() { + /bin/systemctl stop 'nut-driver@'"$1" || false + /bin/systemctl disable 'nut-driver@'"$1" +} +systemd_listInstances() { + /bin/systemctl show 'nut-driver@*' -p Id | egrep '=nut-driver' | sed -e 's/^.*@//' -e 's/\.service$//' | sort -n +} + +################# MAIN PROGRAM + +if [ -s "$UPSCONF" ] ; then + UPSLIST_FILE="`egrep '^[ \t]*\[.*\][ \t]*$' "$UPSCONF" | sed 's,^[ \t]*\[\(.*\)\][ \t]*$,\1,' | sort -n`" || UPSLIST_FILE="" + if [ -z "$UPSLIST_FILE" ] ; then + echo "Error reading the '$UPSCONF' file or it does not declare any device configurations" >&2 + fi +else + echo "The '$UPSCONF' file does not exist or is empty" >&2 +fi + +UPSLIST_SVCS="`$hook_listInstances`" || UPSLIST_SVCS="" +if [ -z "$UPSLIST_SVCS" ] ; then + echo "Error reading the list of service instances for UPS drivers, or none are defined" >&2 +fi + +if [ -n "$UPSLIST_FILE" ]; then + for UPSF in $UPSLIST_FILE ; do + if ! common_isRegistered "$UPSF" ; then + echo "Adding new ${SERVICE_FRAMEWORK} service instance for power device [${UPSF}]..." >&2 + $hook_registerInstance "$UPSF" + fi + done + + UPSLIST_SVCS="`$hook_listInstances`" || UPSLIST_SVCS="" + if [ -z "$UPSLIST_SVCS" ] ; then + echo "Error reading the list of service instances for UPS drivers, or none are defined" >&2 + fi +fi + +if [ -n "$UPSLIST_SVCS" ]; then + for UPSS in $UPSLIST_SVCS ; do + if ! common_isFiled "$UPSS" ; then + echo "Dropping old ${SERVICE_FRAMEWORK} service instance for power device [${UPSS}] which is no longer in config file..." >&2 + $hook_unregisterInstance "$UPSS" + fi + done +fi + +UPSLIST_SVCS="`$hook_listInstances`" || UPSLIST_SVCS="" +if [ -n "$UPSLIST_SVCS" ] ; then + echo "=== The currently defined service instances are:" + echo "$UPSLIST_SVCS" +else + echo "Error reading the list of service instances for UPS drivers, or none are defined" >&2 +fi + +if [ -n "$UPSLIST_FILE" ] ; then + echo "=== The currently defined configurations in '$UPSCONF' are:" + echo "$UPSLIST_FILE" +fi From 53f562632bd0034cded2263e5a7d4238dffa37ee Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 11 Oct 2016 11:05:12 +0200 Subject: [PATCH 005/165] nut-driver@.service.in : integrate comments from @peterhoeg about extending unit requirements --- scripts/systemd/nut-driver@.service.in | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/systemd/nut-driver@.service.in b/scripts/systemd/nut-driver@.service.in index 0b2f65ea4a..4446ce92ff 100644 --- a/scripts/systemd/nut-driver@.service.in +++ b/scripts/systemd/nut-driver@.service.in @@ -8,11 +8,20 @@ PartOf=nut-driver.target # to); however this target does not ensure availability of a real # connection or final IP addresses. Drivers that require network as # a media for interaction with UPSes (snmp-ups, netxml-ups, ipmi etc.) -# may want a clone of this unit with `Requires=network-online.target` +# may want to extend this unit with `Requires=network-online.target` # instead. Also note that *generally* this should not be a problem, # since the drivers have a few retries with timeouts during startup, # and typically by the time the box gets an IP address, the driver # is still retrying to start and will succeed. +# Extending the unit does not require *this* file to be edited, you +# can instead drop in an additional piece of configuration, e.g. add +# a `/etc/systemd/system/nut-driver@.service.d/network.conf` with: +# [Unit] +# Requires=network-online.target +# After=network-online.target +# If your `upsd` requires specific IP addresses to be available before +# starting, a `/etc/systemd/system/nut-driver.target.d/network.conf` +# can be used in a similar manner. [Service] ExecStart=@SBINDIR@/upsdrvctl start %i From 47538873f08f71568fb23abbf82de03acfab7ce3 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 11 Oct 2016 12:43:19 +0200 Subject: [PATCH 006/165] WIP : initial integration of nut-driver-enumerator.sh/service into makefiles etc. --- configure.ac | 1 + scripts/systemd/Makefile.am | 6 ++++- .../systemd/nut-driver-enumerator.service.in | 7 ++++++ scripts/systemd/nut-driver-enumerator.sh | 23 ++++++++++++++++--- 4 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 scripts/systemd/nut-driver-enumerator.service.in diff --git a/configure.ac b/configure.ac index 1f86456a21..99b65d23c5 100644 --- a/configure.ac +++ b/configure.ac @@ -1637,6 +1637,7 @@ AC_OUTPUT([ scripts/systemd/nut-driver@.service scripts/systemd/nut-monitor.service scripts/systemd/nut-server.service + scripts/systemd/nut-driver-enumerator.service scripts/systemd/nutshutdown scripts/Solaris/Makefile scripts/Solaris/pkginfo diff --git a/scripts/systemd/Makefile.am b/scripts/systemd/Makefile.am index 34d2264de7..6cd0ed21a7 100644 --- a/scripts/systemd/Makefile.am +++ b/scripts/systemd/Makefile.am @@ -3,6 +3,7 @@ EXTRA_DIST = README if HAVE_SYSTEMD systemdsystemunit_DATA = \ + nut-driver-enumerator.service \ nut-driver@.service \ nut-monitor.service \ nut-server.service \ @@ -10,8 +11,11 @@ systemdsystemunit_DATA = \ systemdshutdown_SCRIPTS = nutshutdown +libexec_SCRIPTS = nut-driver-enumerator.sh + else EXTRA_DIST += nut-driver@.service.in nut-monitor.service.in \ - nut-server.service.in nutshutdown.in nut-driver.target + nut-server.service.in nutshutdown.in nut-driver.target \ + nut-driver-enumerator.sh nut-driver-enumerator.service.in endif diff --git a/scripts/systemd/nut-driver-enumerator.service.in b/scripts/systemd/nut-driver-enumerator.service.in new file mode 100644 index 0000000000..233b45c536 --- /dev/null +++ b/scripts/systemd/nut-driver-enumerator.service.in @@ -0,0 +1,7 @@ +[Unit] +Description=Network UPS Tools - enumeration of configure-file devices into systemd unit instances +After=local-fs.target +Before=nut-driver.target + +[Install] +WantedBy=multi-user.target diff --git a/scripts/systemd/nut-driver-enumerator.sh b/scripts/systemd/nut-driver-enumerator.sh index ec644469f8..374e8ac9c8 100755 --- a/scripts/systemd/nut-driver-enumerator.sh +++ b/scripts/systemd/nut-driver-enumerator.sh @@ -12,6 +12,9 @@ [ -z "${UPSCONF-}" ] && \ UPSCONF="@sysconfdir@/ups.conf" +# Start a freshly-registered unit? +[ -z "${AUTO_START-}" ] && AUTO_START=yes + if [ -z "${SERVICE_FRAMEWORK-}" ] ; then [ -x /usr/sbin/svcadm ] && [ -x /usr/sbin/svccfg ] && [ -x /usr/bin/svcs ] && \ SERVICE_FRAMEWORK="smf" @@ -76,7 +79,10 @@ smf_listInstances() { } systemd_registerInstance() { - /bin/systemctl enable 'nut-driver@'"$1" + /bin/systemctl enable 'nut-driver@'"$1" || return + if [ "$AUTO_START" = yes ] ; then + /bin/systemctl start --no-block 'nut-driver@'"$1" || return + fi } systemd_unregisterInstance() { /bin/systemctl stop 'nut-driver@'"$1" || false @@ -88,13 +94,15 @@ systemd_listInstances() { ################# MAIN PROGRAM -if [ -s "$UPSCONF" ] ; then +if [ -f "$UPSCONF" ] ; then + [ -s "$UPSCONF" ] && \ UPSLIST_FILE="`egrep '^[ \t]*\[.*\][ \t]*$' "$UPSCONF" | sed 's,^[ \t]*\[\(.*\)\][ \t]*$,\1,' | sort -n`" || UPSLIST_FILE="" if [ -z "$UPSLIST_FILE" ] ; then echo "Error reading the '$UPSCONF' file or it does not declare any device configurations" >&2 fi else - echo "The '$UPSCONF' file does not exist or is empty" >&2 + echo "FATAL: The '$UPSCONF' file does not exist" >&2 + exit 2 fi UPSLIST_SVCS="`$hook_listInstances`" || UPSLIST_SVCS="" @@ -102,6 +110,10 @@ if [ -z "$UPSLIST_SVCS" ] ; then echo "Error reading the list of service instances for UPS drivers, or none are defined" >&2 fi +# Quickly exit if there's nothing to do; note the lists are pre-sorted +# Otherwise a non-zero exit will be done below +[ "$UPSLIST_FILE" = "$UPSLIST_SVCS" ] && exit 0 + if [ -n "$UPSLIST_FILE" ]; then for UPSF in $UPSLIST_FILE ; do if ! common_isRegistered "$UPSF" ; then @@ -137,3 +149,8 @@ if [ -n "$UPSLIST_FILE" ] ; then echo "=== The currently defined configurations in '$UPSCONF' are:" echo "$UPSLIST_FILE" fi + +# Return 42 if there was a change applied succesfully +# (but e.g. some services should restart) +[ "$UPSLIST_FILE" = "$UPSLIST_SVCS" ] && return 42 +exit 13 From 16cab584f9ca4bba72c64c3b20844f682205710a Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 28 Oct 2016 10:36:57 +0200 Subject: [PATCH 007/165] nut-driver-enumerator.sh renamed into nut-driver-enumerator.sh.in as it has processable templates in code --- configure.ac | 1 + scripts/systemd/Makefile.am | 2 +- .../{nut-driver-enumerator.sh => nut-driver-enumerator.sh.in} | 0 3 files changed, 2 insertions(+), 1 deletion(-) rename scripts/systemd/{nut-driver-enumerator.sh => nut-driver-enumerator.sh.in} (100%) diff --git a/configure.ac b/configure.ac index 99b65d23c5..3679bc4f64 100644 --- a/configure.ac +++ b/configure.ac @@ -1638,6 +1638,7 @@ AC_OUTPUT([ scripts/systemd/nut-monitor.service scripts/systemd/nut-server.service scripts/systemd/nut-driver-enumerator.service + scripts/systemd/nut-driver-enumerator.sh scripts/systemd/nutshutdown scripts/Solaris/Makefile scripts/Solaris/pkginfo diff --git a/scripts/systemd/Makefile.am b/scripts/systemd/Makefile.am index 6cd0ed21a7..1bda14d2ca 100644 --- a/scripts/systemd/Makefile.am +++ b/scripts/systemd/Makefile.am @@ -16,6 +16,6 @@ libexec_SCRIPTS = nut-driver-enumerator.sh else EXTRA_DIST += nut-driver@.service.in nut-monitor.service.in \ nut-server.service.in nutshutdown.in nut-driver.target \ - nut-driver-enumerator.sh nut-driver-enumerator.service.in + nut-driver-enumerator.sh.in nut-driver-enumerator.service.in endif diff --git a/scripts/systemd/nut-driver-enumerator.sh b/scripts/systemd/nut-driver-enumerator.sh.in similarity index 100% rename from scripts/systemd/nut-driver-enumerator.sh rename to scripts/systemd/nut-driver-enumerator.sh.in From 08a6511315106a97d35ad27940b1d4e07770b545 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 28 Oct 2016 10:38:31 +0200 Subject: [PATCH 008/165] nut-driver-enumerator.sh.in : add its own config-file support to set the variables used inside (if not via command-line env) --- scripts/systemd/nut-driver-enumerator.sh.in | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index 374e8ac9c8..0f3e310a6a 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -9,6 +9,13 @@ # # \Author: Jim Klimov +[ -z "${NUT_DRIVER_ENUMERATOR_CONF-}" ] && \ + NUT_DRIVER_ENUMERATOR_CONF="@sysconfdir@/nut-driver-enumerator.conf" + +[ -s "${NUT_DRIVER_ENUMERATOR_CONF}" ] && \ + echo "Sourcing config file: ${NUT_DRIVER_ENUMERATOR_CONF}" && \ + . "${NUT_DRIVER_ENUMERATOR_CONF}" + [ -z "${UPSCONF-}" ] && \ UPSCONF="@sysconfdir@/ups.conf" From 879a045f296ee5ef9ce46a518d5bb9abb855d6b0 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 28 Oct 2016 10:38:49 +0200 Subject: [PATCH 009/165] nut-driver-enumerator.sh.in : fix up the copyright header --- scripts/systemd/nut-driver-enumerator.sh.in | 35 ++++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index 0f3e310a6a..a941100c47 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -1,13 +1,32 @@ #!/bin/sh - -# This script allows to enumerate UPSes in order to produce the -# individual service unit instances for each defined configuration. -# It assumes the user has adequate permissions to inspect and create -# services (e.g. is a root or has proper RBAC profiles to do so). -# TODO: Complete the sample basic support for Solaris SMF (needs the -# service definitions similar to systemd NUT units to be added first). # -# \Author: Jim Klimov +# Copyright (C) 2016 Eaton +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +#! \file nut-driver-enumerator.sh(.in) +# \author Jim Klimov +# \brief Enumerate NUT devices for service-unit instance configuration +# \details This script allows to enumerate UPSes in order to produce the +# individual service unit instances for each defined configuration. +# It assumes the user has adequate permissions to inspect and create +# services (e.g. is a root or has proper RBAC profiles to do so). +# \todo Complete the sample basic support for Solaris SMF (needs support +# for the service definitions similar to systemd NUT units to be +# added to that platform first). +# [ -z "${NUT_DRIVER_ENUMERATOR_CONF-}" ] && \ NUT_DRIVER_ENUMERATOR_CONF="@sysconfdir@/nut-driver-enumerator.conf" From 9cbb9a38802ea6926e747b7b79cc2f1e604c8939 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sat, 28 Jan 2017 02:24:30 +0100 Subject: [PATCH 010/165] Subject: Fix systemd service file for Debian From: Laurent Bigonville Forwarded: not-needed --- scripts/systemd/nut-driver@.service.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/systemd/nut-driver@.service.in b/scripts/systemd/nut-driver@.service.in index 4446ce92ff..444025ec05 100644 --- a/scripts/systemd/nut-driver@.service.in +++ b/scripts/systemd/nut-driver@.service.in @@ -1,6 +1,7 @@ [Unit] Description=Network UPS Tools - device driver for %I -After=local-fs.target network.target +After=local-fs.target network.target systemd-udev-settle.service +Wants=systemd-udev-settle.service PartOf=nut-driver.target # Note: The choice of "network.target" allows to schedule this unit # roughly when the network stack of this OS is ready (e.g. that the From 7bfb48bcace8d152efbfd29cb5d6e50f0a04cacc Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 1 Feb 2017 00:07:43 +0100 Subject: [PATCH 011/165] nut-driver-enumerator.sh.in : complete the Solaris SMF support in the helper script --- scripts/systemd/nut-driver-enumerator.sh.in | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index a941100c47..405e6a85a2 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (C) 2016 Eaton +# Copyright (C) 2016-2017 Eaton # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -23,9 +23,10 @@ # individual service unit instances for each defined configuration. # It assumes the user has adequate permissions to inspect and create # services (e.g. is a root or has proper RBAC profiles to do so). +# It helps service frameworks such as Linux systemd and Solaris SMF. # \todo Complete the sample basic support for Solaris SMF (needs support # for the service definitions similar to systemd NUT units to be -# added to that platform first). +# added to that platform first). Parts in this script are finished. # [ -z "${NUT_DRIVER_ENUMERATOR_CONF-}" ] && \ @@ -95,12 +96,18 @@ common_isRegistered() { } smf_registerInstance() { - echo "Solaris SMF support was recognized but currently is not implemented" >&2 + /usr/sbin/svccfg -s nut-driver add "$1" || return + /usr/sbin/svcadm refresh 'nut-driver@'"$1" || return + if [ "$AUTO_START" = yes ] ; then + /usr/sbin/svcadm enable 'nut-driver@'"$1" || return + fi } smf_unregisterInstance() { - echo "Solaris SMF support was recognized but currently is not implemented" >&2 + /usr/sbin/svcadm disable -ts 'nut-driver@'"$1" || false + /usr/sbin/svccfg -s nut-driver delete "$1" } smf_listInstances() { + # Newer versions have pattern matching; older SMF might not have this luxury /usr/bin/svcs -a -H -o fmri | egrep '/nut-driver:' | sed 's/^.*://' | sort -n } From e4d559dae1ee4f89b5bef2a56dea66c11b5b23c7 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 15 Feb 2017 15:39:52 +0100 Subject: [PATCH 012/165] EXTRA_DIST the scripts/systemd/nut-driver.target (non-templated) file --- scripts/systemd/Makefile.am | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/systemd/Makefile.am b/scripts/systemd/Makefile.am index 1bda14d2ca..af33e146e5 100644 --- a/scripts/systemd/Makefile.am +++ b/scripts/systemd/Makefile.am @@ -9,6 +9,8 @@ systemdsystemunit_DATA = \ nut-server.service \ nut-driver.target +EXTRA_DIST += nut-driver.target + systemdshutdown_SCRIPTS = nutshutdown libexec_SCRIPTS = nut-driver-enumerator.sh From 176f79dd6907a1108d515d8eb6d0aeb1b52cc247 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sat, 4 Mar 2017 16:07:45 +0100 Subject: [PATCH 013/165] nut-driver-enumerator.sh.in : updated comments (esp. about usage and exit-codes) and runtime messages --- scripts/systemd/nut-driver-enumerator.sh.in | 35 ++++++++++++++++----- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index 405e6a85a2..caffbc96e6 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -24,20 +24,36 @@ # It assumes the user has adequate permissions to inspect and create # services (e.g. is a root or has proper RBAC profiles to do so). # It helps service frameworks such as Linux systemd and Solaris SMF. +# When executed, this script looks for all configured ups.conf +# sections and registered service instances, and makes these two +# lists match up. No arguments ATM. Returns exit codes: +# 0 Sections and services already match up +# 42 Sections and services differed, but now match up - +# now the caller should likely restart some services. +# Note that the drivers' service instances were started or +# stopped as required (by AUTO_START=yes) - but maybe the +# upsd or upsmon services should restart. +# 13 Sections and services differed, and still do not match up +# 1 Bad inputs, e.g. unrecognized service management framework +# 2 Absent or unreadable ups.conf file # \todo Complete the sample basic support for Solaris SMF (needs support # for the service definitions similar to systemd NUT units to be # added to that platform first). Parts in this script are finished. # +# Directory where NUT configs are located, e.g. /etc/nut or /etc/ups +# Set at package configuration, compiled into daemons and drivers +NUT_CONF_DIR="@sysconfdir@" + [ -z "${NUT_DRIVER_ENUMERATOR_CONF-}" ] && \ - NUT_DRIVER_ENUMERATOR_CONF="@sysconfdir@/nut-driver-enumerator.conf" + NUT_DRIVER_ENUMERATOR_CONF="${NUT_CONF_DIR}/nut-driver-enumerator.conf" [ -s "${NUT_DRIVER_ENUMERATOR_CONF}" ] && \ echo "Sourcing config file: ${NUT_DRIVER_ENUMERATOR_CONF}" && \ . "${NUT_DRIVER_ENUMERATOR_CONF}" [ -z "${UPSCONF-}" ] && \ - UPSCONF="@sysconfdir@/ups.conf" + UPSCONF="${NUT_CONF_DIR}/ups.conf" # Start a freshly-registered unit? [ -z "${AUTO_START-}" ] && AUTO_START=yes @@ -127,20 +143,25 @@ systemd_listInstances() { ################# MAIN PROGRAM -if [ -f "$UPSCONF" ] ; then +if [ -f "$UPSCONF" ] && [ -r "$UPSCONF" ]; then + # Read the ups.conf file and find all defined sections (names of + # configuration blocks for drivers that connect to a certain device + # using specified protocol and media) [ -s "$UPSCONF" ] && \ UPSLIST_FILE="`egrep '^[ \t]*\[.*\][ \t]*$' "$UPSCONF" | sed 's,^[ \t]*\[\(.*\)\][ \t]*$,\1,' | sort -n`" || UPSLIST_FILE="" if [ -z "$UPSLIST_FILE" ] ; then echo "Error reading the '$UPSCONF' file or it does not declare any device configurations" >&2 + # Ok to continue - we may end up removing all instances fi else - echo "FATAL: The '$UPSCONF' file does not exist" >&2 + echo "FATAL: The '$UPSCONF' file does not exist or is not readable" >&2 exit 2 fi UPSLIST_SVCS="`$hook_listInstances`" || UPSLIST_SVCS="" if [ -z "$UPSLIST_SVCS" ] ; then - echo "Error reading the list of service instances for UPS drivers, or none are defined" >&2 + echo "Error reading the list of ${SERVICE_FRAMEWORK-} service instances for UPS drivers, or none are defined - before manipulations" >&2 + # Ok to continue - we may end up defining new instances fi # Quickly exit if there's nothing to do; note the lists are pre-sorted @@ -157,7 +178,7 @@ if [ -n "$UPSLIST_FILE" ]; then UPSLIST_SVCS="`$hook_listInstances`" || UPSLIST_SVCS="" if [ -z "$UPSLIST_SVCS" ] ; then - echo "Error reading the list of service instances for UPS drivers, or none are defined" >&2 + echo "Error reading the list of ${SERVICE_FRAMEWORK-} service instances for UPS drivers, or none are defined - after checking for new config sections to define service instances" >&2 fi fi @@ -184,6 +205,6 @@ if [ -n "$UPSLIST_FILE" ] ; then fi # Return 42 if there was a change applied succesfully -# (but e.g. some services should restart) +# (but e.g. some services should restart - upsd, maybe upsmon) [ "$UPSLIST_FILE" = "$UPSLIST_SVCS" ] && return 42 exit 13 From f958b69d4e215cdda7ecc04e5666704bf7779e82 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sat, 4 Mar 2017 16:20:40 +0100 Subject: [PATCH 014/165] nut-driver-enumerator.service.in : define an actual service payload --- scripts/systemd/nut-driver-enumerator.service.in | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scripts/systemd/nut-driver-enumerator.service.in b/scripts/systemd/nut-driver-enumerator.service.in index 233b45c536..00bb94613f 100644 --- a/scripts/systemd/nut-driver-enumerator.service.in +++ b/scripts/systemd/nut-driver-enumerator.service.in @@ -1,7 +1,22 @@ [Unit] +# This unit starts early in system lifecycle to set up nut-driver instances. +# End-user may also restart this unit after editing ups.conf to automatically +# un-register or add new instances as appropriate. Description=Network UPS Tools - enumeration of configure-file devices into systemd unit instances After=local-fs.target Before=nut-driver.target +[Service] +### Script needs privileges to restart units +#User=@RUN_AS_USER@ +#Group=@RUN_AS_GROUP@ +User=root +# it is expected that the process has to exit before systemd starts follow-up units +Type=oneshot +# the service shall be considered active even when all its processes exited +RemainAfterExit=yes +ExecStart=@libexecdir@/nut-driver-enumerator.sh +ExecReload=@libexecdir@/nut-driver-enumerator.sh + [Install] WantedBy=multi-user.target From 4bda68c95c2f0caf7f84ca1492d1b4eb45cb5d5b Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sat, 4 Mar 2017 17:49:19 +0100 Subject: [PATCH 015/165] nut-driver-enumerator.sh.in : refactor the logic of MAIN PROGRAM into smaller routines for readability --- scripts/systemd/nut-driver-enumerator.sh.in | 81 ++++++++++++--------- 1 file changed, 46 insertions(+), 35 deletions(-) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index caffbc96e6..b8944b3753 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -141,62 +141,73 @@ systemd_listInstances() { /bin/systemctl show 'nut-driver@*' -p Id | egrep '=nut-driver' | sed -e 's/^.*@//' -e 's/\.service$//' | sort -n } -################# MAIN PROGRAM - -if [ -f "$UPSCONF" ] && [ -r "$UPSCONF" ]; then - # Read the ups.conf file and find all defined sections (names of - # configuration blocks for drivers that connect to a certain device - # using specified protocol and media) - [ -s "$UPSCONF" ] && \ - UPSLIST_FILE="`egrep '^[ \t]*\[.*\][ \t]*$' "$UPSCONF" | sed 's,^[ \t]*\[\(.*\)\][ \t]*$,\1,' | sort -n`" || UPSLIST_FILE="" - if [ -z "$UPSLIST_FILE" ] ; then - echo "Error reading the '$UPSCONF' file or it does not declare any device configurations" >&2 - # Ok to continue - we may end up removing all instances +upslist_readFile() { + if [ -f "$UPSCONF" ] && [ -r "$UPSCONF" ]; then + # Read the ups.conf file and find all defined sections (names of + # configuration blocks for drivers that connect to a certain device + # using specified protocol and media) + [ -s "$UPSCONF" ] && \ + UPSLIST_FILE="`egrep '^[ \t]*\[.*\][ \t]*$' "$UPSCONF" | sed 's,^[ \t]*\[\(.*\)\][ \t]*$,\1,' | sort -n`" || UPSLIST_FILE="" + if [ -z "$UPSLIST_FILE" ] ; then + echo "Error reading the '$UPSCONF' file or it does not declare any device configurations" >&2 + # Ok to continue - we may end up removing all instances + fi + else + echo "FATAL: The '$UPSCONF' file does not exist or is not readable" >&2 + return 2 fi -else - echo "FATAL: The '$UPSCONF' file does not exist or is not readable" >&2 - exit 2 -fi - -UPSLIST_SVCS="`$hook_listInstances`" || UPSLIST_SVCS="" -if [ -z "$UPSLIST_SVCS" ] ; then - echo "Error reading the list of ${SERVICE_FRAMEWORK-} service instances for UPS drivers, or none are defined - before manipulations" >&2 - # Ok to continue - we may end up defining new instances -fi +} -# Quickly exit if there's nothing to do; note the lists are pre-sorted -# Otherwise a non-zero exit will be done below -[ "$UPSLIST_FILE" = "$UPSLIST_SVCS" ] && exit 0 +upslist_readSvcs() { + UPSLIST_SVCS="`$hook_listInstances`" || UPSLIST_SVCS="" + if [ -z "$UPSLIST_SVCS" ] && [ "$1" != "-" ] ; then + EXPLAIN="" + [ -z "$1" ] || EXPLAIN=" - $1" + echo "Error reading the list of ${SERVICE_FRAMEWORK-} service instances for UPS drivers, or none are defined${EXPLAIN}" >&2 + # Ok to continue - we may end up defining new instances + fi +} -if [ -n "$UPSLIST_FILE" ]; then +upslist_addSvcs() { for UPSF in $UPSLIST_FILE ; do if ! common_isRegistered "$UPSF" ; then echo "Adding new ${SERVICE_FRAMEWORK} service instance for power device [${UPSF}]..." >&2 $hook_registerInstance "$UPSF" fi done +} - UPSLIST_SVCS="`$hook_listInstances`" || UPSLIST_SVCS="" - if [ -z "$UPSLIST_SVCS" ] ; then - echo "Error reading the list of ${SERVICE_FRAMEWORK-} service instances for UPS drivers, or none are defined - after checking for new config sections to define service instances" >&2 - fi -fi - -if [ -n "$UPSLIST_SVCS" ]; then +upslist_delSvcs() { for UPSS in $UPSLIST_SVCS ; do if ! common_isFiled "$UPSS" ; then echo "Dropping old ${SERVICE_FRAMEWORK} service instance for power device [${UPSS}] which is no longer in config file..." >&2 $hook_unregisterInstance "$UPSS" fi done +} + +################# MAIN PROGRAM + +upslist_readFile || exit $? +upslist_readSvcs "before manipulations" + +# Quickly exit if there's nothing to do; note the lists are pre-sorted +# Otherwise a non-zero exit will be done below +[ "$UPSLIST_FILE" = "$UPSLIST_SVCS" ] && exit 0 + +if [ -n "$UPSLIST_FILE" ]; then + upslist_addSvcs + upslist_readSvcs "after checking for new config sections to define service instances" +fi + +if [ -n "$UPSLIST_SVCS" ]; then + upslist_delSvcs fi -UPSLIST_SVCS="`$hook_listInstances`" || UPSLIST_SVCS="" +upslist_readSvcs if [ -n "$UPSLIST_SVCS" ] ; then echo "=== The currently defined service instances are:" echo "$UPSLIST_SVCS" -else - echo "Error reading the list of service instances for UPS drivers, or none are defined" >&2 fi if [ -n "$UPSLIST_FILE" ] ; then From 8588cd5670fe94cba3ca2c75709da3780cd9dc11 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sat, 4 Mar 2017 17:50:45 +0100 Subject: [PATCH 016/165] nut-driver-enumerator.sh.in : introduce routines to help define custom dependencies of particular drivers on other services --- scripts/systemd/nut-driver-enumerator.sh.in | 72 +++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index b8944b3753..3a072d358d 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -111,8 +111,78 @@ common_isRegistered() { return 1 } +upsconf_getDriver() { + # "$1" = name of ups.conf section; return (echo) the driver name used there + # In the context this function is used, UPSCONF exists and section is there + [ -n "$1" ] || return $? + CURR_SECTION="" + while read LINE ; do + case "$LINE" in + \#*) ;; + \["$1"\]) CURR_SECTION="$1" ;; + \[*\]) CURR_SECTION="other" ;; + *driver*=*) if [ "$CURR_SECTION" = "$1" ]; then + CURR_DRV="$(echo "$LINE" | sed -e 's,\#.*$' -e 's,^[\t\ ]*,,' -e 's,[\t\ ]*$,,' -e 's,[\t\ ]*=[\t\ ]*,=,' -e 's,driver=\([^\t\ ]*\)[\t\ ]*.*$,\1,')" || CURR_DRV="" + [ -z "$CURR_DRV" ] || { echo "$CURR_DRV"; return 0; } + fi + ;; + *) ;; + esac + done + return 1 +} + +upsconf_getPort() { + # "$1" = name of ups.conf section; return (echo) the "port" name used there + # In the context this function is used, UPSCONF exists and section is there + [ -n "$1" ] || return $? + CURR_SECTION="" + while read LINE ; do + case "$LINE" in + \#*) ;; + \["$1"\]) CURR_SECTION="$1" ;; + \[*\]) CURR_SECTION="other" ;; + *port*=*) if [ "$CURR_SECTION" = "$1" ]; then + CURR_PORT="$(echo "$LINE" | sed -e 's,\#.*$' -e 's,^[\t\ ]*,,' -e 's,[\t\ ]*$,,' -e 's,[\t\ ]*=[\t\ ]*,=,' -e 's,port=\([^\t\ ]*\)[\t\ ]*.*$,\1,')" || CURR_PORT="" + [ -z "$CURR_PORT" ] || { echo "$CURR_PORT"; return 0; } + fi + ;; + *) ;; + esac + done + return 1 +} + +upsconf_getDriverMedia() { + # "$1" = name of ups.conf section; return (echo) name and type of driver as + # needed for dependency evaluation (what services we must depend on for this + # unit), tab-separated (drivernametype). Empty type for unclassified + # results, assuming no known special dependencies (note that depending on + # particular system's physics, both serial and network media may need USB). + CURR_DRV="`upsconf_getDriver "$1"`" || return $? + case "$CURR_DRV" in + *netxml*|*snmp*|*ipmi*|*powerman*|*-mib*|*avahi*|*apcsmart*|*apcupsd*) + printf '%s\t%s\n' "$CURR_DRV" "network" ; return ;; + *usb*) + printf '%s\t%s\n' "$CURR_DRV" "usb" ; return ;; + *dummy*|*clone*) # May be networked (proxy to remote NUT) + CURR_PORT="`upsconf_getPort "$1"`" || CURR_PORT="" + case "$CURR_PORT" in + *@localhost|*@|*@127.0.0.1|*@::1) + printf '%s\t%s\n' "$CURR_DRV" "" ; return ;; + *@*) + printf '%s\t%s\n' "$CURR_DRV" "network" ; return ;; + *) + printf '%s\t%s\n' "$CURR_DRV" "" ; return ;; + esac + ;; + *) printf '%s\t%s\n' "$CURR_DRV" "" ; return ;; + esac +} + smf_registerInstance() { /usr/sbin/svccfg -s nut-driver add "$1" || return + # TODO: Add dependencies based on upsconf_getDriverMedia() /usr/sbin/svcadm refresh 'nut-driver@'"$1" || return if [ "$AUTO_START" = yes ] ; then /usr/sbin/svcadm enable 'nut-driver@'"$1" || return @@ -129,6 +199,7 @@ smf_listInstances() { systemd_registerInstance() { /bin/systemctl enable 'nut-driver@'"$1" || return + # TODO: Add dependencies based on upsconf_getDriverMedia() if [ "$AUTO_START" = yes ] ; then /bin/systemctl start --no-block 'nut-driver@'"$1" || return fi @@ -136,6 +207,7 @@ systemd_registerInstance() { systemd_unregisterInstance() { /bin/systemctl stop 'nut-driver@'"$1" || false /bin/systemctl disable 'nut-driver@'"$1" + # TODO: Remove dir with custom dependencies if present } systemd_listInstances() { /bin/systemctl show 'nut-driver@*' -p Id | egrep '=nut-driver' | sed -e 's/^.*@//' -e 's/\.service$//' | sort -n From a18993cc0f2644b0a49603863ce374cdc210318a Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sat, 4 Mar 2017 17:51:56 +0100 Subject: [PATCH 017/165] nut-driver-enumerator.sh.in : allow custom NUT_CONF_DIR from envvar, to facilitate testing --- scripts/systemd/nut-driver-enumerator.sh.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index 3a072d358d..3cc55c6ecb 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -43,7 +43,7 @@ # Directory where NUT configs are located, e.g. /etc/nut or /etc/ups # Set at package configuration, compiled into daemons and drivers -NUT_CONF_DIR="@sysconfdir@" +[ -n "${NUT_CONF_DIR-}" ] || NUT_CONF_DIR="@sysconfdir@" [ -z "${NUT_DRIVER_ENUMERATOR_CONF-}" ] && \ NUT_DRIVER_ENUMERATOR_CONF="${NUT_CONF_DIR}/nut-driver-enumerator.conf" From 36e6b4823e8288db7e9e54dd5f778ec4e46c1151 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sat, 4 Mar 2017 17:53:56 +0100 Subject: [PATCH 018/165] nut-server.service.in : typo fix in comments --- scripts/systemd/nut-server.service.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/systemd/nut-server.service.in b/scripts/systemd/nut-server.service.in index dd1e88931a..039f042736 100644 --- a/scripts/systemd/nut-server.service.in +++ b/scripts/systemd/nut-server.service.in @@ -6,7 +6,7 @@ After=local-fs.target network.target nut-driver.target # accessing successfully started, at least to audit a system. Wants=nut-driver.target # The `upsd` is a networked service (even if bound to a `localhost`) -# so it requres that the OS has some notion of networking already. +# so it requires that the OS has some notion of networking already. Requires=network.target Before=nut-monitor.service From a107cfc4e7fd1ec5a9c9a550ffcfc3a6ff4e8ec4 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 01:09:37 +0100 Subject: [PATCH 019/165] nutshutdown.in : mark executable --- scripts/systemd/nutshutdown.in | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/systemd/nutshutdown.in diff --git a/scripts/systemd/nutshutdown.in b/scripts/systemd/nutshutdown.in old mode 100644 new mode 100755 From 979f35fab27466dc8d6a6e65262604c0bad9e345 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sat, 4 Mar 2017 20:23:35 +0100 Subject: [PATCH 020/165] nut-driver-enumerator.sh.in : support the concept of localhost networking dependencies, and define vars with lists of services to depend on --- scripts/systemd/nut-driver-enumerator.sh.in | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index 3cc55c6ecb..33fa55c4fd 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -45,6 +45,21 @@ # Set at package configuration, compiled into daemons and drivers [ -n "${NUT_CONF_DIR-}" ] || NUT_CONF_DIR="@sysconfdir@" +# Third-party services to depend on (can be overridden by config file) +### Note that for systemd+udev integration, it may be better to set up +### triggers in udev, see e.g. +### http://stackoverflow.com/questions/18463755/linux-start-daemon-on-connected-usb-serial-dongle +DEPSVC_USB_SYSTEMD="systemd-udev.service" +DEPSVC_NET_FULL_SYSTEMD="network-online.target" +DEPSVC_NET_LOCAL_SYSTEMD="network.target" + +# Some or all of these FMRIs may be related to dynamically changing hardware +DEPSVC_USB_SMF="svc:/system/hotplug:default svc:/system/dbus:default svc:/system/hal:default svc:/milestone/devices:default" +# By default there are several physical network FMRIs shipped and at most +# only one is enabled on a particular system (e.g. :default or :nwam) +DEPSVC_NET_FULL_SMF="svc:/network/physical" +DEPSVC_NET_LOCAL_SMF="svc:/network/loopback:default" + [ -z "${NUT_DRIVER_ENUMERATOR_CONF-}" ] && \ NUT_DRIVER_ENUMERATOR_CONF="${NUT_CONF_DIR}/nut-driver-enumerator.conf" @@ -169,7 +184,7 @@ upsconf_getDriverMedia() { CURR_PORT="`upsconf_getPort "$1"`" || CURR_PORT="" case "$CURR_PORT" in *@localhost|*@|*@127.0.0.1|*@::1) - printf '%s\t%s\n' "$CURR_DRV" "" ; return ;; + printf '%s\t%s\n' "$CURR_DRV" "network-localhost" ; return ;; *@*) printf '%s\t%s\n' "$CURR_DRV" "network" ; return ;; *) From cf5124af4f3e73ec9203ab047d18c48b077605a7 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 00:36:05 +0100 Subject: [PATCH 021/165] nut-driver-enumerator.sh.in : added variables for dependency type on third-party service units --- scripts/systemd/nut-driver-enumerator.sh.in | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index 33fa55c4fd..5e3346673a 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -49,16 +49,31 @@ ### Note that for systemd+udev integration, it may be better to set up ### triggers in udev, see e.g. ### http://stackoverflow.com/questions/18463755/linux-start-daemon-on-connected-usb-serial-dongle +### Also can tune whether a driver "Wants" another service (would consider +### ordering if that one is enabled, but live if it is disabled), or if it +### "Requires" that (would cause that to start). DEPSVC_USB_SYSTEMD="systemd-udev.service" +DEPREQ_USB_SYSTEMD="Wants" DEPSVC_NET_FULL_SYSTEMD="network-online.target" +DEPREQ_NET_FULL_SYSTEMD="Wants" DEPSVC_NET_LOCAL_SYSTEMD="network.target" +DEPREQ_NET_LOCAL_SYSTEMD="Wants" # Some or all of these FMRIs may be related to dynamically changing hardware +# require_all) ;; # All cited services are running (online or degraded) +# require_any) ;; # At least one of the cited services is running +# optional_all) ;; # (All) cited services are running or would not run +# # without administrative action (disabled, maintenance, +# # not present, or are waiting for dependencies which do +# # not start without administrative action). DEPSVC_USB_SMF="svc:/system/hotplug:default svc:/system/dbus:default svc:/system/hal:default svc:/milestone/devices:default" +DEPREQ_USB_SMF="optional_all" # By default there are several physical network FMRIs shipped and at most # only one is enabled on a particular system (e.g. :default or :nwam) DEPSVC_NET_FULL_SMF="svc:/network/physical" +DEPREQ_NET_FULL_SMF="optional_all" DEPSVC_NET_LOCAL_SMF="svc:/network/loopback:default" +DEPREQ_NET_LOCAL_SMF="optional_all" [ -z "${NUT_DRIVER_ENUMERATOR_CONF-}" ] && \ NUT_DRIVER_ENUMERATOR_CONF="${NUT_CONF_DIR}/nut-driver-enumerator.conf" From c1568111163b438b59860c930e8c7299ba0d1df4 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sat, 4 Mar 2017 21:09:58 +0100 Subject: [PATCH 022/165] nut-driver-enumerator.sh.in : use proper FMRI:instance separator for SMF --- scripts/systemd/nut-driver-enumerator.sh.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index 5e3346673a..c69c619ef5 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -213,13 +213,13 @@ upsconf_getDriverMedia() { smf_registerInstance() { /usr/sbin/svccfg -s nut-driver add "$1" || return # TODO: Add dependencies based on upsconf_getDriverMedia() - /usr/sbin/svcadm refresh 'nut-driver@'"$1" || return + /usr/sbin/svcadm refresh 'nut-driver:'"$1" || return if [ "$AUTO_START" = yes ] ; then - /usr/sbin/svcadm enable 'nut-driver@'"$1" || return + /usr/sbin/svcadm enable 'nut-driver:'"$1" || return fi } smf_unregisterInstance() { - /usr/sbin/svcadm disable -ts 'nut-driver@'"$1" || false + /usr/sbin/svcadm disable -ts 'nut-driver:'"$1" || false /usr/sbin/svccfg -s nut-driver delete "$1" } smf_listInstances() { From b43aa8918d135f28684ba8ce1a09b127085968b0 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 00:39:36 +0100 Subject: [PATCH 023/165] nut-driver-enumerator.sh.in : change upsconf_getDriverMedia() output from tab-separated to multiline; add upsconf_getMedia() and upsconf_debug() and upslist_debug() --- scripts/systemd/nut-driver-enumerator.sh.in | 34 ++++++++++++++++----- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index c69c619ef5..0a1a7ed5dd 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -186,30 +186,43 @@ upsconf_getPort() { upsconf_getDriverMedia() { # "$1" = name of ups.conf section; return (echo) name and type of driver as # needed for dependency evaluation (what services we must depend on for this - # unit), tab-separated (drivernametype). Empty type for unclassified + # unit), newline-separated (drvnametype). Empty type for unclassified # results, assuming no known special dependencies (note that depending on # particular system's physics, both serial and network media may need USB). CURR_DRV="`upsconf_getDriver "$1"`" || return $? case "$CURR_DRV" in *netxml*|*snmp*|*ipmi*|*powerman*|*-mib*|*avahi*|*apcsmart*|*apcupsd*) - printf '%s\t%s\n' "$CURR_DRV" "network" ; return ;; + printf '%s\n%s\n' "$CURR_DRV" "network" ; return ;; *usb*) - printf '%s\t%s\n' "$CURR_DRV" "usb" ; return ;; + printf '%s\n%s\n' "$CURR_DRV" "usb" ; return ;; *dummy*|*clone*) # May be networked (proxy to remote NUT) CURR_PORT="`upsconf_getPort "$1"`" || CURR_PORT="" case "$CURR_PORT" in *@localhost|*@|*@127.0.0.1|*@::1) - printf '%s\t%s\n' "$CURR_DRV" "network-localhost" ; return ;; + printf '%s\n%s\n' "$CURR_DRV" "network-localhost" ; return ;; *@*) - printf '%s\t%s\n' "$CURR_DRV" "network" ; return ;; + printf '%s\n%s\n' "$CURR_DRV" "network" ; return ;; *) - printf '%s\t%s\n' "$CURR_DRV" "" ; return ;; + printf '%s\n%s\n' "$CURR_DRV" "" ; return ;; esac ;; - *) printf '%s\t%s\n' "$CURR_DRV" "" ; return ;; + *) printf '%s\n%s\n' "$CURR_DRV" "" ; return ;; esac } +upsconf_getMedia() { + _DRVMED="`upsconf_getDriverMedia "$1"`" || return + echo "$_DRVMED" | tail -n +2 + return 0 +} + +upsconf_debug() { + _DRV="`upsconf_getDriver "$1"`" + _PRT="`upsconf_getPort "$1"`" + _MED="`upsconf_getMedia "$1"`" + echo "INST: [$1]: DRV='$_DRV' PORT='$_PRT' MEDIA='$_MED'" +} + smf_registerInstance() { /usr/sbin/svccfg -s nut-driver add "$1" || return # TODO: Add dependencies based on upsconf_getDriverMedia() @@ -270,6 +283,12 @@ upslist_readSvcs() { fi } +upslist_debug() { + for UPSF in $UPSLIST_FILE ; do + upsconf_debug "$UPSF" + done +} + upslist_addSvcs() { for UPSF in $UPSLIST_FILE ; do if ! common_isRegistered "$UPSF" ; then @@ -291,6 +310,7 @@ upslist_delSvcs() { ################# MAIN PROGRAM upslist_readFile || exit $? +upslist_debug upslist_readSvcs "before manipulations" # Quickly exit if there's nothing to do; note the lists are pre-sorted From 2d29617d644a3d7920e1999b20036a5c5f4a42d7 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 00:50:44 +0100 Subject: [PATCH 024/165] nut-driver-enumerator.sh.in : refactor with upsconf_getValue() and cached pre-cooked ups.conf data; infrastructure to configure service dependencies when adding the service instance --- scripts/systemd/nut-driver-enumerator.sh.in | 118 ++++++++++++++------ 1 file changed, 83 insertions(+), 35 deletions(-) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index 0a1a7ed5dd..51b648b0b2 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -96,6 +96,10 @@ if [ -z "${SERVICE_FRAMEWORK-}" ] ; then SERVICE_FRAMEWORK="systemd" fi +# Cache needed bits of ups.conf to speed up later parsing. Note that these +# data are needed for most operations, and populated by upslist_readFile() +UPSCONF_DATA="" + # List of configured UPSes in the config-file UPSLIST_FILE="" # List of configured service instances for UPS drivers @@ -141,46 +145,46 @@ common_isRegistered() { return 1 } -upsconf_getDriver() { - # "$1" = name of ups.conf section; return (echo) the driver name used there - # In the context this function is used, UPSCONF exists and section is there +upsconf_getValue() { + # "$1" = name of ups.conf section; $2 = name of config key; echo the value [ -n "$1" ] || return $? + [ -n "$2" ] || return $? CURR_SECTION="" + echo "$UPSCONF_DATA" | \ while read LINE ; do case "$LINE" in - \#*) ;; \["$1"\]) CURR_SECTION="$1" ;; - \[*\]) CURR_SECTION="other" ;; - *driver*=*) if [ "$CURR_SECTION" = "$1" ]; then - CURR_DRV="$(echo "$LINE" | sed -e 's,\#.*$' -e 's,^[\t\ ]*,,' -e 's,[\t\ ]*$,,' -e 's,[\t\ ]*=[\t\ ]*,=,' -e 's,driver=\([^\t\ ]*\)[\t\ ]*.*$,\1,')" || CURR_DRV="" - [ -z "$CURR_DRV" ] || { echo "$CURR_DRV"; return 0; } + \[*\]) + [ "$CURR_SECTION" = "$1" ] && break + CURR_SECTION="other" + ;; + "$2"=*) if [ "$CURR_SECTION" = "$1" ]; then +# VALUE="$(echo "$LINE" | sed -e 's,\#.*$,,' -e 's,^[\t\ ]*,,' -e 's,[\t\ ]*$,,' -e 's,[\t\ ]*=[\t\ ]*,=,' -e 's,'"$2"'=\([^\t\ ]*\)[\t\ ]*.*$,\1,')" + VALUE="$(echo "$LINE" | sed -e 's,^'"$2"'=\([^\t\ ]*\)[\t\ ]*.*$,\1,')" + RES=$? + echo "$VALUE" + return $RES fi ;; *) ;; esac done + # Nothing matched return 1 } +upsconf_getDriver() { + # "$1" = name of ups.conf section; return (echo) the driver name used there + # In the context this function is used, UPSCONF exists and section is there + upsconf_getValue "$1" "driver" + return $? +} + upsconf_getPort() { # "$1" = name of ups.conf section; return (echo) the "port" name used there # In the context this function is used, UPSCONF exists and section is there - [ -n "$1" ] || return $? - CURR_SECTION="" - while read LINE ; do - case "$LINE" in - \#*) ;; - \["$1"\]) CURR_SECTION="$1" ;; - \[*\]) CURR_SECTION="other" ;; - *port*=*) if [ "$CURR_SECTION" = "$1" ]; then - CURR_PORT="$(echo "$LINE" | sed -e 's,\#.*$' -e 's,^[\t\ ]*,,' -e 's,[\t\ ]*$,,' -e 's,[\t\ ]*=[\t\ ]*,=,' -e 's,port=\([^\t\ ]*\)[\t\ ]*.*$,\1,')" || CURR_PORT="" - [ -z "$CURR_PORT" ] || { echo "$CURR_PORT"; return 0; } - fi - ;; - *) ;; - esac - done - return 1 + upsconf_getValue "$1" "port" + return $? } upsconf_getDriverMedia() { @@ -225,7 +229,27 @@ upsconf_debug() { smf_registerInstance() { /usr/sbin/svccfg -s nut-driver add "$1" || return - # TODO: Add dependencies based on upsconf_getDriverMedia() + + DEPSVC="" + DEPREQ="" + _MED="`upsconf_getMedia "$1"`" + case "$_MED" in + usb) + DEPSVC="$DEPSVC_USB_SMF" + DEPREQ="$DEPREQ_USB_SMF" ;; + network-localhost) + DEPSVC="$DEPSVC_NET_LOCAL_SMF" + DEPREQ="$DEPREQ_NET_LOCAL_SMF" ;; + network) + DEPSVC="$DEPSVC_NET_FULL_SMF" + DEPREQ="$DEPREQ_NET_FULL_SMF" ;; + '') ;; + *) echo "WARNING: Unexpected NUT media type ignored: '$_MED'" >&2 ;; + esac + if [ -n "$DEPSVC" ]; then + echo "Adding '$DEPREQ' dependency for '$1' on '$DEPSVC'..." + fi + /usr/sbin/svcadm refresh 'nut-driver:'"$1" || return if [ "$AUTO_START" = yes ] ; then /usr/sbin/svcadm enable 'nut-driver:'"$1" || return @@ -242,7 +266,27 @@ smf_listInstances() { systemd_registerInstance() { /bin/systemctl enable 'nut-driver@'"$1" || return - # TODO: Add dependencies based on upsconf_getDriverMedia() + + DEPSVC="" + DEPREQ="" + _MED="`upsconf_getMedia "$1"`" + case "$_MED" in + usb) + DEPSVC="$DEPSVC_USB_SYSTEMD" + DEPREQ="$DEPREQ_USB_SYSTEMD" ;; + network-localhost) + DEPSVC="$DEPSVC_NET_LOCAL_SYSTEMD" + DEPREQ="$DEPREQ_NET_LOCAL_SYSTEMD" ;; + network) + DEPSVC="$DEPSVC_NET_FULL_SYSTEMD" + DEPREQ="$DEPREQ_NET_FULL_SYSTEMD" ;; + '') ;; + *) echo "WARNING: Unexpected NUT media type ignored: '$_MED'" >&2 ;; + esac + if [ -n "$DEPSVC" ]; then + echo "Adding '$DEPREQ' dependency for '$1' on '$DEPSVC'..." + fi + if [ "$AUTO_START" = yes ] ; then /bin/systemctl start --no-block 'nut-driver@'"$1" || return fi @@ -257,20 +301,24 @@ systemd_listInstances() { } upslist_readFile() { - if [ -f "$UPSCONF" ] && [ -r "$UPSCONF" ]; then - # Read the ups.conf file and find all defined sections (names of - # configuration blocks for drivers that connect to a certain device - # using specified protocol and media) + # Read the ups.conf file and find all defined sections (names of + # configuration blocks for drivers that connect to a certain device + # using specified protocol and media) + if [ -n "$UPSCONF" ] && [ -f "$UPSCONF" ] && [ -r "$UPSCONF" ]; then [ -s "$UPSCONF" ] && \ - UPSLIST_FILE="`egrep '^[ \t]*\[.*\][ \t]*$' "$UPSCONF" | sed 's,^[ \t]*\[\(.*\)\][ \t]*$,\1,' | sort -n`" || UPSLIST_FILE="" - if [ -z "$UPSLIST_FILE" ] ; then - echo "Error reading the '$UPSCONF' file or it does not declare any device configurations" >&2 - # Ok to continue - we may end up removing all instances - fi + UPSCONF_DATA="$(egrep '[\[\=]' < "$UPSCONF" | sed -e 's,^[\t\ ]*,,' -e 's,^\#.*$,,' -e 's,[\t\ ]*$,,' -e 's,[\t\ ]*=[\t\ ]*,=,g' -e 's,=\"\([^\ \t]*\)\"$,=\1,' | egrep '^(\[.*\]|driver=|port=)')" || \ + UPSCONF_DATA="" else echo "FATAL: The '$UPSCONF' file does not exist or is not readable" >&2 return 2 fi + + [ -n "$UPSCONF_DATA" ] && \ + UPSLIST_FILE="$(echo "$UPSCONF_DATA" | egrep '^\[.*\]$' | sed 's,^\[\(.*\)\]$,\1,' | sort -n)" || UPSLIST_FILE="" + if [ -z "$UPSLIST_FILE" ] ; then + echo "Error reading the '$UPSCONF' file or it does not declare any device configurations" >&2 + # Ok to continue - we may end up removing all instances + fi } upslist_readSvcs() { From ba4bb5794ac1d3c9b332ee46a4ae219a366e0c71 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 01:09:06 +0100 Subject: [PATCH 025/165] Remove hardcoded dependencies on udev and network from provided systemd units; add comments about extending via drop-in files and that nut-driver-enumerator will do this for nut-drivers --- scripts/systemd/nut-driver-enumerator.sh.in | 2 +- scripts/systemd/nut-driver.target | 5 +++-- scripts/systemd/nut-driver@.service.in | 4 ++-- scripts/systemd/nut-monitor.service.in | 6 ++++++ scripts/systemd/nut-server.service.in | 6 ++++++ 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index 51b648b0b2..cc66a379d3 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -52,7 +52,7 @@ ### Also can tune whether a driver "Wants" another service (would consider ### ordering if that one is enabled, but live if it is disabled), or if it ### "Requires" that (would cause that to start). -DEPSVC_USB_SYSTEMD="systemd-udev.service" +DEPSVC_USB_SYSTEMD="systemd-udev.service systemd-udev-settle.service" DEPREQ_USB_SYSTEMD="Wants" DEPSVC_NET_FULL_SYSTEMD="network-online.target" DEPREQ_NET_FULL_SYSTEMD="Wants" diff --git a/scripts/systemd/nut-driver.target b/scripts/systemd/nut-driver.target index 2679a7f088..2698ade448 100644 --- a/scripts/systemd/nut-driver.target +++ b/scripts/systemd/nut-driver.target @@ -1,6 +1,7 @@ [Unit] -Description=Network UPS Tools - power device driver controller -After=local-fs.target network.target +Description=Network UPS Tools - target for power device drivers on this system +After=local-fs.target +# network.target [Install] WantedBy=multi-user.target diff --git a/scripts/systemd/nut-driver@.service.in b/scripts/systemd/nut-driver@.service.in index 444025ec05..68c7396605 100644 --- a/scripts/systemd/nut-driver@.service.in +++ b/scripts/systemd/nut-driver@.service.in @@ -1,7 +1,6 @@ [Unit] Description=Network UPS Tools - device driver for %I -After=local-fs.target network.target systemd-udev-settle.service -Wants=systemd-udev-settle.service +After=local-fs.target PartOf=nut-driver.target # Note: The choice of "network.target" allows to schedule this unit # roughly when the network stack of this OS is ready (e.g. that the @@ -23,6 +22,7 @@ PartOf=nut-driver.target # If your `upsd` requires specific IP addresses to be available before # starting, a `/etc/systemd/system/nut-driver.target.d/network.conf` # can be used in a similar manner. +# Finally note that "nut-driver-enumerator.service" should take care of this. [Service] ExecStart=@SBINDIR@/upsdrvctl start %i diff --git a/scripts/systemd/nut-monitor.service.in b/scripts/systemd/nut-monitor.service.in index f3840256d6..2333537d5c 100644 --- a/scripts/systemd/nut-monitor.service.in +++ b/scripts/systemd/nut-monitor.service.in @@ -7,6 +7,12 @@ After=local-fs.target network.target nut-server.service # The "Wants" directive would try to start the nut-server but # would not abort if that attempt fails for whatever reason. Wants=nut-server.service +# Extending the unit does not require *this* file to be edited, you +# can instead drop in an additional piece of configuration, e.g. add +# a `/etc/systemd/system/nut-monitor.service.d/network.conf` with: +# [Unit] +# Requires=network-online.target +# After=network-online.target [Service] ExecStart=@SBINDIR@/upsmon diff --git a/scripts/systemd/nut-server.service.in b/scripts/systemd/nut-server.service.in index 039f042736..0d9e0edd00 100644 --- a/scripts/systemd/nut-server.service.in +++ b/scripts/systemd/nut-server.service.in @@ -7,6 +7,12 @@ After=local-fs.target network.target nut-driver.target Wants=nut-driver.target # The `upsd` is a networked service (even if bound to a `localhost`) # so it requires that the OS has some notion of networking already. +# Extending the unit does not require *this* file to be edited, you +# can instead drop in an additional piece of configuration, e.g. add +# a `/etc/systemd/system/nut-server.service.d/network.conf` with: +# [Unit] +# Requires=network-online.target +# After=network-online.target Requires=network.target Before=nut-monitor.service From e71275596d282da64a93570a1bf5b2f2c100f09c Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 01:25:13 +0100 Subject: [PATCH 026/165] nut-driver-enumerator.sh.in : complete the systemd drop-in support for custom dependencies for a driver --- scripts/systemd/nut-driver-enumerator.sh.in | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index cc66a379d3..22ea42fb90 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -284,7 +284,17 @@ systemd_registerInstance() { *) echo "WARNING: Unexpected NUT media type ignored: '$_MED'" >&2 ;; esac if [ -n "$DEPSVC" ]; then - echo "Adding '$DEPREQ' dependency for '$1' on '$DEPSVC'..." + [ -n "$DEPREQ" ] || DEPREQ="#Wants" + echo "Adding '$DEPREQ'+After dependency for '$1' on '$DEPSVC'..." + mkdir -p "/etc/systemd/system/nut-driver@$1.service.d" && \ + cat > "/etc/systemd/system/nut-driver@$1.service.d/nut-driver-enumerator-generated.conf" <&2 fi if [ "$AUTO_START" = yes ] ; then @@ -294,7 +304,7 @@ systemd_registerInstance() { systemd_unregisterInstance() { /bin/systemctl stop 'nut-driver@'"$1" || false /bin/systemctl disable 'nut-driver@'"$1" - # TODO: Remove dir with custom dependencies if present + rm -rf "/etc/systemd/system/nut-driver@$1.service.d" } systemd_listInstances() { /bin/systemctl show 'nut-driver@*' -p Id | egrep '=nut-driver' | sed -e 's/^.*@//' -e 's/\.service$//' | sort -n From 2e3a8d9e33aff7ab4632e9ff3c3dfcad60c5f39d Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 01:32:36 +0100 Subject: [PATCH 027/165] nut-driver-enumerator.sh.in : complete the SMF drop-in support for custom dependencies for a driver --- scripts/systemd/nut-driver-enumerator.sh.in | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index 22ea42fb90..1386ba4dd2 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -246,13 +246,25 @@ smf_registerInstance() { '') ;; *) echo "WARNING: Unexpected NUT media type ignored: '$_MED'" >&2 ;; esac + + TARGET_FMRI="nut-driver:$1" if [ -n "$DEPSVC" ]; then + [ -n "$DEPREQ" ] || DEPREQ="optional_all" echo "Adding '$DEPREQ' dependency for '$1' on '$DEPSVC'..." + + DEPPG="nut-driver-enumerator-generated" + RESTARTON="refresh" + svccfg -s "$TARGET_FMRI" addpg "$DEPPG" dependency && \ + svccfg -s "$TARGET_FMRI" setprop "$DEPPG"/grouping = astring: "$DEPREQ" && \ + svccfg -s "$TARGET_FMRI" setprop "$DEPPG"/restart_on = astring: "$RESTARTON" && \ + svccfg -s "$TARGET_FMRI" setprop "$DEPPG"/type = astring: service && \ + svccfg -s "$TARGET_FMRI" setprop "$DEPPG"/entities = fmri: "($DEPSVC)" && \ + echo "OK" || echo "FAILED to define the dependency" >&2 fi - /usr/sbin/svcadm refresh 'nut-driver:'"$1" || return + /usr/sbin/svcadm refresh "${TARGET_FMRI}" || return if [ "$AUTO_START" = yes ] ; then - /usr/sbin/svcadm enable 'nut-driver:'"$1" || return + /usr/sbin/svcadm enable "${TARGET_FMRI}" || return fi } smf_unregisterInstance() { From 17d246cb270464140ce5f7a431918a740bc09901 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 01:33:08 +0100 Subject: [PATCH 028/165] nut-driver-enumerator.sh.in : comment-away upslist_debug() in default runs --- scripts/systemd/nut-driver-enumerator.sh.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index 1386ba4dd2..db631c0212 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -380,7 +380,7 @@ upslist_delSvcs() { ################# MAIN PROGRAM upslist_readFile || exit $? -upslist_debug +#upslist_debug upslist_readSvcs "before manipulations" # Quickly exit if there's nothing to do; note the lists are pre-sorted From 840d3080c1d96c0685b4eb5cac58c9d51e7fecf0 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 02:26:00 +0100 Subject: [PATCH 029/165] WIP Adding Solaris SMF manifests for NUT --- configure.ac | 34 +++++ scripts/Solaris/.gitignore | 8 ++ scripts/Solaris/Makefile.am | 14 +++ scripts/Solaris/nut-client.xml.in | 119 ++++++++++++++++++ scripts/Solaris/nut-driver-enumerator.xml.in | 85 +++++++++++++ scripts/Solaris/nut-driver.xml.in | 114 +++++++++++++++++ scripts/Solaris/nut.xml.in | 125 +++++++++++++++++++ scripts/Solaris/svc-nut-client.in | 49 ++++++++ scripts/Solaris/svc-nut.in | 46 +++++++ 9 files changed, 594 insertions(+) create mode 100644 scripts/Solaris/nut-client.xml.in create mode 100644 scripts/Solaris/nut-driver-enumerator.xml.in create mode 100644 scripts/Solaris/nut-driver.xml.in create mode 100644 scripts/Solaris/nut.xml.in create mode 100755 scripts/Solaris/svc-nut-client.in create mode 100755 scripts/Solaris/svc-nut.in diff --git a/configure.ac b/configure.ac index 3679bc4f64..4d6456f567 100644 --- a/configure.ac +++ b/configure.ac @@ -1181,6 +1181,34 @@ fi AM_CONDITIONAL(WITH_PKG_CONFIG, test -n "${pkgconfigdir}") PKG_PROG_PKG_CONFIG +AC_MSG_CHECKING(whether to install Solaris SMF files) +solarissmf="auto" +AC_ARG_WITH([solaris-smf], + AS_HELP_STRING([--with-solaris-smf=(yes|auto|no)], [Enable installation of NUT scripts and manifests for Solaris Service Management Framework (auto)]), +[ + case "${withval}" in + auto|"") + solarissmf="auto" + ;; + yes|no) + solarissmf="${withval}" + ;; + *) + AC_MSG_ERROR([Unexpected argument for --with-solaris-smf=${withval}]) + ;; + esac +], []) + +if test x"$solarissmf" = xauto ; then + if test -x /usr/sbin/svcadm && test -x /usr/sbin/svccfg && test -x /usr/bin/svcs ; then + solarissmf="yes" + else + solarissmf="no" + fi +fi +AC_MSG_RESULT([${solarissmf}]) +AM_CONDITIONAL(WITH_SOLARIS_SMF, test x"$solarissmf" = x"yes") + AC_MSG_CHECKING(whether to install systemd files) AC_ARG_WITH([systemdsystemunitdir], AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files (auto)]), @@ -1640,6 +1668,12 @@ AC_OUTPUT([ scripts/systemd/nut-driver-enumerator.service scripts/systemd/nut-driver-enumerator.sh scripts/systemd/nutshutdown + scripts/Solaris/nut-driver-enumerator.xml + scripts/Solaris/nut-driver.xml + scripts/Solaris/nut-client.xml + scripts/Solaris/nut.xml + scripts/Solaris/svc-nut + scripts/Solaris/svc-nut-client scripts/Solaris/Makefile scripts/Solaris/pkginfo scripts/Solaris/postinstall diff --git a/scripts/Solaris/.gitignore b/scripts/Solaris/.gitignore index 92334788dc..b74faaea0d 100644 --- a/scripts/Solaris/.gitignore +++ b/scripts/Solaris/.gitignore @@ -1,4 +1,12 @@ /nut /pkginfo +/preinstall /postinstall /preremove +/postremove +/svc-nut +/svc-nut-client +/nut-driver.xml +/nut-driver-enumerator.xml +/nut-client.xml +/nut.xml diff --git a/scripts/Solaris/Makefile.am b/scripts/Solaris/Makefile.am index 15075b0617..43790a8666 100644 --- a/scripts/Solaris/Makefile.am +++ b/scripts/Solaris/Makefile.am @@ -1,5 +1,19 @@ EXTRA_DIST = makelocal.sh +if WITH_SOLARIS_SMF +solarissmfmethoddir = /lib/svc/method +solarissmfmanifestdir = /var/svc/manifest/application +solarissmfmethod_SCRIPTS = \ + ../systemd/nut-driver-enumerator.sh \ + svc-nut \ + svc-nut-client +solarissmfmanifest_DATA = \ + nut.xml \ + nut-client.xml \ + nut-driver.xml \ + nut-driver-enumerator.xml +endif + package: makelocal.sh pkginfo $ cd @prefix@; $ find . -print | pkgproto > prototype1 $ cp makelocal.sh precheck.py pkginfo nut preinstall postinstall preremove postremove preproto.pl @prefix@ diff --git a/scripts/Solaris/nut-client.xml.in b/scripts/Solaris/nut-client.xml.in new file mode 100644 index 0000000000..ac3399e821 --- /dev/null +++ b/scripts/Solaris/nut-client.xml.in @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/Solaris/nut-driver-enumerator.xml.in b/scripts/Solaris/nut-driver-enumerator.xml.in new file mode 100644 index 0000000000..d1b4b4177e --- /dev/null +++ b/scripts/Solaris/nut-driver-enumerator.xml.in @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/Solaris/nut-driver.xml.in b/scripts/Solaris/nut-driver.xml.in new file mode 100644 index 0000000000..3f401aeaa7 --- /dev/null +++ b/scripts/Solaris/nut-driver.xml.in @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/Solaris/nut.xml.in b/scripts/Solaris/nut.xml.in new file mode 100644 index 0000000000..b403733521 --- /dev/null +++ b/scripts/Solaris/nut.xml.in @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/Solaris/svc-nut-client.in b/scripts/Solaris/svc-nut-client.in new file mode 100755 index 0000000000..2e3283afc2 --- /dev/null +++ b/scripts/Solaris/svc-nut-client.in @@ -0,0 +1,49 @@ +#!/sbin/sh + +# Trivial (better is yet to come) SMF method script to start nut services +# Adapted for OpenIndiana userland from init.d script template in NUT sources +# Adaptation copyright (C) 2016-2017 Jim Klimov + +if [ -z "$SMF_FMRI" ]; then + echo "$0 must be called in SMF context!" &>2 + exit 1 +fi + +# smf(5) +. /lib/svc/share/smf_include.sh || exit + +NUT_DIR="@prefix@" +NUT_SBIN_DIR="$NUT_DIR/sbin" +NUT_RUN_DIR="/var/run/nut" +NUTUSER="nut" +NUTGROUP="nut" + +ups_start () { + if [ "$MODE" = "none" ];then + echo "No NUT mode set" >&2 + exit $SMF_EXIT_ERR_CONFIG + fi + + # Default rights inspired by NUT scripts/Solaris/postinstall.in + mkdir -p "$NUT_RUN_DIR" && \ + chown "root:$NUTGROUP" "$NUT_RUN_DIR" && \ + chmod 770 "$NUT_RUN_DIR" \ + || exit $SMF_EXIT_ERR_FATAL + + "${NUT_SBIN_DIR}"/upsmon #> /dev/null 2>&1 +} + +case "$1" in +'start') + ups_start + ;; + +*) + echo "" + echo "Usage: '$0' {start}" + echo "" + exit $SMF_EXIT_ERR_CONFIG + ;; +esac + +exit $? diff --git a/scripts/Solaris/svc-nut.in b/scripts/Solaris/svc-nut.in new file mode 100755 index 0000000000..2ff8eb7386 --- /dev/null +++ b/scripts/Solaris/svc-nut.in @@ -0,0 +1,46 @@ +#!/sbin/sh + +# Trivial (better is yet to come) SMF method script to start nut services +# Adapted for OpenIndiana userland from init.d script template in NUT sources +# Adaptation copyright (C) 2016 Jim Klimov + +if [ -z "$SMF_FMRI" ]; then + echo "$0 must be called in SMF context!" &>2 + exit 1 +fi + +# smf(5) +. /lib/svc/share/smf_include.sh || exit + +NUT_DIR="/usr" +NUT_SBIN_DIR="$NUT_DIR/sbin" +NUT_RUN_DIR="/var/run/nut" +NUTUSER="nut" +NUTGROUP="nut" + +ups_start () { + # Default rights inspired by NUT scripts/Solaris/postinstall.in + mkdir -p "$NUT_RUN_DIR" && \ + chown "root:$NUTGROUP" "$NUT_RUN_DIR" && \ + chmod 770 "$NUT_RUN_DIR" \ + || exit $SMF_EXIT_ERR_FATAL + + # In this distribution, UPS drivers are wrapped by service instances + #"${NUT_SBIN_DIR}"/upsdrvctl start #> /dev/null 2>&1 + "${NUT_SBIN_DIR}"/upsd #> /dev/null 2>&1 +} + +case "$1" in +'start') + ups_start + ;; + +*) + echo "" + echo "Usage: '$0' {start}" + echo "" + exit $SMF_EXIT_ERR_CONFIG + ;; +esac + +exit $? From 1eada55d18b8e70631c52142e19012b577b8ad89 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 13:49:09 +0100 Subject: [PATCH 030/165] Sanitize Solaris SVR4 packaging rules --- scripts/Solaris/Makefile.am | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/scripts/Solaris/Makefile.am b/scripts/Solaris/Makefile.am index 43790a8666..5fc8dc5180 100644 --- a/scripts/Solaris/Makefile.am +++ b/scripts/Solaris/Makefile.am @@ -14,18 +14,22 @@ solarissmfmanifest_DATA = \ nut-driver-enumerator.xml endif -package: makelocal.sh pkginfo - $ cd @prefix@; $ find . -print | pkgproto > prototype1 - $ cp makelocal.sh precheck.py pkginfo nut preinstall postinstall preremove postremove preproto.pl @prefix@ - $ cd @prefix@; perl preproto.pl - $ cd @prefix@; python precheck.py - $ cd @prefix@; rm -f prototype1 - $ cd @prefix@; ./makelocal.sh - $ cp @prefix@/*.gz $(srcdir) - if test `uname -p` = "i386"; then \ - mv NUT_solaris_package.local.gz NUT_solaris_i386_package@PACKAGE_VERSION@.local.gz; \ - else \ - if test `uname -p` = "sparc"; then \ - mv NUT_solaris_package.local.gz NUT_solaris_sparc_package@PACKAGE_VERSION@.local.gz; \ - fi; \ - fi; +# TODO: Define support for IPS packaging +if WITH_SOLARIS_IPS +package: package-ips +else +package: package-svr4 +endif + +package-svr4: makelocal.sh pkginfo + cd @prefix@ && find . -print | pkgproto > prototype1 + cp makelocal.sh precheck.py pkginfo nut preinstall postinstall preremove postremove preproto.pl @prefix@ + cd @prefix@ && perl preproto.pl + cd @prefix@ && python precheck.py + cd @prefix@ && rm -f prototype1 + cd @prefix@ && ./makelocal.sh + cp @prefix@/*.gz $(srcdir) + UNAME_P="`uname -p`" && case "$${UNAME_P}" in \ + i386|sparc) \ + mv NUT_solaris_package.local.gz NUT_solaris_$${UNAME_P}_package@PACKAGE_VERSION@.local.gz;; \ + esac From 1baeab054d9c98a422dc4b0e997c4ebd69ff5053 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 14:57:47 +0100 Subject: [PATCH 031/165] Sanitize Solaris packaging scripts some more --- configure.ac | 4 ++- scripts/Solaris/postinstall.in | 51 +++++++++++++++++----------------- scripts/Solaris/postremove | 14 ---------- scripts/Solaris/postremove.in | 14 ++++++++++ scripts/Solaris/preinstall | 15 ---------- scripts/Solaris/preinstall.in | 22 +++++++++++++++ scripts/Solaris/preremove.in | 1 + 7 files changed, 65 insertions(+), 56 deletions(-) mode change 100644 => 100755 scripts/Solaris/postinstall.in delete mode 100755 scripts/Solaris/postremove create mode 100755 scripts/Solaris/postremove.in delete mode 100755 scripts/Solaris/preinstall create mode 100755 scripts/Solaris/preinstall.in mode change 100644 => 100755 scripts/Solaris/preremove.in diff --git a/configure.ac b/configure.ac index 4d6456f567..97fd621426 100644 --- a/configure.ac +++ b/configure.ac @@ -1676,9 +1676,11 @@ AC_OUTPUT([ scripts/Solaris/svc-nut-client scripts/Solaris/Makefile scripts/Solaris/pkginfo + scripts/Solaris/preinstall scripts/Solaris/postinstall scripts/Solaris/preremove - scripts/Solaris/nut + scripts/Solaris/postremove + scripts/Solaris/nut scripts/udev/Makefile scripts/udev/nut-ipmipsu.rules scripts/udev/nut-usbups.rules diff --git a/scripts/Solaris/postinstall.in b/scripts/Solaris/postinstall.in old mode 100644 new mode 100755 index 136e07719c..90303cf332 --- a/scripts/Solaris/postinstall.in +++ b/scripts/Solaris/postinstall.in @@ -5,56 +5,56 @@ NUT_DIR="@prefix@" # make sure the nut user exists and has correct memberships -res=`getent group nut` +res="`getent group @RUN_AS_GROUP@`" || res="" if [ -z "$res" ]; then - groupadd nut + /usr/sbin/groupadd "@RUN_AS_GROUP@" fi -res=`getent passwd nut` +res="`getent passwd @RUN_AS_USER@`" || res="" if [ -z "$res" ]; then - useradd -g nut -G root -d ${NUT_DIR}/bin nut + /usr/sbin/useradd -c "Network UPS Tools" -g "@RUN_AS_GROUP@" -G root -d "@STATEPATH@" -s /bin/false @RUN_AS_USER@ fi -res=`groups nut | grep -w nut` +res="`groups "@RUN_AS_GROUP@" | grep -w "@RUN_AS_USER@"`" || res="" if [ -z "$res" ]; then - usermod -g nut -G root nut + /usr/sbin/usermod -g "@RUN_AS_GROUP@" -G root "@RUN_AS_USER@" fi # make sure that conffiles are secured and have the correct ownerships -if [ -d @CONFPATH@ ] ; then - chown root:nut @CONFPATH@ +if [ -d "@CONFPATH@" ] ; then + chown "root:@RUN_AS_GROUP@" "@CONFPATH@" fi -for file in nut.conf ups.conf upsd.conf upsmon.conf upsd.users upssched.conf; do - if [ -f @CONFPATH@/$file ] ; then - chown root:nut @CONFPATH@/$file - chmod 640 @CONFPATH@/$file +for file in nut.conf ups.conf upsd.conf upsmon.conf upsd.users upssched.conf nut-driver-enumerator.conf; do + if [ -f "@CONFPATH@/$file" ] ; then + chown "root:@RUN_AS_GROUP@" "@CONFPATH@/$file" + chmod 640 "@CONFPATH@/$file" fi done # make sure that /var/run/nut exists and has the correct ownerships -if [ ! -d @PIDPATH@/nut ] ; then - mkdir -p @PIDPATH@/nut +if [ ! -d "@PIDPATH@/nut" ] ; then + mkdir -p "@PIDPATH@/nut" fi -if [ -d @PIDPATH@/nut ] ; then - chown root:nut @PIDPATH@/nut - chmod 770 @PIDPATH@/nut +if [ -d "@PIDPATH@/nut" ] ; then + chown "root:@RUN_AS_GROUP@" "@PIDPATH@/nut" + chmod 770 "@PIDPATH@/nut" fi # make sure that /var/state/ups exists and has the correct ownerships -if [ ! -d @STATEPATH@ ] ; then - mkdir -p @STATEPATH@ +if [ ! -d "@STATEPATH@" ] ; then + mkdir -p "@STATEPATH@" fi -if [ -d @STATEPATH@ ] ; then - chown root:nut @STATEPATH@ - chmod 770 @STATEPATH@ +if [ -d "@STATEPATH@" ] ; then + chown "root:@RUN_AS_GROUP@" "@STATEPATH@" + chmod 770 "@STATEPATH@" fi # Put init script in /etc/init.d -cp $NUT_DIR/nut /etc/init.d +cp "$NUT_DIR/nut" /etc/init.d chmod 744 /etc/init.d/nut -ln -s /etc/init.d/nut /etc/rc3.d/S100nut > /dev/null 2>&1 -ln -s /etc/init.d/nut /etc/rc3.d/K100nut > /dev/null 2>&1 +ln -s ../init.d/nut /etc/rc3.d/S90nut > /dev/null 2>&1 +ln -s ../init.d/nut /etc/rc3.d/K10nut > /dev/null 2>&1 # Start nut services @@ -62,4 +62,3 @@ ln -s /etc/init.d/nut /etc/rc3.d/K100nut > /dev/null 2>&1 #$NUT_DIR/sbin/upsdrvctl start #> /dev/null 2>&1 #$NUT_DIR/sbin/upsd #> /dev/null 2>&1 #$NUT_DIR/sbin/upsmon #> /dev/null 2>&1 - diff --git a/scripts/Solaris/postremove b/scripts/Solaris/postremove deleted file mode 100755 index 99a0842bc3..0000000000 --- a/scripts/Solaris/postremove +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -# Remove nut group and user - -/usr/sbin/userdel nut - -/usr/sbin/groupdel nut - -# Remove init script from /etc/init.d - -rm /etc/init.d/nut -rm /etc/rc3.d/S100nut -rm /etc/rc3.d/K100nut - diff --git a/scripts/Solaris/postremove.in b/scripts/Solaris/postremove.in new file mode 100755 index 0000000000..ae46515c37 --- /dev/null +++ b/scripts/Solaris/postremove.in @@ -0,0 +1,14 @@ +#!/bin/sh + +# Remove nut group and user + +/usr/sbin/userdel "@RUN_AS_USER@" + +/usr/sbin/groupdel "@RUN_AS_GROUP@" + +# Remove init script from /etc/init.d - created by scripts not packaging + +rm /etc/init.d/nut +rm /etc/rc3.d/S90nut +rm /etc/rc3.d/K10nut + diff --git a/scripts/Solaris/preinstall b/scripts/Solaris/preinstall deleted file mode 100755 index a63ade7c5f..0000000000 --- a/scripts/Solaris/preinstall +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -# Create group nut - -grep -w "nut" /etc/group -if [ $? -eq 1 ]; then - /usr/sbin/groupadd nut -fi - -# Create user for installing "Network UPS Tools" - -grep -w "nut" /etc/passwd -if [ $? -eq 1 ]; then - /usr/sbin/useradd -c "Network UPS Tools" -d /export/home/nut -m nut -fi diff --git a/scripts/Solaris/preinstall.in b/scripts/Solaris/preinstall.in new file mode 100755 index 0000000000..b3156db566 --- /dev/null +++ b/scripts/Solaris/preinstall.in @@ -0,0 +1,22 @@ +#!/bin/sh + +NUT_DIR="@prefix@" + +# Create group nut + +grep -w "@RUN_AS_GROUP@" /etc/group +if [ "$?" != 0 ]; then + /usr/sbin/groupadd "@RUN_AS_GROUP@" +fi + +# Create user for installing "Network UPS Tools" + +grep -w "@RUN_AS_USER@" /etc/passwd +if [ "$?" != 0 ]; then + /usr/sbin/useradd -c "Network UPS Tools" -g "@RUN_AS_GROUP@" -G root -d "@STATEPATH@" -s /bin/false "@RUN_AS_USER@" +fi + +res="`groups "@RUN_AS_GROUP@" | grep -w "@RUN_AS_USER@"`" || res="" +if [ -z "$res" ]; then + /usr/sbin/usermod -g "@RUN_AS_GROUP@" -G root "@RUN_AS_USER@" +fi diff --git a/scripts/Solaris/preremove.in b/scripts/Solaris/preremove.in old mode 100644 new mode 100755 index dc4a1a19b7..dc1ae04c5e --- a/scripts/Solaris/preremove.in +++ b/scripts/Solaris/preremove.in @@ -6,3 +6,4 @@ NUT_DIR="@prefix@" #$NUT_DIR/sbin/upsdrvctl stop +# TODO: Unconfigure SMF services From 46a326d3e19a9b84d3484058dc024aa40cca4554 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 14:58:21 +0100 Subject: [PATCH 032/165] Add configure options for Solaris packaging variants --- configure.ac | 56 +++++++++++++++++++++++++++++++++++++ scripts/Solaris/Makefile.am | 17 ++++++++--- 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 97fd621426..f6919fe277 100644 --- a/configure.ac +++ b/configure.ac @@ -1209,6 +1209,62 @@ fi AC_MSG_RESULT([${solarissmf}]) AM_CONDITIONAL(WITH_SOLARIS_SMF, test x"$solarissmf" = x"yes") +AC_MSG_CHECKING(whether to make Solaris SVR4 packages) +solarispkg_svr4="auto" +AC_ARG_WITH([solaris-pkg-svr4], + AS_HELP_STRING([--with-solaris-pkg-svr4=(yes|auto|no)], [Enable construction of Solaris SVR4 packages (auto)]), +[ + case "${withval}" in + auto|"") + solarispkg_svr4="auto" + ;; + yes|no) + solarispkg_svr4="${withval}" + ;; + *) + AC_MSG_ERROR([Unexpected argument for --with-solaris-pkg-svr4=${withval}]) + ;; + esac +], []) + +if test x"$solarispkg_svr4" = xauto ; then + if test -x /usr/bin/pkgtrans && test -x /usr/bin/pkgmk && test -x /usr/bin/pkgproto ; then + solarispkg_svr4="yes" + else + solarispkg_svr4="no" + fi +fi +AC_MSG_RESULT([${solarispkg_svr4}]) +AM_CONDITIONAL(WITH_SOLARIS_PKG_SVR4, test x"$solarispkg_svr4" = x"yes") + +AC_MSG_CHECKING(whether to make Solaris IPS packages) +solarispkg_ips="auto" +AC_ARG_WITH([solaris-pkg-ips], + AS_HELP_STRING([--with-solaris-pkg-ips=(yes|auto|no)], [Enable construction of Solaris IPS packages (auto)]), +[ + case "${withval}" in + auto|"") + solarispkg_ips="auto" + ;; + yes|no) + solarispkg_ips="${withval}" + ;; + *) + AC_MSG_ERROR([Unexpected argument for --with-solaris-pkg-ips=${withval}]) + ;; + esac +], []) + +if test x"$solarispkg_ips" = xauto ; then + if test -x /usr/bin/pkg && test -x /usr/bin/pkgmogrify && test -x /usr/bin/pkgdepend ; then + solarispkg_ips="yes" + else + solarispkg_ips="no" + fi +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_ARG_WITH([systemdsystemunitdir], AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files (auto)]), diff --git a/scripts/Solaris/Makefile.am b/scripts/Solaris/Makefile.am index 5fc8dc5180..011f0cc058 100644 --- a/scripts/Solaris/Makefile.am +++ b/scripts/Solaris/Makefile.am @@ -14,13 +14,19 @@ solarissmfmanifest_DATA = \ nut-driver-enumerator.xml endif +SOLARIS_PACKAGE_TARGETS = + # TODO: Define support for IPS packaging -if WITH_SOLARIS_IPS -package: package-ips -else -package: package-svr4 +if WITH_SOLARIS_PKG_IPS +SOLARIS_PACKAGE_TARGETS += package-ips +endif + +if WITH_SOLARIS_PKG_SVR4 +SOLARIS_PACKAGE_TARGETS += package-svr4 endif +package: $(SOLARIS_PACKAGE_TARGETS) + package-svr4: makelocal.sh pkginfo cd @prefix@ && find . -print | pkgproto > prototype1 cp makelocal.sh precheck.py pkginfo nut preinstall postinstall preremove postremove preproto.pl @prefix@ @@ -33,3 +39,6 @@ package-svr4: makelocal.sh pkginfo i386|sparc) \ mv NUT_solaris_package.local.gz NUT_solaris_$${UNAME_P}_package@PACKAGE_VERSION@.local.gz;; \ esac + +package-ips: + @echo "Target $@ is not implemented yet" From 7bd7ff6f6bb85eb75594bcc50a3a79a69598f2c1 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 15:07:26 +0100 Subject: [PATCH 033/165] Sanitize Solaris packaging scripts some more - consider DESTDIR for installation root --- Makefile.am | 4 ++-- scripts/Solaris/Makefile.am | 24 +++++++++++++-------- scripts/systemd/nut-driver-enumerator.sh.in | 10 +++++++-- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Makefile.am b/Makefile.am index 7c35d2e124..010ae90e2a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -145,12 +145,12 @@ package: mv NUT_HPUX_package.depot NUT_HPUX_package@PACKAGE_VERSION@.depot; \ elif test `uname -s` = "SunOS"; then \ make; \ - rm -rf @prefix@; \ + rm -rf $(DESTDIR)@prefix@; \ make install; \ cd scripts/Solaris; \ make package; \ make uninstall; \ - rm -rf @prefix@; \ + rm -rf $(DESTDIR)@prefix@; \ elif test `uname -s` = "AIX"; then \ make dist; \ cp scripts/Aix/nut-aix.spec /usr/src/packages/SPECS; \ diff --git a/scripts/Solaris/Makefile.am b/scripts/Solaris/Makefile.am index 011f0cc058..75afeb8192 100644 --- a/scripts/Solaris/Makefile.am +++ b/scripts/Solaris/Makefile.am @@ -1,4 +1,5 @@ -EXTRA_DIST = makelocal.sh +EXTRA_DIST = makelocal.sh +PROTOTYPE_DIR = $(DESTDIR)@prefix@ if WITH_SOLARIS_SMF solarissmfmethoddir = /lib/svc/method @@ -27,17 +28,22 @@ endif package: $(SOLARIS_PACKAGE_TARGETS) +# TODO: Reduce build dependencies (implicit!) on python and perl +# by shelling the scripts used below +# NOTE: This assumes the rest of the product has already been built +# and installed under PROTOTYPE_DIR, but declares no explicit +# dependency on that package-svr4: makelocal.sh pkginfo - cd @prefix@ && find . -print | pkgproto > prototype1 - cp makelocal.sh precheck.py pkginfo nut preinstall postinstall preremove postremove preproto.pl @prefix@ - cd @prefix@ && perl preproto.pl - cd @prefix@ && python precheck.py - cd @prefix@ && rm -f prototype1 - cd @prefix@ && ./makelocal.sh - cp @prefix@/*.gz $(srcdir) + cd $(PROTOTYPE_DIR) && find . -print | pkgproto > prototype1 + cp makelocal.sh precheck.py pkginfo nut preinstall postinstall preremove postremove preproto.pl $(PROTOTYPE_DIR) + cd $(PROTOTYPE_DIR) && perl preproto.pl + cd $(PROTOTYPE_DIR) && python precheck.py + cd $(PROTOTYPE_DIR) && rm -f prototype1 + cd $(PROTOTYPE_DIR) && ./makelocal.sh + cp $(PROTOTYPE_DIR)/*.gz $(srcdir) UNAME_P="`uname -p`" && case "$${UNAME_P}" in \ i386|sparc) \ - mv NUT_solaris_package.local.gz NUT_solaris_$${UNAME_P}_package@PACKAGE_VERSION@.local.gz;; \ + mv NUT_solaris_package.local.gz "NUT_solaris_$${UNAME_P}_package@PACKAGE_VERSION@.local.gz" ;; \ esac package-ips: diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index db631c0212..755eb7af8d 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -32,7 +32,11 @@ # now the caller should likely restart some services. # Note that the drivers' service instances were started or # stopped as required (by AUTO_START=yes) - but maybe the -# upsd or upsmon services should restart. +# upsd or upsmon services should restart. If you pass envvar +# REPORT_RESTART_42=no then this codepath would return 0. +# In default mode, such non-null reconfiguration should cause +# the nut-driver-enumerator service to restart and this would +# propagate to other NUT services that depend on it. # 13 Sections and services differed, and still do not match up # 1 Bad inputs, e.g. unrecognized service management framework # 2 Absent or unreadable ups.conf file @@ -409,5 +413,7 @@ fi # Return 42 if there was a change applied succesfully # (but e.g. some services should restart - upsd, maybe upsmon) -[ "$UPSLIST_FILE" = "$UPSLIST_SVCS" ] && return 42 +if [ "$UPSLIST_FILE" = "$UPSLIST_SVCS" ] ; then + [ "${REPORT_RESTART_42-}" = no ] && return 0 || return 42 +fi exit 13 From 3adf6a5e93736d999dc7e6d59fdc767bd1bd9e3e Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 18:29:53 +0100 Subject: [PATCH 034/165] Solaris-SMF : svc-nut.in svc-nut-client.in : use @RUN_AS_*@ and @PIDPATH@ vars instead of hardcoding --- scripts/Solaris/svc-nut-client.in | 6 +++--- scripts/Solaris/svc-nut.in | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/Solaris/svc-nut-client.in b/scripts/Solaris/svc-nut-client.in index 2e3283afc2..d5ac6f2724 100755 --- a/scripts/Solaris/svc-nut-client.in +++ b/scripts/Solaris/svc-nut-client.in @@ -14,9 +14,9 @@ fi NUT_DIR="@prefix@" NUT_SBIN_DIR="$NUT_DIR/sbin" -NUT_RUN_DIR="/var/run/nut" -NUTUSER="nut" -NUTGROUP="nut" +NUT_RUN_DIR="@PIDPATH@/nut" +NUTUSER="@RUN_AS_USER@" +NUTGROUP="@RUN_AS_GROUP@" ups_start () { if [ "$MODE" = "none" ];then diff --git a/scripts/Solaris/svc-nut.in b/scripts/Solaris/svc-nut.in index 2ff8eb7386..82de7d1721 100755 --- a/scripts/Solaris/svc-nut.in +++ b/scripts/Solaris/svc-nut.in @@ -14,9 +14,9 @@ fi NUT_DIR="/usr" NUT_SBIN_DIR="$NUT_DIR/sbin" -NUT_RUN_DIR="/var/run/nut" -NUTUSER="nut" -NUTGROUP="nut" +NUT_RUN_DIR="@PIDPATH@/nut" +NUTUSER="@RUN_AS_USER@" +NUTGROUP="@RUN_AS_GROUP@" ups_start () { # Default rights inspired by NUT scripts/Solaris/postinstall.in From a4f016301475b74ff01bd294d3021571aaaa5e73 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 20:24:02 +0100 Subject: [PATCH 035/165] svc-nut.in svc-nut-client.in : consider nut.conf if available --- scripts/Solaris/svc-nut-client.in | 5 +++++ scripts/Solaris/svc-nut.in | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/scripts/Solaris/svc-nut-client.in b/scripts/Solaris/svc-nut-client.in index d5ac6f2724..267d004d23 100755 --- a/scripts/Solaris/svc-nut-client.in +++ b/scripts/Solaris/svc-nut-client.in @@ -15,9 +15,14 @@ fi NUT_DIR="@prefix@" NUT_SBIN_DIR="$NUT_DIR/sbin" NUT_RUN_DIR="@PIDPATH@/nut" +CONFIG="@CONFPATH@/nut.conf" NUTUSER="@RUN_AS_USER@" NUTGROUP="@RUN_AS_GROUP@" +if [ -f "$CONFIG" ] ; then + . "$CONFIG" +fi + ups_start () { if [ "$MODE" = "none" ];then echo "No NUT mode set" >&2 diff --git a/scripts/Solaris/svc-nut.in b/scripts/Solaris/svc-nut.in index 82de7d1721..309720d373 100755 --- a/scripts/Solaris/svc-nut.in +++ b/scripts/Solaris/svc-nut.in @@ -15,9 +15,14 @@ fi NUT_DIR="/usr" NUT_SBIN_DIR="$NUT_DIR/sbin" NUT_RUN_DIR="@PIDPATH@/nut" +CONFIG="@CONFPATH@/nut.conf" NUTUSER="@RUN_AS_USER@" NUTGROUP="@RUN_AS_GROUP@" +if [ -f "$CONFIG" ] ; then + . "$CONFIG" +fi + ups_start () { # Default rights inspired by NUT scripts/Solaris/postinstall.in mkdir -p "$NUT_RUN_DIR" && \ From 633ea2eb0ef81aeaf03127125777471d217b7b84 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 19:49:52 +0100 Subject: [PATCH 036/165] Solaris/nut.in : sanitize the default init-script --- scripts/Solaris/nut.in | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) mode change 100644 => 100755 scripts/Solaris/nut.in diff --git a/scripts/Solaris/nut.in b/scripts/Solaris/nut.in old mode 100644 new mode 100755 index ab7ec94efa..587c77c15b --- a/scripts/Solaris/nut.in +++ b/scripts/Solaris/nut.in @@ -3,29 +3,30 @@ #init.d script to start nut services NUT_DIR="@prefix@" -CONFIG=$NUT_DIR/etc/nut.conf +NUT_SBIN_DIR="${NUT_DIR}/sbin" +CONFIG="@CONFPATH@/nut.conf" -if [ -f $CONFIG ] ; then - . $CONFIG +if [ -f "$CONFIG" ] ; then + . "$CONFIG" fi ups_stop () { pkill -n upsmon pkill -n upsd - ${NUT_DIR}/sbin/upsdrvctl stop > /dev/null 2>&1 + "${NUT_SBIN_DIR}/upsdrvctl" stop > /dev/null 2>&1 } ups_start () { if [ "$MODE" = "none" ];then - echo No mode set + echo "No NUT mode set, not starting anything" >&2 exit 1 fi - if [ ! "$MODE" = "netclient" ];then - $NUT_DIR/sbin/upsdrvctl start #> /dev/null 2>&1 - $NUT_DIR/sbin/upsd #> /dev/null 2>&1 + if [ "$MODE" != "netclient" ] ; then + "${NUT_SBIN_DIR}/upsdrvctl" start #> /dev/null 2>&1 + "${NUT_SBIN_DIR}/upsd" #> /dev/null 2>&1 fi - $NUT_DIR/sbin/upsmon #> /dev/null 2>&1 + "${NUT_SBIN_DIR}/upsmon" #> /dev/null 2>&1 } case $1 in @@ -46,10 +47,11 @@ case $1 in ups_start ;; 'poweroff') - $NUT_DIR/sbin/upsmon -K >/dev/null 2>&1 + "${NUT_SBIN_DIR}/upsmon" -K >/dev/null 2>&1 if [ $? = 0 ]; then - echo "Shutting down the UPS ..." - #$NUT_DIR/sbin/upsdrvctl shutdown + echo "Shutting down the UPS(es) ..." + echo "WARNING: UPS shutdown is currently disabled, please uncomment it in the init-script if desired" >&2 + #${NUT_SBIN_DIR}/upsdrvctl shutdown fi ;; *) @@ -57,7 +59,7 @@ case $1 in echo "Usage: '$0' {start | stop | restart }" echo "" exit 64 - ;; + ;; esac exit $? From 40e643ace1d067b465caa665a0a56777eef8d734 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 17:14:57 +0100 Subject: [PATCH 037/165] Turn solaris preproto.pl into a template so it uses proper (configured) user/group strings --- configure.ac | 1 + scripts/Solaris/.gitignore | 1 + scripts/Solaris/{preproto.pl => preproto.pl.in} | 6 ++++-- 3 files changed, 6 insertions(+), 2 deletions(-) rename scripts/Solaris/{preproto.pl => preproto.pl.in} (86%) diff --git a/configure.ac b/configure.ac index f6919fe277..62b301ac91 100644 --- a/configure.ac +++ b/configure.ac @@ -1736,6 +1736,7 @@ AC_OUTPUT([ scripts/Solaris/postinstall scripts/Solaris/preremove scripts/Solaris/postremove + scripts/Solaris/preproto.pl scripts/Solaris/nut scripts/udev/Makefile scripts/udev/nut-ipmipsu.rules diff --git a/scripts/Solaris/.gitignore b/scripts/Solaris/.gitignore index b74faaea0d..b0f5c7fa44 100644 --- a/scripts/Solaris/.gitignore +++ b/scripts/Solaris/.gitignore @@ -4,6 +4,7 @@ /postinstall /preremove /postremove +/preproto.pl /svc-nut /svc-nut-client /nut-driver.xml diff --git a/scripts/Solaris/preproto.pl b/scripts/Solaris/preproto.pl.in similarity index 86% rename from scripts/Solaris/preproto.pl rename to scripts/Solaris/preproto.pl.in index 5068859704..5e60e7f330 100755 --- a/scripts/Solaris/preproto.pl +++ b/scripts/Solaris/preproto.pl.in @@ -8,6 +8,8 @@ $postinstall = "postinstall"; $preremove = "preremove"; $postremove = "postremove"; +$nutuser = "@RUN_AS_USER@"; +$nutgroup = "@RUN_AS_GROUP@"; open (PREPROTO,"< $temp") || die "Unable to read prototype information ($!)\n"; open (PROTO,"> $prototype") || die "Unable to write file prototype ($!)\n"; @@ -26,12 +28,12 @@ } elsif ($thisline =~ "^[fd] ") { # Change the ownership for files and directories ($dir, $none, $file, $mode, $user, $group) = split / /,$thisline; - print PROTO "$dir $none $file=$file $mode nut nut\n"; + print PROTO "$dir $none $file=$file $mode $nutuser $nutgroup\n"; } else { # Symlinks and other stuff should be printed as well ofcourse print PROTO "$thisline\n"; } } -print PROTO "f $none nut $mode root nut\n"; +print PROTO "f $none nut $mode root $nutgroup\n"; close PROTO; close PREPROTO; From 3b884af75a1a00e09a9677fa2b96864d40b7ca53 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 17:31:32 +0100 Subject: [PATCH 038/165] Makefile.am : use $(MAKE) $(AM_MAKEFLAGS) instead of explicit "make" (mostly in packaging recipe) --- Makefile.am | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile.am b/Makefile.am index 010ae90e2a..2168783b47 100644 --- a/Makefile.am +++ b/Makefile.am @@ -121,7 +121,7 @@ install-dirs: @echo "Warning: 'make install-dirs' is deprecated." @echo "Use 'make installdirs' instead." @echo $(WARN) - make installdirs + $(MAKE) installdirs cgi build-cgi install-cgi install-cgi-dir install-cgi-bin \ install-cgi-man install-cgi-conf install-cgi-html: @echo "Error: 'make $@' no longer exists." @@ -141,18 +141,18 @@ setver: package: if test `uname -s` = "HP-UX"; then \ cd scripts/HP-UX; \ - make package; \ + $(MAKE) $(AM_MAKEFLAGS) package; \ mv NUT_HPUX_package.depot NUT_HPUX_package@PACKAGE_VERSION@.depot; \ elif test `uname -s` = "SunOS"; then \ - make; \ + $(MAKE) $(AM_MAKEFLAGS); \ rm -rf $(DESTDIR)@prefix@; \ - make install; \ + $(MAKE) $(AM_MAKEFLAGS) install; \ cd scripts/Solaris; \ - make package; \ - make uninstall; \ + $(MAKE) $(AM_MAKEFLAGS) package; \ + $(MAKE) $(AM_MAKEFLAGS) uninstall; \ rm -rf $(DESTDIR)@prefix@; \ elif test `uname -s` = "AIX"; then \ - make dist; \ + $(MAKE) $(AM_MAKEFLAGS) dist; \ cp scripts/Aix/nut-aix.spec /usr/src/packages/SPECS; \ cp scripts/Aix/nut.init nut-@PACKAGE_VERSION@.tar.gz /usr/src/packages/SOURCES; \ rpm -ba /usr/src/packages/SPECS/nut-aix.spec; \ From 6aaa44e5854623dc97f7b18ec47c98542321433a Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 17:29:35 +0100 Subject: [PATCH 039/165] Makefile.am : ensure there is a DESTDIR set before packaging --- Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.am b/Makefile.am index 2168783b47..e30a9ad06e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -139,6 +139,7 @@ setver: @echo "Error: 'make setver' no longer exists." @echo "Edit configure.in to set version number." package: + if test -z "$$DESTDIR" ; then DESTDIR="$(abs_builddir)/_install_pkgprotodir" ; fi ; export DESTDIR; \ if test `uname -s` = "HP-UX"; then \ cd scripts/HP-UX; \ $(MAKE) $(AM_MAKEFLAGS) package; \ From a2aad0f22700bed2a30a994c5bf920511c159f82 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 17:46:28 +0100 Subject: [PATCH 040/165] Makefile.am : ensure the DESTDIR is used for packaging purposes (when calling sub-makes) --- Makefile.am | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index e30a9ad06e..a6855c332b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -142,15 +142,15 @@ package: if test -z "$$DESTDIR" ; then DESTDIR="$(abs_builddir)/_install_pkgprotodir" ; fi ; export DESTDIR; \ if test `uname -s` = "HP-UX"; then \ cd scripts/HP-UX; \ - $(MAKE) $(AM_MAKEFLAGS) package; \ + $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$DESTDIR" package; \ mv NUT_HPUX_package.depot NUT_HPUX_package@PACKAGE_VERSION@.depot; \ elif test `uname -s` = "SunOS"; then \ $(MAKE) $(AM_MAKEFLAGS); \ rm -rf $(DESTDIR)@prefix@; \ - $(MAKE) $(AM_MAKEFLAGS) install; \ + $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$DESTDIR" install; \ cd scripts/Solaris; \ - $(MAKE) $(AM_MAKEFLAGS) package; \ - $(MAKE) $(AM_MAKEFLAGS) uninstall; \ + $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$DESTDIR" package; \ + $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$DESTDIR" uninstall; \ rm -rf $(DESTDIR)@prefix@; \ elif test `uname -s` = "AIX"; then \ $(MAKE) $(AM_MAKEFLAGS) dist; \ From a79958d160843c87f8fc912427a9f3a579c9646e Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 17:57:33 +0100 Subject: [PATCH 041/165] Makefile.am : ensure only the custom DESTDIR is used for packaging purposes --- Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index a6855c332b..fa1c91f8ce 100644 --- a/Makefile.am +++ b/Makefile.am @@ -139,7 +139,7 @@ setver: @echo "Error: 'make setver' no longer exists." @echo "Edit configure.in to set version number." package: - if test -z "$$DESTDIR" ; then DESTDIR="$(abs_builddir)/_install_pkgprotodir" ; fi ; export DESTDIR; \ + DESTDIR="$(abs_builddir)/_install_pkgprotodir" ; export DESTDIR; \ if test `uname -s` = "HP-UX"; then \ cd scripts/HP-UX; \ $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$DESTDIR" package; \ From cc44fa64e6f225bf3255a9e880681d750ce3ef5f Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 17:59:35 +0100 Subject: [PATCH 042/165] Makefile.am : convert the big packaging "if" into "case"; link steps with "&&"; retain DESTDIR if Solaris packaging fails; ensure the correct custom DESTDIR is absent before packaging (and after Solaris packaging) --- Makefile.am | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/Makefile.am b/Makefile.am index fa1c91f8ce..eb1c69a29c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -140,21 +140,26 @@ setver: @echo "Edit configure.in to set version number." package: DESTDIR="$(abs_builddir)/_install_pkgprotodir" ; export DESTDIR; \ - if test `uname -s` = "HP-UX"; then \ - cd scripts/HP-UX; \ - $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$DESTDIR" package; \ - mv NUT_HPUX_package.depot NUT_HPUX_package@PACKAGE_VERSION@.depot; \ - elif test `uname -s` = "SunOS"; then \ - $(MAKE) $(AM_MAKEFLAGS); \ - rm -rf $(DESTDIR)@prefix@; \ - $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$DESTDIR" install; \ - cd scripts/Solaris; \ - $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$DESTDIR" package; \ - $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$DESTDIR" uninstall; \ - rm -rf $(DESTDIR)@prefix@; \ - elif test `uname -s` = "AIX"; then \ - $(MAKE) $(AM_MAKEFLAGS) dist; \ - cp scripts/Aix/nut-aix.spec /usr/src/packages/SPECS; \ - cp scripts/Aix/nut.init nut-@PACKAGE_VERSION@.tar.gz /usr/src/packages/SOURCES; \ - rpm -ba /usr/src/packages/SPECS/nut-aix.spec; \ - fi; + rm -rf "$$DESTDIR"; \ + case "`uname -s`" in \ + "HP-UX") \ + ( cd scripts/HP-UX && \ + $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$DESTDIR" package && \ + mv NUT_HPUX_package.depot NUT_HPUX_package@PACKAGE_VERSION@.depot ) ;; \ + "SunOS") \ + $(MAKE) $(AM_MAKEFLAGS) && \ + $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$DESTDIR" install && \ + ( cd scripts/Solaris && \ + $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$DESTDIR" package ) && \ + $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$DESTDIR" uninstall && \ + rm -rf "$$DESTDIR" || \ + { echo "FAILED to produce SunOS packages, inspect '$$DESTDIR' for clues" >&2 ; exit 1; } ;; \ + "AIX") \ + if test -d /usr/src/packages/SPECS -a -w /usr/src/packages/SPECS ; then : ; else echo "Can not write to /usr/src/packages/SPECS" >&2 ; exit 1; fi ; \ + if test -d /usr/src/packages/SOURCES -a -w /usr/src/packages/SOURCES ; then : ; else echo "Can not write to /usr/src/packages/SOURCES" >&2 ; exit 1; fi ; \ + $(MAKE) $(AM_MAKEFLAGS) dist && \ + cp scripts/Aix/nut-aix.spec /usr/src/packages/SPECS && \ + cp scripts/Aix/nut.init nut-@PACKAGE_VERSION@.tar.gz /usr/src/packages/SOURCES && \ + rpm -ba /usr/src/packages/SPECS/nut-aix.spec;; \ + *) echo "Unsupported OS for 'make $@' (no recipe bound)" >&2; exit 1;; \ + esac From 32a003ad19bc22aa5f7ba23f7a4961630bd85eb0 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 17:36:55 +0100 Subject: [PATCH 043/165] makelocal.sh : commented and revised --- scripts/Solaris/makelocal.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/Solaris/makelocal.sh b/scripts/Solaris/makelocal.sh index 639e780036..f017c43cdd 100755 --- a/scripts/Solaris/makelocal.sh +++ b/scripts/Solaris/makelocal.sh @@ -1,5 +1,11 @@ #!/bin/sh -pkgmk -o -d `pwd` -pkgtrans `pwd` `pwd`/NUT_solaris_package.local -gzip `pwd`/NUT_solaris_package.local +# Creates the package file from current-directory contents +# Called by Makefile starting from installed prototype directory + +echo "Making Solaris SVR4 package metadata..." && \ +pkgmk -o -d "`pwd`" && \ +echo "Making Solaris SVR4 package archive file..." && \ +( yes "" | pkgtrans "`pwd`" "`pwd`/NUT_solaris_package.local" ) && \ +echo "Compressing Solaris SVR4 package archive file..." && \ +gzip "`pwd`/NUT_solaris_package.local" From cbf06f8c6f6b46081ba95cbf5193f12a0319ef49 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 19:24:45 +0100 Subject: [PATCH 044/165] Remove Solaris/prepackage.py (unreferenced duplicate of precheck.py) --- scripts/Solaris/prepackage.py | 37 ----------------------------------- 1 file changed, 37 deletions(-) delete mode 100755 scripts/Solaris/prepackage.py diff --git a/scripts/Solaris/prepackage.py b/scripts/Solaris/prepackage.py deleted file mode 100755 index f8d987b36b..0000000000 --- a/scripts/Solaris/prepackage.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env python - -import sys -import commands - -# checkinstall script creation - -platform = commands.getoutput('uname -s') -architecture = commands.getoutput('uname -p') - -fp=open("checkinstall","w") -fp.write("#!/bin/sh\n") -fp.write("\nexpected_platform=SunOS\n") -if platform == "SunOS" and architecture == "i386": - fp.write("expected_architecture=i386\n") -elif platform == "SunOS" and architecture == "sparc": - fp.write("expected_architecture=sparc\n") - -fp.write("platform=`uname -s`\n") -fp.write("architecture=`uname -p`\n\n") - -fp.write("if [ ${platform} -eq ${expected_platform} ]; then\n") -fp.write("\tif [ ${architecture} -eq ${expected_architecture} ]; then\n") -fp.write("\t\techo \"Checkinstall complete\"\n") -fp.write("\telse\n") -fp.write("\t\techo \"This is not Solaris $architecture machine\"\n") -fp.write("\t\texit 1\n") -fp.write("\tfi\n") -fp.write("else\n") -fp.write("\techo \"This is not Solaris machine\"\n") -fp.write("\texit 1\n") -fp.write("fi\n") -fp.write("exit 0\n") - -fp.close() - - From 94cb83f724be2217aa1698203325a21a8964542c Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 20:21:54 +0100 Subject: [PATCH 045/165] Change Aix/nut.init to a .in template --- configure.ac | 1 + scripts/Aix/.gitignore | 1 + scripts/Aix/{nut.init => nut.init.in} | 0 3 files changed, 2 insertions(+) rename scripts/Aix/{nut.init => nut.init.in} (100%) diff --git a/configure.ac b/configure.ac index 62b301ac91..9b900f7fff 100644 --- a/configure.ac +++ b/configure.ac @@ -1714,6 +1714,7 @@ AC_OUTPUT([ scripts/devd/nut-usb.conf scripts/hotplug/Makefile scripts/hotplug/libhidups + scripts/Aix/nut.init scripts/HP-UX/nut.psf scripts/HP-UX/postinstall scripts/python/Makefile diff --git a/scripts/Aix/.gitignore b/scripts/Aix/.gitignore index ce505768bf..038fae6802 100644 --- a/scripts/Aix/.gitignore +++ b/scripts/Aix/.gitignore @@ -1 +1,2 @@ nut-aix.spec +nut.init diff --git a/scripts/Aix/nut.init b/scripts/Aix/nut.init.in similarity index 100% rename from scripts/Aix/nut.init rename to scripts/Aix/nut.init.in From f6c493ac73e145edc258c526623138bfbb58b197 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 21:20:14 +0100 Subject: [PATCH 046/165] Sanitize Aix/nut.init.in --- scripts/Aix/nut.init.in | 100 ++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 46 deletions(-) diff --git a/scripts/Aix/nut.init.in b/scripts/Aix/nut.init.in index a54f85899d..018777efe6 100644 --- a/scripts/Aix/nut.init.in +++ b/scripts/Aix/nut.init.in @@ -31,10 +31,19 @@ failure() { SERVER="no" CLIENT="no" -if [ -f /usr/local/ups/etc/nut.conf ]; then - . /usr/local/ups/etc/nut.conf - - case $MODE in +NUT_DIR="@prefix@" +NUT_SBIN_DIR="${NUT_DIR}/sbin" +NUT_LIB_DIR="${NUT_DIR}/lib" +NUT_RUN_DIR="@PIDPATH@/nut" +CONFIG="@CONFPATH@/nut.conf" +NUTUSER="@RUN_AS_USER@" +NUTGROUP="@RUN_AS_GROUP@" +NUT_VAR_LOCK="/var/locks/ups" + +if [ -f "$CONFIG" ] ; then + . "$CONFIG" + + case "$MODE" in standalone|netserver) SERVER="yes" ;; @@ -44,80 +53,79 @@ if [ -f /usr/local/ups/etc/nut.conf ]; then fi do_start() { + RETVAL=0 + + if [ ! -d "$NUT_RUN_DIR" ]; then + mkdir -p "$NUT_RUN_DIR" && \ + chown "root:$NUTGROUP" "$NUT_RUN_DIR" && \ + chmod 770 "$NUT_RUN_DIR" + RETVAL=$? + fi + if [ "$SERVER" = "yes" ]; then echo "Starting UPS driver controller: \c" - /usr/local/ups/sbin/upsdrvctl start >/dev/null 2>&1 && success || failure - RETVAL=$? + LD_LIBRARY_PATH="${NUT_LIB_DIR}:$LD_LIBRARY_PATH" "${NUT_SBIN_DIR}"/upsdrvctl start >/dev/null 2>&1 && success || { RETVAL=$?; failure; } echo "Starting upsd: \c" - /usr/local/ups/sbin/upsd $UPSD_OPTIONS >/dev/null 2>&1 && success || failure - if [ "$RETVAL" = 0 ]; then - RETVAL=$? - fi + LD_LIBRARY_PATH="${NUT_LIB_DIR}:$LD_LIBRARY_PATH" "${NUT_SBIN_DIR}"/upsd $UPSD_OPTIONS >/dev/null 2>&1 && success || { RETVAL=$?; failure; } fi if [ "$CLIENT" = "yes" ]; then echo "Starting UPS monitor: \c" - /usr/local/ups/sbin/upsmon >/dev/null 2>&1 && success || failure - if [ "$RETVAL" = 0 ]; then - RETVAL=$? - fi + LD_LIBRARY_PATH="${NUT_LIB_DIR}:$LD_LIBRARY_PATH" "${NUT_SBIN_DIR}"/upsmon >/dev/null 2>&1 && success || { RETVAL=$?; failure; } fi - [ "$RETVAL" = 0 ] && touch /var/locks/ups + [ "$RETVAL" = 0 ] && touch "${NUT_VAR_LOCK}" + return $RETVAL } do_stop() { - if test -e /var/run/nut/upsmon.pid; then + RETVAL=0 + if test -e "${NUT_RUN_DIR}"/upsmon.pid; then echo "Stopping UPS monitor: \c" - PID=`cat /var/run/nut/upsmon.pid` - kill $PID && success || failure - rm /var/run/nut/upsmon.pid + PID="`cat "${NUT_RUN_DIR}"/upsmon.pid`" + kill -15 $PID && success || { RETVAL=$?; failure; } + rm "${NUT_RUN_DIR}"/upsmon.pid fi if [ "$SERVER" = "yes" ]; then - if test -e /var/run/nut/upsd.pid; then + if test -e "${NUT_RUN_DIR}"/upsd.pid; then echo "Stopping upsd: \c" - PID=`cat /var/run/nut/upsd.pid` - kill -9 $PID && success || failure - rm /var/run/nut/upsd.pid + PID="`cat "${NUT_RUN_DIR}"/upsd.pid`" + kill -15 $PID && success || { RETVAL=$?; failure; } + rm "${NUT_RUN_DIR}"/upsd.pid fi - RETVAL=$? echo "Shutting down UPS driver controller: \c" - /usr/local/ups/sbin/upsdrvctl stop > /dev/null 2>&1 && success || failure - if [ "$RETVAL" = 0 ]; then - RETVAL=$? - fi + "${NUT_SBIN_DIR}"/upsdrvctl stop > /dev/null 2>&1 && success || { RETVAL=$?; failure; } fi - [ "$RETVAL" = 0 ] && rm -f /var/locks/ups + [ "$RETVAL" = 0 ] && rm -f "${NUT_VAR_LOCK}" + return $RETVAL } do_restart() { do_stop - waitmore=5 - while [ -n "$(ls /var/run/nut/)" -a $waitmore -ge 1 ] - do - sleep 1 - waitmore=$((waitmore-1)) - done + waitmore=5 + while [ -n "$(ls "${NUT_RUN_DIR}"/)" -a $waitmore -ge 1 ] + do + sleep 1 + waitmore="$(expr $waitmore - 1)" + done do_start } do_reload() { # FIXME: upsd and upsmon always return 0 # => can't tell if reload was successful + RETVAL=0 if [ "$SERVER" = "yes" ]; then echo "Reloading upsd" - /usr/local/ups/sbin/upsd -c reload - RETVAL=$? + LD_LIBRARY_PATH="${NUT_LIB_DIR}:$LD_LIBRARY_PATH" "${NUT_SBIN_DIR}"/upsd -c reload && success || { RETVAL=$?; failure; } fi echo "Reloading upsmon" - /usr/local/ups/sbin/upsmon -c reload - if [ "$RETVAL" = 0 ]; then - RETVAL=$? - fi + LD_LIBRARY_PATH="${NUT_LIB_DIR}:$LD_LIBRARY_PATH" "${NUT_SBIN_DIR}"/upsmon -c reload && success || { RETVAL=$?; failure; } + return $RETVAL } # See how we are called. @@ -132,7 +140,7 @@ case "$1" in do_restart ;; try-restart) - [ -f /var/locks/ups ] && do_restart || true + [ -f "${NUT_VAR_LOCK}" ] && do_restart || true ;; reload) @@ -143,13 +151,13 @@ case "$1" in status) if [ "$SERVER" = "yes" ]; then - if test -f /var/locks/ups; then - echo "upsd is running with PID" `cat /var/run/nut/upsd.pid` + if test -f "${NUT_VAR_LOCK}"; then + echo "upsd is running with PID" `cat "${NUT_RUN_DIR}"/upsd.pid` fi fi - if test -e /var/run/nut/upsmon.pid; then - echo "upsmon is running with PID" `cat /var/run/nut/upsmon.pid` + if test -e "${NUT_RUN_DIR}"/upsmon.pid; then + echo "upsmon is running with PID" `cat "${NUT_RUN_DIR}"/upsmon.pid` elif rpm -q nut-client >/dev/null 2>&1; then echo "upsmon isn't running" fi From edc66f334d534b3cc0ea4caf8aaecd5cf4d13f7f Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 21:27:40 +0100 Subject: [PATCH 047/165] More standardization of Solaris initscripts and SMF methods; use LD_LIBRARY_PATH to prefer NUT provided libs in case of conflicts (facilitate bundling with third-party packages) --- scripts/Solaris/nut.in | 11 ++++++----- scripts/Solaris/svc-nut-client.in | 11 ++++++----- scripts/Solaris/svc-nut.in | 20 ++++++++++++++------ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/scripts/Solaris/nut.in b/scripts/Solaris/nut.in index 587c77c15b..1c39603c37 100755 --- a/scripts/Solaris/nut.in +++ b/scripts/Solaris/nut.in @@ -4,6 +4,7 @@ NUT_DIR="@prefix@" NUT_SBIN_DIR="${NUT_DIR}/sbin" +NUT_LIB_DIR="${NUT_DIR}/lib" CONFIG="@CONFPATH@/nut.conf" if [ -f "$CONFIG" ] ; then @@ -13,7 +14,7 @@ fi ups_stop () { pkill -n upsmon pkill -n upsd - "${NUT_SBIN_DIR}/upsdrvctl" stop > /dev/null 2>&1 + LD_LIBRARY_PATH="${NUT_LIB_DIR}:$LD_LIBRARY_PATH" "${NUT_SBIN_DIR}/upsdrvctl" stop > /dev/null 2>&1 } ups_start () { @@ -23,10 +24,10 @@ ups_start () { fi if [ "$MODE" != "netclient" ] ; then - "${NUT_SBIN_DIR}/upsdrvctl" start #> /dev/null 2>&1 - "${NUT_SBIN_DIR}/upsd" #> /dev/null 2>&1 + LD_LIBRARY_PATH="${NUT_LIB_DIR}:$LD_LIBRARY_PATH" "${NUT_SBIN_DIR}/upsdrvctl" start #> /dev/null 2>&1 + LD_LIBRARY_PATH="${NUT_LIB_DIR}:$LD_LIBRARY_PATH" "${NUT_SBIN_DIR}/upsd" #> /dev/null 2>&1 fi - "${NUT_SBIN_DIR}/upsmon" #> /dev/null 2>&1 + LD_LIBRARY_PATH="${NUT_LIB_DIR}:$LD_LIBRARY_PATH" "${NUT_SBIN_DIR}/upsmon" #> /dev/null 2>&1 } case $1 in @@ -47,7 +48,7 @@ case $1 in ups_start ;; 'poweroff') - "${NUT_SBIN_DIR}/upsmon" -K >/dev/null 2>&1 + LD_LIBRARY_PATH="${NUT_LIB_DIR}:$LD_LIBRARY_PATH" "${NUT_SBIN_DIR}/upsmon" -K >/dev/null 2>&1 if [ $? = 0 ]; then echo "Shutting down the UPS(es) ..." echo "WARNING: UPS shutdown is currently disabled, please uncomment it in the init-script if desired" >&2 diff --git a/scripts/Solaris/svc-nut-client.in b/scripts/Solaris/svc-nut-client.in index 267d004d23..b338aa2c77 100755 --- a/scripts/Solaris/svc-nut-client.in +++ b/scripts/Solaris/svc-nut-client.in @@ -5,15 +5,16 @@ # Adaptation copyright (C) 2016-2017 Jim Klimov if [ -z "$SMF_FMRI" ]; then - echo "$0 must be called in SMF context!" &>2 - exit 1 + echo "$0 must be called in SMF context!" >&2 + exit 1 fi # smf(5) . /lib/svc/share/smf_include.sh || exit NUT_DIR="@prefix@" -NUT_SBIN_DIR="$NUT_DIR/sbin" +NUT_SBIN_DIR="${NUT_DIR}/sbin" +NUT_LIB_DIR="${NUT_DIR}/lib" NUT_RUN_DIR="@PIDPATH@/nut" CONFIG="@CONFPATH@/nut.conf" NUTUSER="@RUN_AS_USER@" @@ -25,7 +26,7 @@ fi ups_start () { if [ "$MODE" = "none" ];then - echo "No NUT mode set" >&2 + echo "No NUT mode set, not starting anything" >&2 exit $SMF_EXIT_ERR_CONFIG fi @@ -35,7 +36,7 @@ ups_start () { chmod 770 "$NUT_RUN_DIR" \ || exit $SMF_EXIT_ERR_FATAL - "${NUT_SBIN_DIR}"/upsmon #> /dev/null 2>&1 + LD_LIBRARY_PATH="${NUT_LIB_DIR}:$LD_LIBRARY_PATH" "${NUT_SBIN_DIR}"/upsmon #> /dev/null 2>&1 } case "$1" in diff --git a/scripts/Solaris/svc-nut.in b/scripts/Solaris/svc-nut.in index 309720d373..c018c271b0 100755 --- a/scripts/Solaris/svc-nut.in +++ b/scripts/Solaris/svc-nut.in @@ -5,15 +5,16 @@ # Adaptation copyright (C) 2016 Jim Klimov if [ -z "$SMF_FMRI" ]; then - echo "$0 must be called in SMF context!" &>2 - exit 1 + echo "$0 must be called in SMF context!" >&2 + exit 1 fi # smf(5) . /lib/svc/share/smf_include.sh || exit -NUT_DIR="/usr" +NUT_DIR="@prefix@" NUT_SBIN_DIR="$NUT_DIR/sbin" +NUT_LIB_DIR="${NUT_DIR}/lib" NUT_RUN_DIR="@PIDPATH@/nut" CONFIG="@CONFPATH@/nut.conf" NUTUSER="@RUN_AS_USER@" @@ -30,9 +31,16 @@ ups_start () { chmod 770 "$NUT_RUN_DIR" \ || exit $SMF_EXIT_ERR_FATAL - # In this distribution, UPS drivers are wrapped by service instances - #"${NUT_SBIN_DIR}"/upsdrvctl start #> /dev/null 2>&1 - "${NUT_SBIN_DIR}"/upsd #> /dev/null 2>&1 + if [ "$MODE" = "none" ];then + echo "No NUT mode set, not starting anything" >&2 + exit 1 + fi + + if [ "$MODE" != "netclient" ] ; then + # In this distribution, UPS drivers are wrapped by service instances + #LD_LIBRARY_PATH="${NUT_LIB_DIR}:$LD_LIBRARY_PATH" "${NUT_SBIN_DIR}/upsdrvctl" start #> /dev/null 2>&1 + LD_LIBRARY_PATH="${NUT_LIB_DIR}:$LD_LIBRARY_PATH" "${NUT_SBIN_DIR}/upsd" #> /dev/null 2>&1 + fi } case "$1" in From abc47a4f2c4afaba1f0448e349d58bab8c78c7a3 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 17:40:58 +0100 Subject: [PATCH 048/165] Solaris/Makefile.am : put generated SVR4 package into builddir (not srcdir that may be readonly) to match other OS recipes --- scripts/Solaris/Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/Solaris/Makefile.am b/scripts/Solaris/Makefile.am index 75afeb8192..e87637085c 100644 --- a/scripts/Solaris/Makefile.am +++ b/scripts/Solaris/Makefile.am @@ -40,10 +40,10 @@ package-svr4: makelocal.sh pkginfo cd $(PROTOTYPE_DIR) && python precheck.py cd $(PROTOTYPE_DIR) && rm -f prototype1 cd $(PROTOTYPE_DIR) && ./makelocal.sh - cp $(PROTOTYPE_DIR)/*.gz $(srcdir) + cp $(PROTOTYPE_DIR)/*.gz $(builddir) UNAME_P="`uname -p`" && case "$${UNAME_P}" in \ i386|sparc) \ - mv NUT_solaris_package.local.gz "NUT_solaris_$${UNAME_P}_package@PACKAGE_VERSION@.local.gz" ;; \ + mv -f NUT_solaris_package.local.gz "NUT_solaris_$${UNAME_P}_package@PACKAGE_VERSION@.local.gz" ;; \ esac package-ips: From 7e13c9939dc179b76992523794a0e57d9a541abb Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 17:49:27 +0100 Subject: [PATCH 049/165] Solaris/pkginfo.in : ARCH is CPU_TYPE, not OS_NAME --- scripts/Solaris/pkginfo.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Solaris/pkginfo.in b/scripts/Solaris/pkginfo.in index d99bdbec53..39667f0a79 100644 --- a/scripts/Solaris/pkginfo.in +++ b/scripts/Solaris/pkginfo.in @@ -1,6 +1,6 @@ PKG="NUT" NAME="Network UPS Tools" -ARCH="@OS_NAME@" +ARCH="@target_cpu@" VERSION="@PACKAGE_VERSION@" CATEGORY="application" VENDOR="http://www.networkupstools.org" From 43a38078e4e4b087123fd587d6387e1bb51ca633 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 17:52:15 +0100 Subject: [PATCH 050/165] GitIgnore built Solaris/NUT*.local.gz product --- scripts/Solaris/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/Solaris/.gitignore b/scripts/Solaris/.gitignore index b0f5c7fa44..4bf01c06b2 100644 --- a/scripts/Solaris/.gitignore +++ b/scripts/Solaris/.gitignore @@ -11,3 +11,4 @@ /nut-driver-enumerator.xml /nut-client.xml /nut.xml +/NUT*.local.gz From 55da630e3d8f4af6d365a46a4143a14b6579a799 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 17:55:21 +0100 Subject: [PATCH 051/165] GitIgnore built systemd files --- scripts/systemd/.gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/systemd/.gitignore b/scripts/systemd/.gitignore index 4164cd086c..c3a3fa0474 100644 --- a/scripts/systemd/.gitignore +++ b/scripts/systemd/.gitignore @@ -1,4 +1,8 @@ /nut-driver.service +/nut-driver@.service +/nut-driver.target /nut-monitor.service /nut-server.service /nutshutdown +/nut-driver-enumerator.service +/nut-driver-enumerator.sh From 5d6dd9372e848f3a39a7f86f1d3ef5195a2e9498 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 17:57:04 +0100 Subject: [PATCH 052/165] GitIgnore _install_pkgprotodir --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 27df0d4cc4..e5782962b3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ .deps/ .libs/ .inst/ +/_install_pkgprotodir/ Makefile Makefile.in ## Parent directory only From bc0ab27c16253bab01b000a7f7c9ce44c6b8bfbf Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 19:19:06 +0100 Subject: [PATCH 053/165] GitIgnore config.cache --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e5782962b3..dc2a4d997d 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ Makefile.in /config.log /config.status /config.sub +/config.cache /configure /cscope.* /depcomp From 75d5fc8e67f7a5d6d46652f7fb4ee879eda29893 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 18:18:32 +0100 Subject: [PATCH 054/165] Solaris/Makefile.am : Revise recipe-names and comments for Solaris packaging variants --- scripts/Solaris/Makefile.am | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/Solaris/Makefile.am b/scripts/Solaris/Makefile.am index e87637085c..f61580f8eb 100644 --- a/scripts/Solaris/Makefile.am +++ b/scripts/Solaris/Makefile.am @@ -17,13 +17,12 @@ endif SOLARIS_PACKAGE_TARGETS = -# TODO: Define support for IPS packaging if WITH_SOLARIS_PKG_IPS -SOLARIS_PACKAGE_TARGETS += package-ips +SOLARIS_PACKAGE_TARGETS += package-solaris-ips endif if WITH_SOLARIS_PKG_SVR4 -SOLARIS_PACKAGE_TARGETS += package-svr4 +SOLARIS_PACKAGE_TARGETS += package-solaris-svr4 endif package: $(SOLARIS_PACKAGE_TARGETS) @@ -33,7 +32,7 @@ package: $(SOLARIS_PACKAGE_TARGETS) # NOTE: This assumes the rest of the product has already been built # and installed under PROTOTYPE_DIR, but declares no explicit # dependency on that -package-svr4: makelocal.sh pkginfo +package-solaris-svr4: makelocal.sh pkginfo cd $(PROTOTYPE_DIR) && find . -print | pkgproto > prototype1 cp makelocal.sh precheck.py pkginfo nut preinstall postinstall preremove postremove preproto.pl $(PROTOTYPE_DIR) cd $(PROTOTYPE_DIR) && perl preproto.pl @@ -46,5 +45,6 @@ package-svr4: makelocal.sh pkginfo mv -f NUT_solaris_package.local.gz "NUT_solaris_$${UNAME_P}_package@PACKAGE_VERSION@.local.gz" ;; \ esac -package-ips: - @echo "Target $@ is not implemented yet" +# TODO: Define support for IPS packaging (provide p5m files and make rules) +package-solaris-ips: + @echo "SKIPPED : Target $@ is not implemented yet" From 8682737de0a13b135c37f18565469431c6c703e0 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 18:24:18 +0100 Subject: [PATCH 055/165] Solaris/Makefile.am and *.xml.in : relocate SMF methods and manifests under NUT DATADIR to package compactly --- scripts/Solaris/Makefile.am | 6 ++++-- scripts/Solaris/nut-client.xml.in | 2 +- scripts/Solaris/nut-driver-enumerator.xml.in | 2 +- scripts/Solaris/nut.xml.in | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/Solaris/Makefile.am b/scripts/Solaris/Makefile.am index f61580f8eb..f162b7381c 100644 --- a/scripts/Solaris/Makefile.am +++ b/scripts/Solaris/Makefile.am @@ -2,8 +2,10 @@ EXTRA_DIST = makelocal.sh PROTOTYPE_DIR = $(DESTDIR)@prefix@ if WITH_SOLARIS_SMF -solarissmfmethoddir = /lib/svc/method -solarissmfmanifestdir = /var/svc/manifest/application +# OS equivalent of /lib/svc/method and /var/svc/manifest/application +# but we can just use then from this location +solarissmfmethoddir = @datadir@/solaris-smf/method +solarissmfmanifestdir = @datadir@/solaris-smf/manifest solarissmfmethod_SCRIPTS = \ ../systemd/nut-driver-enumerator.sh \ svc-nut \ diff --git a/scripts/Solaris/nut-client.xml.in b/scripts/Solaris/nut-client.xml.in index ac3399e821..8f02f0fc91 100644 --- a/scripts/Solaris/nut-client.xml.in +++ b/scripts/Solaris/nut-client.xml.in @@ -80,7 +80,7 @@ Date: Sun, 5 Mar 2017 18:36:31 +0100 Subject: [PATCH 056/165] Solaris/Makefile.am : list helper scripts and installation scripts and data in variables and depend on them in packaging; chmod +x the scripts after copying over to proto area --- scripts/Solaris/Makefile.am | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/Solaris/Makefile.am b/scripts/Solaris/Makefile.am index f162b7381c..4ceb2e8c4a 100644 --- a/scripts/Solaris/Makefile.am +++ b/scripts/Solaris/Makefile.am @@ -34,9 +34,13 @@ package: $(SOLARIS_PACKAGE_TARGETS) # NOTE: This assumes the rest of the product has already been built # and installed under PROTOTYPE_DIR, but declares no explicit # dependency on that -package-solaris-svr4: makelocal.sh pkginfo +SOLARIS_PACKAGE_SVR4_HELPERSCRIPTS = makelocal.sh precheck.py preproto.pl +SOLARIS_PACKAGE_SVR4_INSTALLSCRIPTS = preinstall postinstall preremove postremove nut +SOLARIS_PACKAGE_SVR4_INSTALLDATA = pkginfo +package-solaris-svr4: $(SOLARIS_PACKAGE_SVR4_HELPERSCRIPTS) $(SOLARIS_PACKAGE_SVR4_INSTALLSCRIPTS) $(SOLARIS_PACKAGE_SVR4_INSTALLDATA) cd $(PROTOTYPE_DIR) && find . -print | pkgproto > prototype1 - cp makelocal.sh precheck.py pkginfo nut preinstall postinstall preremove postremove preproto.pl $(PROTOTYPE_DIR) + cp $(SOLARIS_PACKAGE_SVR4_HELPERSCRIPTS) $(SOLARIS_PACKAGE_SVR4_INSTALLSCRIPTS) $(SOLARIS_PACKAGE_SVR4_INSTALLDATA) $(PROTOTYPE_DIR) + cd $(PROTOTYPE_DIR) && chmod +x $(SOLARIS_PACKAGE_SVR4_HELPERSCRIPTS) $(SOLARIS_PACKAGE_SVR4_INSTALLSCRIPTS) cd $(PROTOTYPE_DIR) && perl preproto.pl cd $(PROTOTYPE_DIR) && python precheck.py cd $(PROTOTYPE_DIR) && rm -f prototype1 From 76fbfe0f898bc03cf1f5fd975efc9790496ec33a Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 19:51:31 +0100 Subject: [PATCH 057/165] Solaris/Makefile.am : put init-scripts under NUT share (DATADIR) to package it compactly; copy to OS dirs in postinstall --- scripts/Solaris/Makefile.am | 5 ++++- scripts/Solaris/postinstall.in | 3 ++- scripts/Solaris/preproto.pl.in | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/Solaris/Makefile.am b/scripts/Solaris/Makefile.am index 4ceb2e8c4a..fc478e82a4 100644 --- a/scripts/Solaris/Makefile.am +++ b/scripts/Solaris/Makefile.am @@ -17,6 +17,9 @@ solarissmfmanifest_DATA = \ nut-driver-enumerator.xml endif +solarisinitscriptdir = @datadir@/solaris-init +solarisinitscript_SCRIPTS = nut + SOLARIS_PACKAGE_TARGETS = if WITH_SOLARIS_PKG_IPS @@ -35,7 +38,7 @@ package: $(SOLARIS_PACKAGE_TARGETS) # and installed under PROTOTYPE_DIR, but declares no explicit # dependency on that SOLARIS_PACKAGE_SVR4_HELPERSCRIPTS = makelocal.sh precheck.py preproto.pl -SOLARIS_PACKAGE_SVR4_INSTALLSCRIPTS = preinstall postinstall preremove postremove nut +SOLARIS_PACKAGE_SVR4_INSTALLSCRIPTS = preinstall postinstall preremove postremove SOLARIS_PACKAGE_SVR4_INSTALLDATA = pkginfo package-solaris-svr4: $(SOLARIS_PACKAGE_SVR4_HELPERSCRIPTS) $(SOLARIS_PACKAGE_SVR4_INSTALLSCRIPTS) $(SOLARIS_PACKAGE_SVR4_INSTALLDATA) cd $(PROTOTYPE_DIR) && find . -print | pkgproto > prototype1 diff --git a/scripts/Solaris/postinstall.in b/scripts/Solaris/postinstall.in index 90303cf332..4d50e264a3 100755 --- a/scripts/Solaris/postinstall.in +++ b/scripts/Solaris/postinstall.in @@ -50,7 +50,8 @@ fi # Put init script in /etc/init.d -cp "$NUT_DIR/nut" /etc/init.d +cp -pf "@DATADIR@/solaris-init/nut" /etc/init.d +chown root:bin /etc/init.d/nut chmod 744 /etc/init.d/nut ln -s ../init.d/nut /etc/rc3.d/S90nut > /dev/null 2>&1 diff --git a/scripts/Solaris/preproto.pl.in b/scripts/Solaris/preproto.pl.in index 5e60e7f330..ac52c16b29 100755 --- a/scripts/Solaris/preproto.pl.in +++ b/scripts/Solaris/preproto.pl.in @@ -34,6 +34,6 @@ while () { print PROTO "$thisline\n"; } } -print PROTO "f $none nut $mode root $nutgroup\n"; +#print PROTO "f $none nut $mode root $nutgroup\n"; close PROTO; close PREPROTO; From bebabc3bbf7bd385c60841b788ae3e9c5440e528 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 20:19:53 +0100 Subject: [PATCH 058/165] Makefile.am .gitignore etc. relocate successfully built package files to abs_top_builddir --- .gitignore | 4 ++++ Makefile.am | 5 +++-- scripts/Aix/nut.init.in | 0 scripts/Solaris/Makefile.am | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) mode change 100644 => 100755 scripts/Aix/nut.init.in diff --git a/.gitignore b/.gitignore index dc2a4d997d..c067fadad1 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,10 @@ common/.dirstamp # Dist /nut-*.*.*/ /nut-*.tar.gz +/nut*.rpm +/NUT*.local.gz +/NUT*.p5i +/NUT*.depot # Official dist /nut-*.tar.gz.md5 diff --git a/Makefile.am b/Makefile.am index eb1c69a29c..927ec85408 100644 --- a/Makefile.am +++ b/Makefile.am @@ -145,7 +145,7 @@ package: "HP-UX") \ ( cd scripts/HP-UX && \ $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$DESTDIR" package && \ - mv NUT_HPUX_package.depot NUT_HPUX_package@PACKAGE_VERSION@.depot ) ;; \ + mv NUT_HPUX_package.depot $(abs_top_builddir)/NUT_HPUX_package@PACKAGE_VERSION@.depot ) ;; \ "SunOS") \ $(MAKE) $(AM_MAKEFLAGS) && \ $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$DESTDIR" install && \ @@ -160,6 +160,7 @@ package: $(MAKE) $(AM_MAKEFLAGS) dist && \ cp scripts/Aix/nut-aix.spec /usr/src/packages/SPECS && \ cp scripts/Aix/nut.init nut-@PACKAGE_VERSION@.tar.gz /usr/src/packages/SOURCES && \ - rpm -ba /usr/src/packages/SPECS/nut-aix.spec;; \ + rpm -ba /usr/src/packages/SPECS/nut-aix.spec && \ + mv /usr/src/packages/RPMS/nut*rpm $(abs_top_builddir)/ ;; \ *) echo "Unsupported OS for 'make $@' (no recipe bound)" >&2; exit 1;; \ esac diff --git a/scripts/Aix/nut.init.in b/scripts/Aix/nut.init.in old mode 100644 new mode 100755 diff --git a/scripts/Solaris/Makefile.am b/scripts/Solaris/Makefile.am index fc478e82a4..f3caf30b16 100644 --- a/scripts/Solaris/Makefile.am +++ b/scripts/Solaris/Makefile.am @@ -51,7 +51,7 @@ package-solaris-svr4: $(SOLARIS_PACKAGE_SVR4_HELPERSCRIPTS) $(SOLARIS_PACKAGE_SV cp $(PROTOTYPE_DIR)/*.gz $(builddir) UNAME_P="`uname -p`" && case "$${UNAME_P}" in \ i386|sparc) \ - mv -f NUT_solaris_package.local.gz "NUT_solaris_$${UNAME_P}_package@PACKAGE_VERSION@.local.gz" ;; \ + mv -f NUT_solaris_package.local.gz "$(abs_top_builddir)/NUT_solaris_$${UNAME_P}_package@PACKAGE_VERSION@.local.gz" ;; \ esac # TODO: Define support for IPS packaging (provide p5m files and make rules) From cf90b67d0e7f9b1784cec1391c6c18ed6390efac Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 20:58:33 +0100 Subject: [PATCH 059/165] Solaris/Makefile.am and SVR4 scripts : install augeas lenses as part of NUT package (in DATADIR at least) --- scripts/Solaris/Makefile.am | 4 ++++ scripts/Solaris/postinstall.in | 4 ++++ scripts/Solaris/preremove.in | 6 +++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/scripts/Solaris/Makefile.am b/scripts/Solaris/Makefile.am index f3caf30b16..dee8133bef 100644 --- a/scripts/Solaris/Makefile.am +++ b/scripts/Solaris/Makefile.am @@ -41,6 +41,10 @@ SOLARIS_PACKAGE_SVR4_HELPERSCRIPTS = makelocal.sh precheck.py preproto.pl SOLARIS_PACKAGE_SVR4_INSTALLSCRIPTS = preinstall postinstall preremove postremove SOLARIS_PACKAGE_SVR4_INSTALLDATA = pkginfo package-solaris-svr4: $(SOLARIS_PACKAGE_SVR4_HELPERSCRIPTS) $(SOLARIS_PACKAGE_SVR4_INSTALLSCRIPTS) $(SOLARIS_PACKAGE_SVR4_INSTALLDATA) + if test -n "@auglensdir@" && test -d "$(DESTDIR)@auglensdir@" ; then \ + mkdir -p "$(DESTDIR)@datadir@/augeas-lenses" && \ + cd "$(DESTDIR)@auglensdir@" && \ + cp -prf ./ "$(DESTDIR)@datadir@/augeas-lenses/" ; fi cd $(PROTOTYPE_DIR) && find . -print | pkgproto > prototype1 cp $(SOLARIS_PACKAGE_SVR4_HELPERSCRIPTS) $(SOLARIS_PACKAGE_SVR4_INSTALLSCRIPTS) $(SOLARIS_PACKAGE_SVR4_INSTALLDATA) $(PROTOTYPE_DIR) cd $(PROTOTYPE_DIR) && chmod +x $(SOLARIS_PACKAGE_SVR4_HELPERSCRIPTS) $(SOLARIS_PACKAGE_SVR4_INSTALLSCRIPTS) diff --git a/scripts/Solaris/postinstall.in b/scripts/Solaris/postinstall.in index 4d50e264a3..f3ea9010de 100755 --- a/scripts/Solaris/postinstall.in +++ b/scripts/Solaris/postinstall.in @@ -48,6 +48,10 @@ if [ -d "@STATEPATH@" ] ; then chmod 770 "@STATEPATH@" fi +if [ -n "@auglensdir@" ] && [ -d "@auglensdir@" ] && [ -d "@datadir@/augeas-lenses" ] ; then + ( cd "@datadir@/augeas-lenses" && cp -prf ./ "@auglensdir@"/ ) +fi + # Put init script in /etc/init.d cp -pf "@DATADIR@/solaris-init/nut" /etc/init.d diff --git a/scripts/Solaris/preremove.in b/scripts/Solaris/preremove.in index dc1ae04c5e..7282e5a36f 100755 --- a/scripts/Solaris/preremove.in +++ b/scripts/Solaris/preremove.in @@ -1,4 +1,4 @@ -#!bin/sh +#!/bin/sh # Stop all nut services @@ -7,3 +7,7 @@ NUT_DIR="@prefix@" #$NUT_DIR/sbin/upsdrvctl stop # TODO: Unconfigure SMF services + +if [ -n "@auglensdir@" ] && [ -d "@auglensdir@" ] && [ -d "@datadir@/augeas-lenses" ] ; then + ( cd "@datadir@/augeas-lenses" && find . -type f -exec rm -f "@auglensdir@"/'{}' \; ) +fi From 549ed5d9f079406d150f738a84f68df760665c45 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 21:03:23 +0100 Subject: [PATCH 060/165] configure.ac : comment about sysconfdir for NUT --- configure.ac | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 9b900f7fff..ba9a52aa58 100644 --- a/configure.ac +++ b/configure.ac @@ -1535,7 +1535,9 @@ else AC_MSG_RESULT(no) fi -dnl expand ${sysconfdir} and write it out +dnl expand ${sysconfdir} and write it out - note that most packages +dnl override it to be /etc/nut, /etc/ups or similar, while the +dnl autotools default would be $prefix/etc conftemp="${sysconfdir}" eval conftemp=\"${conftemp}\" eval conftemp=\"${conftemp}\" From 481f63b2b4b5a963f5503b3730493e4b3af7dd8c Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 23:38:15 +0100 Subject: [PATCH 061/165] Solaris/Makefile.am : add ability to "make check" something here, e.g. validate manifest XMLs --- scripts/Solaris/Makefile.am | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/scripts/Solaris/Makefile.am b/scripts/Solaris/Makefile.am index dee8133bef..9194232242 100644 --- a/scripts/Solaris/Makefile.am +++ b/scripts/Solaris/Makefile.am @@ -1,20 +1,27 @@ EXTRA_DIST = makelocal.sh PROTOTYPE_DIR = $(DESTDIR)@prefix@ +SOLARIS_CHECK_TARGETS = + +SOLARIS_SMF_MANIFESTS = \ + nut.xml \ + nut-client.xml \ + nut-driver.xml \ + nut-driver-enumerator.xml + +SOLARIS_SMF_METHODSCRIPTS = \ + ../systemd/nut-driver-enumerator.sh \ + svc-nut \ + svc-nut-client if WITH_SOLARIS_SMF # OS equivalent of /lib/svc/method and /var/svc/manifest/application # but we can just use then from this location solarissmfmethoddir = @datadir@/solaris-smf/method solarissmfmanifestdir = @datadir@/solaris-smf/manifest -solarissmfmethod_SCRIPTS = \ - ../systemd/nut-driver-enumerator.sh \ - svc-nut \ - svc-nut-client -solarissmfmanifest_DATA = \ - nut.xml \ - nut-client.xml \ - nut-driver.xml \ - nut-driver-enumerator.xml +solarissmfmethod_SCRIPTS = $(SOLARIS_SMF_METHODSCRIPTS) +solarissmfmanifest_DATA = $(SOLARIS_SMF_MANIFESTS) + +SOLARIS_CHECK_TARGETS += check-local-solaris-smf endif solarisinitscriptdir = @datadir@/solaris-init @@ -61,3 +68,12 @@ package-solaris-svr4: $(SOLARIS_PACKAGE_SVR4_HELPERSCRIPTS) $(SOLARIS_PACKAGE_SV # TODO: Define support for IPS packaging (provide p5m files and make rules) package-solaris-ips: @echo "SKIPPED : Target $@ is not implemented yet" + +check-local: $(SOLARIS_CHECK_TARGETS) + +check-local-solaris-smf: $(SOLARIS_SMF_MANIFESTS) + @[ -x /usr/sbin/svccfg ] || { echo "WARNING : Target $@ skipped due to absent /usr/sbin/svccfg" >&2; return 0; } ; \ + RES=0 ; for F in $^ ; do \ + echo " SVCCFG-VALIDATE $$F"; \ + /usr/sbin/svccfg validate "$$F" || RES=$$? ; \ + done; exit $$RES From e1359b7b0a5b3586160f8e3d4df14e3fe55948b2 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 23:44:27 +0100 Subject: [PATCH 062/165] Solaris SMF XML manifests : fix "dependent" definitions, and add dependencies on required config files --- scripts/Solaris/nut-client.xml.in | 8 ++++++++ scripts/Solaris/nut-driver-enumerator.xml.in | 18 +++++++++++++++++ scripts/Solaris/nut-driver.xml.in | 13 +++++++++--- scripts/Solaris/nut.xml.in | 21 ++++++++++++++++++++ 4 files changed, 57 insertions(+), 3 deletions(-) diff --git a/scripts/Solaris/nut-client.xml.in b/scripts/Solaris/nut-client.xml.in index 8f02f0fc91..0b4cf8110b 100644 --- a/scripts/Solaris/nut-client.xml.in +++ b/scripts/Solaris/nut-client.xml.in @@ -38,6 +38,14 @@ value='svc:/system/filesystem/usr:default'/> + + + + + + + + diff --git a/scripts/Solaris/nut-driver.xml.in b/scripts/Solaris/nut-driver.xml.in index 3f401aeaa7..d553c89d56 100644 --- a/scripts/Solaris/nut-driver.xml.in +++ b/scripts/Solaris/nut-driver.xml.in @@ -32,6 +32,14 @@ value='svc:/system/filesystem/usr:default'/> + + + + + grouping='require_all' + restart_on='refresh'> diff --git a/scripts/Solaris/nut.xml.in b/scripts/Solaris/nut.xml.in index c6ba3e18db..06b6efbf23 100644 --- a/scripts/Solaris/nut.xml.in +++ b/scripts/Solaris/nut.xml.in @@ -38,6 +38,16 @@ value='svc:/system/filesystem/usr:default'/> + + + + + + + + + + From 0b7b1da42363562d36b26a8e15dde7dbd51243b6 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 5 Mar 2017 23:49:46 +0100 Subject: [PATCH 063/165] configure.ac : fix a manually crafted "Checking for" into using AC_MSG routines --- configure.ac | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index ba9a52aa58..1e8324c3ee 100644 --- a/configure.ac +++ b/configure.ac @@ -311,13 +311,14 @@ dnl Solaris 10/11 USB handling (need librt and libusb runtime path) dnl HPUX, since v11, needs an explicit activation of pthreads case ${target_os} in solaris2.1* ) - echo Checking for Solaris 10 / 11 specific configuration for usb drivers + AC_MSG_CHECKING([for Solaris 10 / 11 specific configuration for usb drivers]) AC_SEARCH_LIBS(nanosleep, rt) LIBUSB_LIBS="-R/usr/sfw/lib ${LIBUSB_LIBS}" dnl FIXME: Sun's libusb doesn't support timeout (so blocks notification) dnl and need to call libusb close upon reconnection AC_DEFINE(SUN_LIBUSB, 1, [Define to 1 for Sun version of the libusb.]) SUN_LIBUSB=1 + AC_MSG_RESULT([${LIBUSB_LIBS}]) ;; hpux11*) CFLAGS="${CFLAGS} -lpthread" From d5dc7d1005c70454393fd2f150ddcad949d60a2d Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 6 Mar 2017 00:04:25 +0100 Subject: [PATCH 064/165] Solaris SVR4 packaging should now take care of SMF service registration/teardown --- scripts/Solaris/postinstall.in | 20 +++++++++++++------- scripts/Solaris/preremove.in | 20 +++++++++++++++++--- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/scripts/Solaris/postinstall.in b/scripts/Solaris/postinstall.in index f3ea9010de..8e381d2d29 100755 --- a/scripts/Solaris/postinstall.in +++ b/scripts/Solaris/postinstall.in @@ -52,14 +52,20 @@ if [ -n "@auglensdir@" ] && [ -d "@auglensdir@" ] && [ -d "@datadir@/augeas-lens ( cd "@datadir@/augeas-lenses" && cp -prf ./ "@auglensdir@"/ ) fi -# Put init script in /etc/init.d +if test -x /usr/sbin/svcadm && test -x /usr/sbin/svccfg && test -x /usr/bin/svcs ; then + # Register SMF services + for S in nut-client nut-driver-enumerator nut-driver nut ; do + /usr/sbin/svccfg import "@DATADIR@/solaris-smf/$S.xml" + done +else + # Put init script in /etc/init.d + cp -pf "@DATADIR@/solaris-init/nut" /etc/init.d + chown root:bin /etc/init.d/nut + chmod 744 /etc/init.d/nut -cp -pf "@DATADIR@/solaris-init/nut" /etc/init.d -chown root:bin /etc/init.d/nut -chmod 744 /etc/init.d/nut - -ln -s ../init.d/nut /etc/rc3.d/S90nut > /dev/null 2>&1 -ln -s ../init.d/nut /etc/rc3.d/K10nut > /dev/null 2>&1 + ln -s ../init.d/nut /etc/rc3.d/S90nut > /dev/null 2>&1 + ln -s ../init.d/nut /etc/rc3.d/K10nut > /dev/null 2>&1 +fi # Start nut services diff --git a/scripts/Solaris/preremove.in b/scripts/Solaris/preremove.in index 7282e5a36f..ca89cb9c43 100755 --- a/scripts/Solaris/preremove.in +++ b/scripts/Solaris/preremove.in @@ -4,9 +4,23 @@ NUT_DIR="@prefix@" -#$NUT_DIR/sbin/upsdrvctl stop - -# TODO: Unconfigure SMF services +if test -x /usr/sbin/svcadm && test -x /usr/sbin/svccfg && test -x /usr/bin/svcs ; then + # Unconfigure SMF services + for S in nut-client nut-driver-enumerator nut ; do + /usr/sbin/svcadm disable -s "$S" + /usr/sbin/svccfg -s "$S" delete || \ + /usr/sbin/svccfg -s "$S" delete default + done + for S in `/usr/bin/svcs -H -o fmri 'nut-driver*'` ; do + /usr/sbin/svcadm disable -s "$S" + /usr/sbin/svccfg -s "nut-driver" delete "`echo "$S" | sed 's,^.*:\([^:]*\)$,\1,'`" + done + S="nut-driver" && \ + /usr/sbin/svccfg -s "$S" delete || \ + /usr/sbin/svccfg -s "$S" delete default +else + [ -x /etc/init.d/nut ] && /etc/init.d/nut stop +fi if [ -n "@auglensdir@" ] && [ -d "@auglensdir@" ] && [ -d "@datadir@/augeas-lenses" ] ; then ( cd "@datadir@/augeas-lenses" && find . -type f -exec rm -f "@auglensdir@"/'{}' \; ) From e0d77df30d9b60db00cbd6164c2f79d0ac1ed27b Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 6 Mar 2017 00:07:42 +0100 Subject: [PATCH 065/165] Solaris preremove.in postinstall.in : Usage of @datadir@ caused "${prefix}" strings to pop up - define the vars --- scripts/Solaris/postinstall.in | 1 + scripts/Solaris/preremove.in | 1 + 2 files changed, 2 insertions(+) diff --git a/scripts/Solaris/postinstall.in b/scripts/Solaris/postinstall.in index 8e381d2d29..c9a4fa34cd 100755 --- a/scripts/Solaris/postinstall.in +++ b/scripts/Solaris/postinstall.in @@ -3,6 +3,7 @@ #Postinstall script NUT_DIR="@prefix@" +prefix="@prefix@" # expanded as part of some autoconf macros below # make sure the nut user exists and has correct memberships res="`getent group @RUN_AS_GROUP@`" || res="" diff --git a/scripts/Solaris/preremove.in b/scripts/Solaris/preremove.in index ca89cb9c43..c75ce2a8f8 100755 --- a/scripts/Solaris/preremove.in +++ b/scripts/Solaris/preremove.in @@ -3,6 +3,7 @@ # Stop all nut services NUT_DIR="@prefix@" +prefix="@prefix@" # expanded as part of some autoconf macros below if test -x /usr/sbin/svcadm && test -x /usr/sbin/svccfg && test -x /usr/bin/svcs ; then # Unconfigure SMF services From cf5c82f315048e1bfda0b2b63d2bf11594c75ecf Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 6 Mar 2017 00:19:29 +0100 Subject: [PATCH 066/165] Solaris scripts : use lower-cased @datadir@ in templates processed by configure --- scripts/Solaris/nut-client.xml.in | 2 +- scripts/Solaris/nut-driver-enumerator.xml.in | 2 +- scripts/Solaris/nut.xml.in | 2 +- scripts/Solaris/postinstall.in | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/Solaris/nut-client.xml.in b/scripts/Solaris/nut-client.xml.in index 0b4cf8110b..d2cae3972e 100644 --- a/scripts/Solaris/nut-client.xml.in +++ b/scripts/Solaris/nut-client.xml.in @@ -88,7 +88,7 @@ Date: Mon, 6 Mar 2017 00:21:40 +0100 Subject: [PATCH 067/165] Solaris/preremove.in : fix FMRI pattern when removing package --- scripts/Solaris/preremove.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Solaris/preremove.in b/scripts/Solaris/preremove.in index c75ce2a8f8..d02dc2b06a 100755 --- a/scripts/Solaris/preremove.in +++ b/scripts/Solaris/preremove.in @@ -12,7 +12,7 @@ if test -x /usr/sbin/svcadm && test -x /usr/sbin/svccfg && test -x /usr/bin/svcs /usr/sbin/svccfg -s "$S" delete || \ /usr/sbin/svccfg -s "$S" delete default done - for S in `/usr/bin/svcs -H -o fmri 'nut-driver*'` ; do + for S in `/usr/bin/svcs -H -o fmri '*/nut-driver:*'` ; do /usr/sbin/svcadm disable -s "$S" /usr/sbin/svccfg -s "nut-driver" delete "`echo "$S" | sed 's,^.*:\([^:]*\)$,\1,'`" done From 269a3b6e820d44bc846dbd7a700d10db2bf1063f Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 6 Mar 2017 00:24:17 +0100 Subject: [PATCH 068/165] Solaris/postinstall.in : fix SMF manifest dir --- scripts/Solaris/postinstall.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Solaris/postinstall.in b/scripts/Solaris/postinstall.in index 5babbed949..fd34e0015d 100755 --- a/scripts/Solaris/postinstall.in +++ b/scripts/Solaris/postinstall.in @@ -56,7 +56,7 @@ fi if test -x /usr/sbin/svcadm && test -x /usr/sbin/svccfg && test -x /usr/bin/svcs ; then # Register SMF services for S in nut-client nut-driver-enumerator nut-driver nut ; do - /usr/sbin/svccfg import "@datadir@/solaris-smf/$S.xml" + /usr/sbin/svccfg import "@datadir@/solaris-smf/manifest/$S.xml" done else # Put init script in /etc/init.d From 11c398b92e436d7c74ac725e34fe44a685052f90 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 6 Mar 2017 00:26:19 +0100 Subject: [PATCH 069/165] Solaris/postremove.in : fix verbose RM; wipe the /var/run/nut dir too --- scripts/Solaris/postremove.in | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/scripts/Solaris/postremove.in b/scripts/Solaris/postremove.in index ae46515c37..0fdb9f79b5 100755 --- a/scripts/Solaris/postremove.in +++ b/scripts/Solaris/postremove.in @@ -1,14 +1,17 @@ #!/bin/sh +# Remove init script from /etc/init.d - created by scripts not packaging + +rm -f /etc/init.d/nut +rm -f /etc/rc3.d/S90nut +rm -f /etc/rc3.d/K10nut + # Remove nut group and user /usr/sbin/userdel "@RUN_AS_USER@" /usr/sbin/groupdel "@RUN_AS_GROUP@" -# Remove init script from /etc/init.d - created by scripts not packaging - -rm /etc/init.d/nut -rm /etc/rc3.d/S90nut -rm /etc/rc3.d/K10nut +# Remove /var/run/nut +rm -rf "@PIDPATH@/nut" From d650c7827bbd15426865abd7cd0a53508fe7b8e0 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 6 Mar 2017 00:34:57 +0100 Subject: [PATCH 070/165] Solaris/preremove.in : fix commands when removing package --- scripts/Solaris/preremove.in | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/Solaris/preremove.in b/scripts/Solaris/preremove.in index d02dc2b06a..b78bd699a3 100755 --- a/scripts/Solaris/preremove.in +++ b/scripts/Solaris/preremove.in @@ -9,14 +9,19 @@ if test -x /usr/sbin/svcadm && test -x /usr/sbin/svccfg && test -x /usr/bin/svcs # Unconfigure SMF services for S in nut-client nut-driver-enumerator nut ; do /usr/sbin/svcadm disable -s "$S" + /usr/sbin/svccfg delete "$S" || \ /usr/sbin/svccfg -s "$S" delete || \ /usr/sbin/svccfg -s "$S" delete default done for S in `/usr/bin/svcs -H -o fmri '*/nut-driver:*'` ; do /usr/sbin/svcadm disable -s "$S" - /usr/sbin/svccfg -s "nut-driver" delete "`echo "$S" | sed 's,^.*:\([^:]*\)$,\1,'`" + done + for S in `/usr/bin/svcs -H -o fmri '*/nut-driver:*'` ; do + /usr/sbin/svccfg -s "nut-driver" delete "$S" || \ + /usr/sbin/svccfg delete "$S" done S="nut-driver" && \ + /usr/sbin/svccfg delete "$S" || \ /usr/sbin/svccfg -s "$S" delete || \ /usr/sbin/svccfg -s "$S" delete default else From a6e6b62777aeed84b76a8a22aa74ebf3d0842bd7 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 6 Mar 2017 00:40:29 +0100 Subject: [PATCH 071/165] Solaris/postinstall.in : enable SMF services if configs are already available (esp. create nut-driver instances) --- scripts/Solaris/postinstall.in | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/scripts/Solaris/postinstall.in b/scripts/Solaris/postinstall.in index fd34e0015d..b76575c110 100755 --- a/scripts/Solaris/postinstall.in +++ b/scripts/Solaris/postinstall.in @@ -58,6 +58,18 @@ if test -x /usr/sbin/svcadm && test -x /usr/sbin/svccfg && test -x /usr/bin/svcs for S in nut-client nut-driver-enumerator nut-driver nut ; do /usr/sbin/svccfg import "@datadir@/solaris-smf/manifest/$S.xml" done + # Enable services if the system already has a configuration (e.g. upgrade) + if test -s "@CONFPATH@/ups.conf" ; then + /usr/sbin/svcadm enable -s nut-driver-enumerator || \ + { /usr/sbin/svcadm clear nut-driver-enumerator ; \ + /usr/sbin/svcadm enable -s nut-driver-enumerator; } + fi + if test -s "@CONFPATH@/ups.conf" -a test -s "@CONFPATH@/upsd.conf" -a test -s "@CONFPATH@/upsd.users" ; then + /usr/sbin/svcadm enable -s nut + fi + if test -s "@CONFPATH@/upsmon.conf" ; then + /usr/sbin/svcadm enable -s nut-client + fi else # Put init script in /etc/init.d cp -pf "@datadir@/solaris-init/nut" /etc/init.d @@ -66,11 +78,11 @@ else ln -s ../init.d/nut /etc/rc3.d/S90nut > /dev/null 2>&1 ln -s ../init.d/nut /etc/rc3.d/K10nut > /dev/null 2>&1 -fi -# Start nut services + # Start nut services -#echo "Starting nut services" -#$NUT_DIR/sbin/upsdrvctl start #> /dev/null 2>&1 -#$NUT_DIR/sbin/upsd #> /dev/null 2>&1 -#$NUT_DIR/sbin/upsmon #> /dev/null 2>&1 + #echo "Starting nut services" + #$NUT_DIR/sbin/upsdrvctl start #> /dev/null 2>&1 + #$NUT_DIR/sbin/upsd #> /dev/null 2>&1 + #$NUT_DIR/sbin/upsmon #> /dev/null 2>&1 +fi From 7f1ab8f266e8ad70e3248c9bbedc90f7bbd7b437 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 6 Mar 2017 00:41:28 +0100 Subject: [PATCH 072/165] Solaris/preremove.in : fix commands when removing package --- scripts/Solaris/preremove.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Solaris/preremove.in b/scripts/Solaris/preremove.in index b78bd699a3..8fa20dddd8 100755 --- a/scripts/Solaris/preremove.in +++ b/scripts/Solaris/preremove.in @@ -16,7 +16,7 @@ if test -x /usr/sbin/svcadm && test -x /usr/sbin/svccfg && test -x /usr/bin/svcs for S in `/usr/bin/svcs -H -o fmri '*/nut-driver:*'` ; do /usr/sbin/svcadm disable -s "$S" done - for S in `/usr/bin/svcs -H -o fmri '*/nut-driver:*'` ; do + for S in `/usr/bin/svcs -H -o fmri '*/nut-driver:*' | grep -wv default` ; do /usr/sbin/svccfg -s "nut-driver" delete "$S" || \ /usr/sbin/svccfg delete "$S" done From 65a324122d747f7059f37828e8a172aa5ecf7bd8 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 6 Mar 2017 00:45:43 +0100 Subject: [PATCH 073/165] Solaris/postinstall.in : enable SMF services if configs are already available (esp. create nut-driver instances) - verbosity --- scripts/Solaris/postinstall.in | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/Solaris/postinstall.in b/scripts/Solaris/postinstall.in index b76575c110..8a995c3f12 100755 --- a/scripts/Solaris/postinstall.in +++ b/scripts/Solaris/postinstall.in @@ -54,24 +54,27 @@ if [ -n "@auglensdir@" ] && [ -d "@auglensdir@" ] && [ -d "@datadir@/augeas-lens fi if test -x /usr/sbin/svcadm && test -x /usr/sbin/svccfg && test -x /usr/bin/svcs ; then - # Register SMF services + echo "Register SMF services..." for S in nut-client nut-driver-enumerator nut-driver nut ; do /usr/sbin/svccfg import "@datadir@/solaris-smf/manifest/$S.xml" done # Enable services if the system already has a configuration (e.g. upgrade) if test -s "@CONFPATH@/ups.conf" ; then + echo "Enable NUT drivers (if any)..." /usr/sbin/svcadm enable -s nut-driver-enumerator || \ { /usr/sbin/svcadm clear nut-driver-enumerator ; \ /usr/sbin/svcadm enable -s nut-driver-enumerator; } fi - if test -s "@CONFPATH@/ups.conf" -a test -s "@CONFPATH@/upsd.conf" -a test -s "@CONFPATH@/upsd.users" ; then + if test -s "@CONFPATH@/ups.conf" && test -s "@CONFPATH@/upsd.conf" && test -s "@CONFPATH@/upsd.users" ; then + echo "Enable NUT upsd server..." /usr/sbin/svcadm enable -s nut fi if test -s "@CONFPATH@/upsmon.conf" ; then + echo "Enable NUT upsmon client..." /usr/sbin/svcadm enable -s nut-client fi else - # Put init script in /etc/init.d + echo "Put init script in /etc/init.d..." cp -pf "@datadir@/solaris-init/nut" /etc/init.d chown root:bin /etc/init.d/nut chmod 744 /etc/init.d/nut From 8e6e399dd85005c177a0f5f830d787934850fc2b Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 6 Mar 2017 01:07:08 +0100 Subject: [PATCH 074/165] Solaris/nut-driver-enumerator.xml.in : use a unique dependency name (avoid conflict in nut-driver instances chain of deps) --- scripts/Solaris/nut-driver-enumerator.xml.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Solaris/nut-driver-enumerator.xml.in b/scripts/Solaris/nut-driver-enumerator.xml.in index 739823317f..2247464a04 100644 --- a/scripts/Solaris/nut-driver-enumerator.xml.in +++ b/scripts/Solaris/nut-driver-enumerator.xml.in @@ -50,7 +50,7 @@ Prerequisite for NUT upsd to be started, if it's enabled --> From 7440028b50166e37aa09a2bd00f674caa7b7158a Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 6 Mar 2017 01:22:11 +0100 Subject: [PATCH 075/165] systemd and Solaris : fix up embedded ${prefix} in service files and SMF manifests after generation --- scripts/Solaris/Makefile.am | 6 ++++++ scripts/Solaris/svc-nut-client.in | 1 + scripts/Solaris/svc-nut.in | 1 + scripts/systemd/Makefile.am | 6 ++++++ scripts/systemd/nut-driver-enumerator.sh.in | 1 + 5 files changed, 15 insertions(+) diff --git a/scripts/Solaris/Makefile.am b/scripts/Solaris/Makefile.am index 9194232242..e551acd400 100644 --- a/scripts/Solaris/Makefile.am +++ b/scripts/Solaris/Makefile.am @@ -69,6 +69,12 @@ package-solaris-svr4: $(SOLARIS_PACKAGE_SVR4_HELPERSCRIPTS) $(SOLARIS_PACKAGE_SV package-solaris-ips: @echo "SKIPPED : Target $@ is not implemented yet" +# Fix up autotools expansion of default values (e.g. datadir="${prefix}/share" verbatim) +$(SOLARIS_SMF_MANIFESTS): Makefile.am + sed -e 's,\$\{prefix\}/,@prefix@/,g' \ + -e 's,\$\{exec_prefix\}/,@exec_prefix@/,g' \ + -i "$@" + check-local: $(SOLARIS_CHECK_TARGETS) check-local-solaris-smf: $(SOLARIS_SMF_MANIFESTS) diff --git a/scripts/Solaris/svc-nut-client.in b/scripts/Solaris/svc-nut-client.in index b338aa2c77..a7dd0dc91d 100755 --- a/scripts/Solaris/svc-nut-client.in +++ b/scripts/Solaris/svc-nut-client.in @@ -12,6 +12,7 @@ fi # smf(5) . /lib/svc/share/smf_include.sh || exit +prefix="@prefix@" NUT_DIR="@prefix@" NUT_SBIN_DIR="${NUT_DIR}/sbin" NUT_LIB_DIR="${NUT_DIR}/lib" diff --git a/scripts/Solaris/svc-nut.in b/scripts/Solaris/svc-nut.in index c018c271b0..9a826036e4 100755 --- a/scripts/Solaris/svc-nut.in +++ b/scripts/Solaris/svc-nut.in @@ -12,6 +12,7 @@ fi # smf(5) . /lib/svc/share/smf_include.sh || exit +prefix="@prefix@" NUT_DIR="@prefix@" NUT_SBIN_DIR="$NUT_DIR/sbin" NUT_LIB_DIR="${NUT_DIR}/lib" diff --git a/scripts/systemd/Makefile.am b/scripts/systemd/Makefile.am index af33e146e5..ad2e7a9f44 100644 --- a/scripts/systemd/Makefile.am +++ b/scripts/systemd/Makefile.am @@ -9,6 +9,12 @@ systemdsystemunit_DATA = \ nut-server.service \ nut-driver.target +# Fix up autotools expansion of default values (e.g. datadir="${prefix}/share" verbatim) +$(systemdsystemunit_DATA): Makefile.am + sed -e 's,\$\{prefix\}/,@prefix@/,g' \ + -e 's,\$\{exec_prefix\}/,@exec_prefix@/,g' \ + -i "$@" + EXTRA_DIST += nut-driver.target systemdshutdown_SCRIPTS = nutshutdown diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index 755eb7af8d..1b314f8841 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -47,6 +47,7 @@ # Directory where NUT configs are located, e.g. /etc/nut or /etc/ups # Set at package configuration, compiled into daemons and drivers +prefix="@prefix@" [ -n "${NUT_CONF_DIR-}" ] || NUT_CONF_DIR="@sysconfdir@" # Third-party services to depend on (can be overridden by config file) From b455150850d715ca038e889cc4ff2a608045c85d Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 6 Mar 2017 01:37:59 +0100 Subject: [PATCH 076/165] systemd/README : add recent authors --- scripts/systemd/README | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/systemd/README b/scripts/systemd/README index c8930ab958..fb66e97243 100644 --- a/scripts/systemd/README +++ b/scripts/systemd/README @@ -5,4 +5,5 @@ These files are automatically installed, upon detection (at configure time) of a systemd enabled system. Contributed by Michal Hlavinka +Updated 2016-2017 by Michal Hrusecky and Jim Klimov From 8d6dd03048d1b9d25992c5e4fc79258a66f04c4c Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 6 Mar 2017 01:50:22 +0100 Subject: [PATCH 077/165] Define a NUT_DATADIR and NUT_LIBEXECDIR with expanded path values to use in service manifests --- configure.ac | 10 ++++++++++ scripts/Solaris/Makefile.am | 6 ------ scripts/Solaris/nut-client.xml.in | 2 +- scripts/Solaris/nut-driver-enumerator.xml.in | 2 +- scripts/Solaris/nut.xml.in | 2 +- scripts/systemd/Makefile.am | 6 ------ scripts/systemd/nut-driver-enumerator.service.in | 4 ++-- 7 files changed, 15 insertions(+), 17 deletions(-) diff --git a/configure.ac b/configure.ac index 1e8324c3ee..4cad9087bc 100644 --- a/configure.ac +++ b/configure.ac @@ -1550,6 +1550,7 @@ conftemp="${datadir}" eval conftemp=\"${conftemp}\" eval conftemp=\"${conftemp}\" DATADIR=${conftemp} +NUT_DATADIR=${conftemp} AC_DEFINE_UNQUOTED(DATADIR, "${conftemp}", [Default path for data files]) dnl same for bindir @@ -1573,6 +1574,13 @@ eval conftemp=\"${conftemp}\" LIBDIR=${conftemp} AC_DEFINE_UNQUOTED(LIBDIR, "${conftemp}", [Default path for system libraries]) +dnl same for libexecdir +conftemp="${libexecdir}" +eval conftemp=\"${conftemp}\" +eval conftemp=\"${conftemp}\" +LIBEXECDIR=${conftemp} +AC_DEFINE_UNQUOTED(LIBEXECDIR, "${conftemp}", [Default path for system exec-libraries]) + dnl checks related to --with-snmp enabled on command-line @@ -1664,6 +1672,8 @@ AC_SUBST(STATEPATH) AC_SUBST(CONFPATH) AC_SUBST(BINDIR) AC_SUBST(LIBDIR) +AC_SUBST(NUT_DATADIR, [`eval echo "${DATADIR}"`]) +AC_SUBST(NUT_LIBEXECDIR, [`eval echo "${LIBEXECDIR}"`]) AC_SUBST(DRVPATH) AC_SUBST(SBINDIR) AC_SUBST(PORT) diff --git a/scripts/Solaris/Makefile.am b/scripts/Solaris/Makefile.am index e551acd400..9194232242 100644 --- a/scripts/Solaris/Makefile.am +++ b/scripts/Solaris/Makefile.am @@ -69,12 +69,6 @@ package-solaris-svr4: $(SOLARIS_PACKAGE_SVR4_HELPERSCRIPTS) $(SOLARIS_PACKAGE_SV package-solaris-ips: @echo "SKIPPED : Target $@ is not implemented yet" -# Fix up autotools expansion of default values (e.g. datadir="${prefix}/share" verbatim) -$(SOLARIS_SMF_MANIFESTS): Makefile.am - sed -e 's,\$\{prefix\}/,@prefix@/,g' \ - -e 's,\$\{exec_prefix\}/,@exec_prefix@/,g' \ - -i "$@" - check-local: $(SOLARIS_CHECK_TARGETS) check-local-solaris-smf: $(SOLARIS_SMF_MANIFESTS) diff --git a/scripts/Solaris/nut-client.xml.in b/scripts/Solaris/nut-client.xml.in index d2cae3972e..f957382f51 100644 --- a/scripts/Solaris/nut-client.xml.in +++ b/scripts/Solaris/nut-client.xml.in @@ -88,7 +88,7 @@ Date: Mon, 6 Mar 2017 01:57:12 +0100 Subject: [PATCH 078/165] Solaris : packaged service addition/removal more verbose --- scripts/Solaris/postinstall.in | 4 +++- scripts/Solaris/preremove.in | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/Solaris/postinstall.in b/scripts/Solaris/postinstall.in index 8a995c3f12..468bfc2210 100755 --- a/scripts/Solaris/postinstall.in +++ b/scripts/Solaris/postinstall.in @@ -55,12 +55,14 @@ fi if test -x /usr/sbin/svcadm && test -x /usr/sbin/svccfg && test -x /usr/bin/svcs ; then echo "Register SMF services..." - for S in nut-client nut-driver-enumerator nut-driver nut ; do + for S in nut-driver-enumerator nut-driver nut nut-client ; do + echo "Importing NUT service manifest: $S..." /usr/sbin/svccfg import "@datadir@/solaris-smf/manifest/$S.xml" done # Enable services if the system already has a configuration (e.g. upgrade) if test -s "@CONFPATH@/ups.conf" ; then echo "Enable NUT drivers (if any)..." + "@datadir@/solaris-smf/method/nut-driver-enumerator.sh" /usr/sbin/svcadm enable -s nut-driver-enumerator || \ { /usr/sbin/svcadm clear nut-driver-enumerator ; \ /usr/sbin/svcadm enable -s nut-driver-enumerator; } diff --git a/scripts/Solaris/preremove.in b/scripts/Solaris/preremove.in index 8fa20dddd8..bfb789d201 100755 --- a/scripts/Solaris/preremove.in +++ b/scripts/Solaris/preremove.in @@ -8,19 +8,24 @@ prefix="@prefix@" # expanded as part of some autoconf macros below if test -x /usr/sbin/svcadm && test -x /usr/sbin/svccfg && test -x /usr/bin/svcs ; then # Unconfigure SMF services for S in nut-client nut-driver-enumerator nut ; do + echo "Stopping NUT service: $S..." /usr/sbin/svcadm disable -s "$S" + echo "Removing NUT service: $S..." /usr/sbin/svccfg delete "$S" || \ /usr/sbin/svccfg -s "$S" delete || \ /usr/sbin/svccfg -s "$S" delete default done for S in `/usr/bin/svcs -H -o fmri '*/nut-driver:*'` ; do + echo "Stopping NUT service: $S..." /usr/sbin/svcadm disable -s "$S" done for S in `/usr/bin/svcs -H -o fmri '*/nut-driver:*' | grep -wv default` ; do + echo "Removing NUT service: $S..." /usr/sbin/svccfg -s "nut-driver" delete "$S" || \ /usr/sbin/svccfg delete "$S" done S="nut-driver" && \ + echo "Removing NUT service: $S..." && \ /usr/sbin/svccfg delete "$S" || \ /usr/sbin/svccfg -s "$S" delete || \ /usr/sbin/svccfg -s "$S" delete default From 57c43906cc7d9ecb70a01605eb55f08cee139b9a Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 6 Mar 2017 02:03:24 +0100 Subject: [PATCH 079/165] nut-driver-enumerator.xml.in nut-driver.xml.in : do not block startup of nut server --- scripts/Solaris/nut-driver-enumerator.xml.in | 4 +++- scripts/Solaris/nut-driver.xml.in | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/Solaris/nut-driver-enumerator.xml.in b/scripts/Solaris/nut-driver-enumerator.xml.in index e2b74ad08f..259517e8e3 100644 --- a/scripts/Solaris/nut-driver-enumerator.xml.in +++ b/scripts/Solaris/nut-driver-enumerator.xml.in @@ -48,10 +48,12 @@ diff --git a/scripts/Solaris/nut-driver.xml.in b/scripts/Solaris/nut-driver.xml.in index d553c89d56..27907cc107 100644 --- a/scripts/Solaris/nut-driver.xml.in +++ b/scripts/Solaris/nut-driver.xml.in @@ -67,10 +67,12 @@ From 35bcfa05e2de256b644825b57f167cbbfc0f12a2 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 6 Mar 2017 02:14:38 +0100 Subject: [PATCH 080/165] nut.xml.in : do not block startup of nut server due to failed nut-driver-enumerator --- scripts/Solaris/nut.xml.in | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/Solaris/nut.xml.in b/scripts/Solaris/nut.xml.in index 3fad089fc9..4cadcbd662 100644 --- a/scripts/Solaris/nut.xml.in +++ b/scripts/Solaris/nut.xml.in @@ -74,10 +74,12 @@ From b55b2eef7923fd7182c860897f707d45c948bb25 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 20 Nov 2017 00:11:06 +0100 Subject: [PATCH 081/165] nut-driver-enumerator.xml.in : add REFRESH action and do not die on RESTART --- scripts/Solaris/nut-driver-enumerator.xml.in | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/Solaris/nut-driver-enumerator.xml.in b/scripts/Solaris/nut-driver-enumerator.xml.in index 259517e8e3..c9c39394f4 100644 --- a/scripts/Solaris/nut-driver-enumerator.xml.in +++ b/scripts/Solaris/nut-driver-enumerator.xml.in @@ -68,10 +68,17 @@ exec='@NUT_DATADIR@/solaris-smf/method/nut-driver-enumerator.sh' timeout_seconds='0'/> + + + From 7a67d1c03096d2bbbbe275878617a94943ea9ed1 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 6 Mar 2017 02:40:10 +0100 Subject: [PATCH 082/165] nut-driver-enumerator.sh.in : improve portability by using TAB char as is (not regex \t which gets misinterpreted by some tools) --- scripts/systemd/nut-driver-enumerator.sh.in | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index 1b314f8841..9e890249de 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -93,6 +93,9 @@ DEPREQ_NET_LOCAL_SMF="optional_all" # Start a freshly-registered unit? [ -z "${AUTO_START-}" ] && AUTO_START=yes +# We avoid regex '\t' which gets misinterpreted by some tools +TABCHAR="`printf '\t'`" || TABCHAR=' ' + if [ -z "${SERVICE_FRAMEWORK-}" ] ; then [ -x /usr/sbin/svcadm ] && [ -x /usr/sbin/svccfg ] && [ -x /usr/bin/svcs ] && \ SERVICE_FRAMEWORK="smf" @@ -165,7 +168,7 @@ upsconf_getValue() { ;; "$2"=*) if [ "$CURR_SECTION" = "$1" ]; then # VALUE="$(echo "$LINE" | sed -e 's,\#.*$,,' -e 's,^[\t\ ]*,,' -e 's,[\t\ ]*$,,' -e 's,[\t\ ]*=[\t\ ]*,=,' -e 's,'"$2"'=\([^\t\ ]*\)[\t\ ]*.*$,\1,')" - VALUE="$(echo "$LINE" | sed -e 's,^'"$2"'=\([^\t\ ]*\)[\t\ ]*.*$,\1,')" + VALUE="$(echo "$LINE" | sed -e 's,^'"$2"'=\([^'"$TABCHAR"'\ ]*\)['"$TABCHAR"'\ ]*.*$,\1,')" RES=$? echo "$VALUE" return $RES @@ -333,7 +336,7 @@ upslist_readFile() { # using specified protocol and media) if [ -n "$UPSCONF" ] && [ -f "$UPSCONF" ] && [ -r "$UPSCONF" ]; then [ -s "$UPSCONF" ] && \ - UPSCONF_DATA="$(egrep '[\[\=]' < "$UPSCONF" | sed -e 's,^[\t\ ]*,,' -e 's,^\#.*$,,' -e 's,[\t\ ]*$,,' -e 's,[\t\ ]*=[\t\ ]*,=,g' -e 's,=\"\([^\ \t]*\)\"$,=\1,' | egrep '^(\[.*\]|driver=|port=)')" || \ + UPSCONF_DATA="$(egrep '[\[\=]' < "$UPSCONF" | sed -e 's,^['"$TABCHAR"'\ ]*,,' -e 's,^\#.*$,,' -e 's,['"$TABCHAR"'\ ]*$,,' -e 's,['"$TABCHAR"'\ ]*=['"$TABCHAR"'\ ]*,=,g' -e 's,=\"\([^\ '"$TABCHAR"']*\)\"$,=\1,' | egrep '^(\[.*\]|driver=|port=)')" || \ UPSCONF_DATA="" else echo "FATAL: The '$UPSCONF' file does not exist or is not readable" >&2 From d28bb9d36be80c8c8defc7a37b19e8ccb24ac459 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 6 Mar 2017 03:08:02 +0100 Subject: [PATCH 083/165] nut-driver-enumerator.sh.in : comment the caveats --- scripts/systemd/nut-driver-enumerator.sh.in | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index 9e890249de..621212031c 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -45,6 +45,27 @@ # added to that platform first). Parts in this script are finished. # +# NOTE: Currently found caveats that might be solved later but require +# considerable effort: +# * Solaris SMF constrains the syntax of valid strings for instance names +# (e.g. not starting with a digit, no period chars) which blocks creation +# of some UPS driver instances. This might be worked around by hashing +# the device name e.g. to base64 (and un-hashing instance name when calling +# upsdrvctl), but is not quite user-friendly. Also can store device name +# in a service attribute while mangling the instance name to a valid subset. +# Comparisons (if devices are already wrapped) becomes more complicated in +# the script in either case, as well as in the service startup method. +# ** The `+` `/` `=` characters from base64 are also invalid for SMF instance +# name, but the first two can be sed'ed to `-` `_` and back, for example. +# Some prefix word is also needed (avoid starting with a digit). +# The trailing padding `=` can be dropped, and added until we get a +# non-empty decode. Conversions can be done by +# `echo "$string" | openssl base64 -e|-d` +# * Dummy-UPS services that "proxy" another locally defined section are +# essentially a circular dependency for upsd. While the system might +# start-up lacking a driver, there should be some timer to re-enable +# failed not-disabled drivers (would be useful in any case though). + # Directory where NUT configs are located, e.g. /etc/nut or /etc/ups # Set at package configuration, compiled into daemons and drivers prefix="@prefix@" From cc61d775cd107b8973c5ef24d2944aeed7640aa0 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 6 Apr 2017 10:17:28 +0200 Subject: [PATCH 084/165] nut-driver-enumerator.sh.in : apcsmart is serial only --- scripts/systemd/nut-driver-enumerator.sh.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index 621212031c..8cac25e532 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -224,7 +224,7 @@ upsconf_getDriverMedia() { # particular system's physics, both serial and network media may need USB). CURR_DRV="`upsconf_getDriver "$1"`" || return $? case "$CURR_DRV" in - *netxml*|*snmp*|*ipmi*|*powerman*|*-mib*|*avahi*|*apcsmart*|*apcupsd*) + *netxml*|*snmp*|*ipmi*|*powerman*|*-mib*|*avahi*|*apcupsd*) printf '%s\n%s\n' "$CURR_DRV" "network" ; return ;; *usb*) printf '%s\n%s\n' "$CURR_DRV" "usb" ; return ;; From 86c290de332ef9044d0fa274c6c4cddd3a87f7e4 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 19 Nov 2017 20:58:22 +0100 Subject: [PATCH 085/165] nut-driver-enumerator.sh.in : By default, update wrapping of devices into services... but keep the door open to other uses of the script --- scripts/systemd/nut-driver-enumerator.sh.in | 63 ++++++++++++--------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index 8cac25e532..8312d56661 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -406,39 +406,46 @@ upslist_delSvcs() { done } -################# MAIN PROGRAM +nut-driver-enumerator-main() { + ################# MAIN PROGRAM by default -upslist_readFile || exit $? -#upslist_debug -upslist_readSvcs "before manipulations" + upslist_readFile || exit $? + #upslist_debug + upslist_readSvcs "before manipulations" -# Quickly exit if there's nothing to do; note the lists are pre-sorted -# Otherwise a non-zero exit will be done below -[ "$UPSLIST_FILE" = "$UPSLIST_SVCS" ] && exit 0 + # Quickly exit if there's nothing to do; note the lists are pre-sorted + # Otherwise a non-zero exit will be done below + [ "$UPSLIST_FILE" = "$UPSLIST_SVCS" ] && return 0 -if [ -n "$UPSLIST_FILE" ]; then - upslist_addSvcs - upslist_readSvcs "after checking for new config sections to define service instances" -fi + if [ -n "$UPSLIST_FILE" ]; then + upslist_addSvcs + upslist_readSvcs "after checking for new config sections to define service instances" + fi -if [ -n "$UPSLIST_SVCS" ]; then - upslist_delSvcs -fi + if [ -n "$UPSLIST_SVCS" ]; then + upslist_delSvcs + fi -upslist_readSvcs -if [ -n "$UPSLIST_SVCS" ] ; then - echo "=== The currently defined service instances are:" - echo "$UPSLIST_SVCS" -fi + upslist_readSvcs + if [ -n "$UPSLIST_SVCS" ] ; then + echo "=== The currently defined service instances are:" + echo "$UPSLIST_SVCS" + fi -if [ -n "$UPSLIST_FILE" ] ; then - echo "=== The currently defined configurations in '$UPSCONF' are:" - echo "$UPSLIST_FILE" -fi + if [ -n "$UPSLIST_FILE" ] ; then + echo "=== The currently defined configurations in '$UPSCONF' are:" + echo "$UPSLIST_FILE" + fi + + # Return 42 if there was a change applied succesfully + # (but e.g. some services should restart - upsd, maybe upsmon) + if [ "$UPSLIST_FILE" = "$UPSLIST_SVCS" ] ; then + [ "${REPORT_RESTART_42-}" = no ] && return 0 || return 42 + fi + return 13 +} -# Return 42 if there was a change applied succesfully -# (but e.g. some services should restart - upsd, maybe upsmon) -if [ "$UPSLIST_FILE" = "$UPSLIST_SVCS" ] ; then - [ "${REPORT_RESTART_42-}" = no ] && return 0 || return 42 +# By default, update wrapping of devices into services +if [ $# = 0 ]; then + nut-driver-enumerator-main ; exit $? fi -exit 13 From 8f743ed4052825f117ba697e2007c71ad277e836 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 19 Nov 2017 22:34:09 +0100 Subject: [PATCH 086/165] Introduce upsdrvsvcctl with semantics similar to upsdrvctl, but managing stop/start of SMF or systemd unit instances --- configure.ac | 1 + scripts/Solaris/Makefile.am | 2 + scripts/systemd/Makefile.am | 5 +- scripts/systemd/upsdrvsvcctl.in | 117 ++++++++++++++++++++++++++++++++ 4 files changed, 124 insertions(+), 1 deletion(-) create mode 100755 scripts/systemd/upsdrvsvcctl.in diff --git a/configure.ac b/configure.ac index 4cad9087bc..35380ea9be 100644 --- a/configure.ac +++ b/configure.ac @@ -1738,6 +1738,7 @@ AC_OUTPUT([ scripts/systemd/nut-driver-enumerator.service scripts/systemd/nut-driver-enumerator.sh scripts/systemd/nutshutdown + scripts/systemd/upsdrvsvcctl scripts/Solaris/nut-driver-enumerator.xml scripts/Solaris/nut-driver.xml scripts/Solaris/nut-client.xml diff --git a/scripts/Solaris/Makefile.am b/scripts/Solaris/Makefile.am index 9194232242..df9fa22937 100644 --- a/scripts/Solaris/Makefile.am +++ b/scripts/Solaris/Makefile.am @@ -21,6 +21,8 @@ solarissmfmanifestdir = @datadir@/solaris-smf/manifest solarissmfmethod_SCRIPTS = $(SOLARIS_SMF_METHODSCRIPTS) solarissmfmanifest_DATA = $(SOLARIS_SMF_MANIFESTS) +sbin_SCRIPTS = ../systemd/upsdrvsvcctl + SOLARIS_CHECK_TARGETS += check-local-solaris-smf endif diff --git a/scripts/systemd/Makefile.am b/scripts/systemd/Makefile.am index af33e146e5..5536da408d 100644 --- a/scripts/systemd/Makefile.am +++ b/scripts/systemd/Makefile.am @@ -15,9 +15,12 @@ systemdshutdown_SCRIPTS = nutshutdown libexec_SCRIPTS = nut-driver-enumerator.sh +sbin_SCRIPTS = upsdrvsvcctl + else EXTRA_DIST += nut-driver@.service.in nut-monitor.service.in \ nut-server.service.in nutshutdown.in nut-driver.target \ - nut-driver-enumerator.sh.in nut-driver-enumerator.service.in + nut-driver-enumerator.sh.in nut-driver-enumerator.service.in \ + upsdrvsvcctl.in endif diff --git a/scripts/systemd/upsdrvsvcctl.in b/scripts/systemd/upsdrvsvcctl.in new file mode 100755 index 0000000000..6e26460f4e --- /dev/null +++ b/scripts/systemd/upsdrvsvcctl.in @@ -0,0 +1,117 @@ +#!/bin/sh +# +# Copyright (C) 2016-2017 Eaton +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +#! \file upsdrvsvcctl(.in) +# \author Jim Klimov +# \brief Manage NUT devices registered as service-unit instances +# + +ENUMERATOR="@NUT_LIBEXECDIR@/nut-driver-enumerator.sh" + +usage() { + # Note: version header differs from UPS_VERSION in binaries that + # might also have the git-version suffixed during build time + cat << EOF +Network UPS Tools - UPS driver controller ${PACKAGE_VERSION} +Starts and stops UPS drivers via system service instances, see +the $ENUMERATOR +script for more details. + +usage: ./drivers/upsdrvctl [OPTIONS] (start | stop | shutdown) [] + + -h display this help + -t testing mode - prints actions without doing them + -D raise debugging level + start start all UPS drivers in ups.conf + start only start driver for UPS + stop stop all UPS drivers in ups.conf + stop only stop driver for UPS +# shutdown shutdown all UPS drivers in ups.conf +# shutdown only shutdown UPS +EOF +} + +ACTION="" +SVCINST="" +DRYRUN="" +DEBUG=0 # UNUSED_PARAM so far +while [ $# -gt 0 ]; do + case "$1" in + start|stop) if [ -n "$2" ] ; then SVCINST="`$ENUMERATOR --get-service-for-device "$2"`" || exit ; shift ; fi + ACTION="$1" ;; + shutdown) echo "Action '$1' is not implemented via services currently" >&2 ; exit 1 ;; + -t) DRYRUN="echo" ;; + -h) usage; exit 0 ;; + -d) DEBUG="`expr $DEBUG + 1`" ;; + -r|-u) echo "Option '$1 $2' is not implemented via services currently" >&2 ; shift;; + *) echo "Unrecognized argument: $1" >&2 ; exit ;; + esac + shift +done + +if [ -z "$ACTION" ]; then + echo "No action was requested!" >&2 + exit 1 +fi + +if [ -z "$SVCINST" ]; then + SVCINST="`$ENUMERATOR --list-services`" || exit +fi + +if [ -z "${SERVICE_FRAMEWORK-}" ] ; then + [ -x /usr/sbin/svcadm ] && [ -x /usr/sbin/svccfg ] && [ -x /usr/bin/svcs ] && \ + SERVICE_FRAMEWORK="smf" + [ -z "${SERVICE_FRAMEWORK-}" ] && \ + [ -x /bin/systemctl ] && \ + SERVICE_FRAMEWORK="systemd" +fi + +VERB="" +CMD="" +CMDARG="" +case "$SERVICE_FRAMEWORK" in + smf) CMD="/usr/sbin/svcadm" ;; + systemd) CMD="/bin/systemctl" ;; + *) echo "Unrecognized SERVICE_FRAMEWORK: $SERVICE_FRAMEWORK" >&2 ; exit ;; +esac + +# TODO: Support shutdown of one or all UPSes by stopping its service and calling upsdrvctl on it +case "$ACTION" in + start) + VERB="Starting" + case "$SERVICE_FRAMEWORK" in + smf) CMDARG="enable -t" ;; + systemd) CMDARG="start" ;; + esac + ;; + stop) + VERB="Stopping" + case "$SERVICE_FRAMEWORK" in + smf) CMDARG="disable -t" ;; + systemd) CMDARG="stop" ;; + esac + ;; + *) echo "Unrecognized ACTION: $ACTION" >&2 ; exit ;; +esac + +for INST in $SVCINST ; do + echo "$VERB $INST ..." >&2 + $DRYRUN $CMD $CMDARG "$INST" & +done + +wait From 25691d21c59d4f2048071b483b8f2b339e822711 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 19 Nov 2017 22:29:50 +0100 Subject: [PATCH 087/165] nut-driver-enumerator.sh.in : refactor a bit and add externally callable actions --- scripts/systemd/nut-driver-enumerator.sh.in | 136 ++++++++++++++++++-- 1 file changed, 126 insertions(+), 10 deletions(-) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index 8312d56661..bf5a949334 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -84,6 +84,7 @@ DEPSVC_NET_FULL_SYSTEMD="network-online.target" DEPREQ_NET_FULL_SYSTEMD="Wants" DEPSVC_NET_LOCAL_SYSTEMD="network.target" DEPREQ_NET_LOCAL_SYSTEMD="Wants" +SVCNAME_SYSTEMD="nut-driver" # Some or all of these FMRIs may be related to dynamically changing hardware # require_all) ;; # All cited services are running (online or degraded) @@ -100,6 +101,7 @@ DEPSVC_NET_FULL_SMF="svc:/network/physical" DEPREQ_NET_FULL_SMF="optional_all" DEPSVC_NET_LOCAL_SMF="svc:/network/loopback:default" DEPREQ_NET_LOCAL_SMF="optional_all" +SVCNAME_SMF="svc:/system/power/nut-driver" [ -z "${NUT_DRIVER_ENUMERATOR_CONF-}" ] && \ NUT_DRIVER_ENUMERATOR_CONF="${NUT_CONF_DIR}/nut-driver-enumerator.conf" @@ -136,17 +138,26 @@ UPSLIST_SVCS="" hook_registerInstance="" hook_unregisterInstance="" hook_listInstances="" +hook_listInstances_raw="" +hook_validInstanceName="" +hook_validFullUnitName="" case "${SERVICE_FRAMEWORK-}" in smf) hook_registerInstance="smf_registerInstance" hook_unregisterInstance="smf_unregisterInstance" hook_listInstances="smf_listInstances" + hook_listInstances_raw="smf_listInstances_raw" + hook_validInstanceName="smf_validInstanceName" + hook_validFullUnitName="smf_validFullUnitName" ;; systemd) hook_registerInstance="systemd_registerInstance" hook_unregisterInstance="systemd_unregisterInstance" hook_listInstances="systemd_listInstances" + hook_listInstances_raw="systemd_listInstances_raw" + hook_validInstanceName="systemd_validInstanceName" + hook_validFullUnitName="systemd_validFullUnitName" ;; "") echo "Error detecting the service-management framework on this OS" >&2 @@ -256,8 +267,15 @@ upsconf_debug() { echo "INST: [$1]: DRV='$_DRV' PORT='$_PRT' MEDIA='$_MED'" } +smf_validFullUnitName() { + echo "$SVCNAME_SMF:$1" +} +smf_validInstanceName() { + echo "`echo "$1" | md5sum | awk '{print $1}'`_" +} smf_registerInstance() { - /usr/sbin/svccfg -s nut-driver add "$1" || return + /usr/sbin/svccfg -s nut-driver add "$1" || \ + /usr/sbin/svccfg -s nut-driver add "`smf_validInstanceName "$1"`" || return DEPSVC="" DEPREQ="" @@ -300,13 +318,23 @@ smf_unregisterInstance() { /usr/sbin/svcadm disable -ts 'nut-driver:'"$1" || false /usr/sbin/svccfg -s nut-driver delete "$1" } -smf_listInstances() { +smf_listInstances_raw() { # Newer versions have pattern matching; older SMF might not have this luxury - /usr/bin/svcs -a -H -o fmri | egrep '/nut-driver:' | sed 's/^.*://' | sort -n + /usr/bin/svcs -a -H -o fmri | egrep '/nut-driver:' +} +smf_listInstances() { + smf_listInstances_raw | sed 's/^.*://' | sort -n } +systemd_validFullUnitName() { + echo "$SVCNAME_SYSTEMD@$1.service" +} +systemd_validInstanceName() { + echo "`echo "$1" | md5sum | awk '{print $1}'`_" +} systemd_registerInstance() { - /bin/systemctl enable 'nut-driver@'"$1" || return + /bin/systemctl enable 'nut-driver@'"$1" || \ + /bin/systemctl enable 'nut-driver@'"`systemd_validInstanceName "$1"`" || return DEPSVC="" DEPREQ="" @@ -347,8 +375,11 @@ systemd_unregisterInstance() { /bin/systemctl disable 'nut-driver@'"$1" rm -rf "/etc/systemd/system/nut-driver@$1.service.d" } +systemd_listInstances_raw() { + /bin/systemctl show 'nut-driver@*' -p Id | egrep '=nut-driver' | sed 's,^Id=,,' +} systemd_listInstances() { - /bin/systemctl show 'nut-driver@*' -p Id | egrep '=nut-driver' | sed -e 's/^.*@//' -e 's/\.service$//' | sort -n + systemd_listInstances_raw | sed -e 's/^.*@//' -e 's/\.service$//' | sort -n } upslist_readFile() { @@ -357,15 +388,16 @@ upslist_readFile() { # using specified protocol and media) if [ -n "$UPSCONF" ] && [ -f "$UPSCONF" ] && [ -r "$UPSCONF" ]; then [ -s "$UPSCONF" ] && \ - UPSCONF_DATA="$(egrep '[\[\=]' < "$UPSCONF" | sed -e 's,^['"$TABCHAR"'\ ]*,,' -e 's,^\#.*$,,' -e 's,['"$TABCHAR"'\ ]*$,,' -e 's,['"$TABCHAR"'\ ]*=['"$TABCHAR"'\ ]*,=,g' -e 's,=\"\([^\ '"$TABCHAR"']*\)\"$,=\1,' | egrep '^(\[.*\]|driver=|port=)')" || \ - UPSCONF_DATA="" + UPSCONF_DATA="$(egrep '[\[\=]' < "$UPSCONF" | sed -e 's,^['"$TABCHAR"'\ ]*,,' -e 's,^\#.*$,,' -e 's,['"$TABCHAR"'\ ]*$,,' -e 's,['"$TABCHAR"'\ ]*=['"$TABCHAR"'\ ]*,=,g' -e 's,=\"\([^\ '"$TABCHAR"']*\)\"$,=\1,' | egrep '^(\[.*\]|driver=|port=)')" \ + || UPSCONF_DATA="" else echo "FATAL: The '$UPSCONF' file does not exist or is not readable" >&2 return 2 fi [ -n "$UPSCONF_DATA" ] && \ - UPSLIST_FILE="$(echo "$UPSCONF_DATA" | egrep '^\[.*\]$' | sed 's,^\[\(.*\)\]$,\1,' | sort -n)" || UPSLIST_FILE="" + UPSLIST_FILE="$(echo "$UPSCONF_DATA" | egrep '^\[.*\]$' | sed 's,^\[\(.*\)\]$,\1,' | sort -n)" \ + || UPSLIST_FILE="" if [ -z "$UPSLIST_FILE" ] ; then echo "Error reading the '$UPSCONF' file or it does not declare any device configurations" >&2 # Ok to continue - we may end up removing all instances @@ -406,7 +438,7 @@ upslist_delSvcs() { done } -nut-driver-enumerator-main() { +nut_driver_enumerator_main() { ################# MAIN PROGRAM by default upslist_readFile || exit $? @@ -447,5 +479,89 @@ nut-driver-enumerator-main() { # By default, update wrapping of devices into services if [ $# = 0 ]; then - nut-driver-enumerator-main ; exit $? + nut_driver_enumerator_main ; exit $? fi + +usage() { + cat << EOF +$0 (no args) Update wrapping of devices into services +$0 --get-service-framework Print the detected service + management framework in this OS +$0 --list-devices Print list of devices in NUT config +$0 --list-services Print list of service instances + which wrap registered NUT devices (full name of service unit) +$0 --list-instances Print list of service instances + which wrap registered NUT devices (just instance suffix) +$0 --get-service-for-device DEV Print the full name of + service unit which wraps a NUT device named "DEV" +EOF +} + +while [ $# -gt 0 ]; do + case "$1" in + --help|-h|-help) usage; exit 0 ;; + --get-service-framework) echo "${SERVICE_FRAMEWORK}" ; exit 0 ;; + --list-devices) + upslist_readFile && \ + if [ -n "$UPSLIST_FILE" ] ; then + echo "=== The currently defined configurations in '$UPSCONF' are:" + echo "$UPSLIST_FILE" + exit 0 + fi + echo "No devices detected in '$UPSCONF'" >&2 + exit 1 + ;; + --list-services) + UPSLIST_SVCS_RAW="`$hook_listInstances_raw`" && \ + if [ -n "$UPSLIST_SVCS_RAW" ] ; then + echo "=== The currently defined service units are:" + echo "$UPSLIST_SVCS_RAW" + exit 0 + fi + echo "No service units detected" >&2 + exit 1 + ;; + --list-instances) + upslist_readSvcs "by user request" && \ + if [ -n "$UPSLIST_SVCS" ] ; then + echo "=== The currently defined service instances are:" + echo "$UPSLIST_SVCS" + exit 0 + fi + echo "No service instances detected" >&2 + exit 1 + ;; + --get-service-for-device) [ -z "$2" ] && echo "Device name argument required" >&2 && exit 1 + upslist_readSvcs "by user request" && [ -n "$UPSLIST_SVCS" ] \ + || { echo "No service instances detected" >&2 ; exit 1; } + UPSLIST_SVCS_RAW="`$hook_listInstances_raw`" && [ -n "$UPSLIST_SVCS_RAW" ] \ + || { echo "No service units detected" >&2 ; exit 1; } + # First pass over simple verbatim names + for INST in $UPSLIST_SVCS ; do + if [ "$INST" = "$2" ] ; then + for UNIT in $UPSLIST_SVCS_RAW ; do + if [ "$UNIT" = "`$hook_validFullUnitName "$INST"`" ] ; then + echo "$UNIT" + exit 0 + fi + done + fi + done + for INST in $UPSLIST_SVCS ; do + vINST="`$hook_validInstanceName "$INST"`" + if [ "$vINST" = "$2" ] ; then + for UNIT in $UPSLIST_SVCS_RAW ; do + if [ "$UNIT" = "`$hook_validFullUnitName "$vINST"`" ] ; then + echo "$UNIT" + exit 0 + fi + done + fi + done + echo "No service instances detected that match device '$2'" >&2 + exit 1 + ;; + *) echo "Unrecognized argument: $1" >&2 ; exit 1 ;; + esac + shift +done From 7894fe1132a4206e4587d76985175a7f0714e47b Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 19 Nov 2017 22:40:29 +0100 Subject: [PATCH 088/165] nut-driver-enumerator.sh.in : consider possible difference of device and service instance names --- scripts/systemd/nut-driver-enumerator.sh.in | 54 +++++++++++++++------ 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index bf5a949334..5a9af197a3 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -173,6 +173,7 @@ common_isFiled() { [ -n "$UPSLIST_FILE" ] && \ for UPSF in $UPSLIST_FILE ; do [ "$1" = "$UPSF" ] && return 0 + [ "`$hook_validInstanceName "$UPSF"`" = "$1" ] && return 0 done return 1 } @@ -181,10 +182,29 @@ common_isRegistered() { [ -n "$UPSLIST_SVCS" ] && \ for UPSS in $UPSLIST_SVCS ; do [ "$1" = "$UPSS" ] && return 0 + [ "`$hook_validInstanceName "$1"`" = "$UPSS" ] && return 0 done return 1 } +upslist_equals() { + # Compare list of DEVICES ($1) and SVCINSTs ($2) including mangling + [ "$1" = "$2" ] && return 0 + [ "`echo "$1" | wc -l`" = "`echo "$2" | wc -l`" ] || return $? + + _TMP_DEV_SVC="" + for _DEV in $1 ; do + for _SVC in $2 ; do + [ "$_DEV" = "$_SVC" ] \ + || [ "`$hook_validInstanceName "$_DEV"`" = "$_SVC" ] \ + && { [ -z "$_TMP_DEV_SVC" ] \ + && _TMP_DEV_SVC="$_DEV = $_SVC" \ + || _TMP_DEV_SVC="$_TMP_DEV_SVC +$_DEV = $_SVC" ; } + done + done +} + upsconf_getValue() { # "$1" = name of ups.conf section; $2 = name of config key; echo the value [ -n "$1" ] || return $? @@ -274,12 +294,15 @@ smf_validInstanceName() { echo "`echo "$1" | md5sum | awk '{print $1}'`_" } smf_registerInstance() { - /usr/sbin/svccfg -s nut-driver add "$1" || \ - /usr/sbin/svccfg -s nut-driver add "`smf_validInstanceName "$1"`" || return + DEVICE="$1" + SVCINST="$1" + /usr/sbin/svccfg -s nut-driver add "$DEVICE" || \ + { SVCINST="`smf_validInstanceName "$1"`" && \ + /usr/sbin/svccfg -s nut-driver add "$SVCINST" || return ; } DEPSVC="" DEPREQ="" - _MED="`upsconf_getMedia "$1"`" + _MED="`upsconf_getMedia "$DEVICE"`" case "$_MED" in usb) DEPSVC="$DEPSVC_USB_SMF" @@ -294,10 +317,10 @@ smf_registerInstance() { *) echo "WARNING: Unexpected NUT media type ignored: '$_MED'" >&2 ;; esac - TARGET_FMRI="nut-driver:$1" + TARGET_FMRI="nut-driver:$SVCINST" if [ -n "$DEPSVC" ]; then [ -n "$DEPREQ" ] || DEPREQ="optional_all" - echo "Adding '$DEPREQ' dependency for '$1' on '$DEPSVC'..." + echo "Adding '$DEPREQ' dependency for '$SVCINST' on '$DEPSVC'..." DEPPG="nut-driver-enumerator-generated" RESTARTON="refresh" @@ -333,12 +356,15 @@ systemd_validInstanceName() { echo "`echo "$1" | md5sum | awk '{print $1}'`_" } systemd_registerInstance() { - /bin/systemctl enable 'nut-driver@'"$1" || \ - /bin/systemctl enable 'nut-driver@'"`systemd_validInstanceName "$1"`" || return + DEVICE="$1" + SVCINST="$1" + /bin/systemctl enable 'nut-driver@'"$DEVICE" || \ + { SVCINST="`systemd_validInstanceName "$1"`" && \ + /bin/systemctl enable 'nut-driver@'"$SVCINST" || return ; } DEPSVC="" DEPREQ="" - _MED="`upsconf_getMedia "$1"`" + _MED="`upsconf_getMedia "$DEVICE"`" case "$_MED" in usb) DEPSVC="$DEPSVC_USB_SYSTEMD" @@ -354,10 +380,10 @@ systemd_registerInstance() { esac if [ -n "$DEPSVC" ]; then [ -n "$DEPREQ" ] || DEPREQ="#Wants" - echo "Adding '$DEPREQ'+After dependency for '$1' on '$DEPSVC'..." + echo "Adding '$DEPREQ'+After dependency for '$SVCINST' on '$DEPSVC'..." mkdir -p "/etc/systemd/system/nut-driver@$1.service.d" && \ - cat > "/etc/systemd/system/nut-driver@$1.service.d/nut-driver-enumerator-generated.conf" < "/etc/systemd/system/nut-driver@$SVCINST.service.d/nut-driver-enumerator-generated.conf" < Date: Sun, 19 Nov 2017 23:25:43 +0100 Subject: [PATCH 089/165] nut-driver-enumerator.sh.in : refactor md5 --- scripts/systemd/nut-driver-enumerator.sh.in | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index 5a9af197a3..55843fbb6f 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -287,11 +287,19 @@ upsconf_debug() { echo "INST: [$1]: DRV='$_DRV' PORT='$_PRT' MEDIA='$_MED'" } +calc_md5() { + _MD5="" + _MD5="`echo "$1" | md5sum 2>/dev/null | awk '{print $1}'`" && [ -n "$_MD5" ] || \ + { _MD5="`echo "$1" | openssl dgst -md5 2>/dev/null | awk '{print $NF}'`" && [ -n "$_MD5" ]; } || \ + return 1 + echo "$_MD5" +} + smf_validFullUnitName() { echo "$SVCNAME_SMF:$1" } smf_validInstanceName() { - echo "`echo "$1" | md5sum | awk '{print $1}'`_" + echo "MD5_`calc_md5 "$1"`" } smf_registerInstance() { DEVICE="$1" @@ -353,7 +361,7 @@ systemd_validFullUnitName() { echo "$SVCNAME_SYSTEMD@$1.service" } systemd_validInstanceName() { - echo "`echo "$1" | md5sum | awk '{print $1}'`_" + echo "MD5_`calc_md5 "$1"`" } systemd_registerInstance() { DEVICE="$1" From dfefda24b90c8a92206ea0d89472be90c34b1399 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 4 Dec 2017 09:53:54 +0100 Subject: [PATCH 090/165] Mention nut-driver-enumerator and upsdrvsvcctl in (systemd/|Solaris/)README --- scripts/Solaris/Makefile.am | 2 +- scripts/Solaris/README | 10 ++++++++++ scripts/systemd/README | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 scripts/Solaris/README diff --git a/scripts/Solaris/Makefile.am b/scripts/Solaris/Makefile.am index df9fa22937..a9e20c51c0 100644 --- a/scripts/Solaris/Makefile.am +++ b/scripts/Solaris/Makefile.am @@ -1,4 +1,4 @@ -EXTRA_DIST = makelocal.sh +EXTRA_DIST = makelocal.sh README PROTOTYPE_DIR = $(DESTDIR)@prefix@ SOLARIS_CHECK_TARGETS = diff --git a/scripts/Solaris/README b/scripts/Solaris/README new file mode 100644 index 0000000000..9053ff1cea --- /dev/null +++ b/scripts/Solaris/README @@ -0,0 +1,10 @@ +This directory contains init-scripts and SMF manifests and methods +for integration of NUT services with Solaris and descendant OSes. + +This also includes the nut-driver-enumerator.sh (service and implementation +method) and upsdrvsvcctl (tool) to manage NUT drivers as service instances, +which are stored in `../systemd/` subdirectory (portable codebase shared +with Linux systemd). + +Init-script solution contributed by numerous authors +SMF solution contributed by Jim Klimov diff --git a/scripts/systemd/README b/scripts/systemd/README index fb66e97243..925a80da2d 100644 --- a/scripts/systemd/README +++ b/scripts/systemd/README @@ -4,6 +4,9 @@ Service Manager. These files are automatically installed, upon detection (at configure time) of a systemd enabled system. +This also includes the nut-driver-enumerator.sh (service and implementation +method) and upsdrvsvcctl (tool) to manage NUT drivers as service instances. + Contributed by Michal Hlavinka Updated 2016-2017 by Michal Hrusecky and Jim Klimov From ab8a1d09e0312c60993fc5b1e0bc309bf39caee4 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 4 Dec 2017 10:03:39 +0100 Subject: [PATCH 091/165] upsdrvsvcctl.in : updated comments --- scripts/systemd/upsdrvsvcctl.in | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/systemd/upsdrvsvcctl.in b/scripts/systemd/upsdrvsvcctl.in index 6e26460f4e..9defc75bc4 100755 --- a/scripts/systemd/upsdrvsvcctl.in +++ b/scripts/systemd/upsdrvsvcctl.in @@ -32,8 +32,9 @@ Starts and stops UPS drivers via system service instances, see the $ENUMERATOR script for more details. -usage: ./drivers/upsdrvctl [OPTIONS] (start | stop | shutdown) [] +usage: $0 [OPTIONS] (start | stop | shutdown) [] +Options: -h display this help -t testing mode - prints actions without doing them -D raise debugging level @@ -41,6 +42,9 @@ usage: ./drivers/upsdrvctl [OPTIONS] (start | stop | shutdown) [] start only start driver for UPS stop stop all UPS drivers in ups.conf stop only stop driver for UPS + +Note: the "shutdown" options from original upsdrvctl are not currently +supported by this service management framework wrapper: # shutdown shutdown all UPS drivers in ups.conf # shutdown only shutdown UPS EOF @@ -90,7 +94,8 @@ case "$SERVICE_FRAMEWORK" in *) echo "Unrecognized SERVICE_FRAMEWORK: $SERVICE_FRAMEWORK" >&2 ; exit ;; esac -# TODO: Support shutdown of one or all UPSes by stopping its service and calling upsdrvctl on it +# TODO: Support shutdown of one or all UPSes by stopping its service +# and then calling the original upsdrvctl on it? case "$ACTION" in start) VERB="Starting" From f3b8bf81605f07e342a3d2faa242db86134251c8 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 4 Dec 2017 10:07:22 +0100 Subject: [PATCH 092/165] upsdrvsvcctl.in : added a resync option --- scripts/systemd/upsdrvsvcctl.in | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/systemd/upsdrvsvcctl.in b/scripts/systemd/upsdrvsvcctl.in index 9defc75bc4..cb25f4d489 100755 --- a/scripts/systemd/upsdrvsvcctl.in +++ b/scripts/systemd/upsdrvsvcctl.in @@ -43,6 +43,11 @@ Options: stop stop all UPS drivers in ups.conf stop only stop driver for UPS +usage: $0 [OPTIONS] resync + resync call $ENUMERATOR + to update the mapping of service instances for + NUT drivers to device sections in 'ups.conf' + Note: the "shutdown" options from original upsdrvctl are not currently supported by this service management framework wrapper: # shutdown shutdown all UPS drivers in ups.conf @@ -56,6 +61,7 @@ DRYRUN="" DEBUG=0 # UNUSED_PARAM so far while [ $# -gt 0 ]; do case "$1" in + resync) eval $DRYRUN $ENUMERATOR ; exit $? ;; start|stop) if [ -n "$2" ] ; then SVCINST="`$ENUMERATOR --get-service-for-device "$2"`" || exit ; shift ; fi ACTION="$1" ;; shutdown) echo "Action '$1' is not implemented via services currently" >&2 ; exit 1 ;; From 4eb2e99f7c1f3f3942bada43bc23b00ad82675e5 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 4 Dec 2017 12:45:21 +0100 Subject: [PATCH 093/165] upsdrvsvcctl.in : reformat prettily --- scripts/systemd/upsdrvsvcctl.in | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/systemd/upsdrvsvcctl.in b/scripts/systemd/upsdrvsvcctl.in index cb25f4d489..506146f665 100755 --- a/scripts/systemd/upsdrvsvcctl.in +++ b/scripts/systemd/upsdrvsvcctl.in @@ -58,11 +58,16 @@ EOF ACTION="" SVCINST="" DRYRUN="" -DEBUG=0 # UNUSED_PARAM so far +DEBUG=0 +# Note: DEBUG is UNUSED_PARAM so far while [ $# -gt 0 ]; do case "$1" in resync) eval $DRYRUN $ENUMERATOR ; exit $? ;; - start|stop) if [ -n "$2" ] ; then SVCINST="`$ENUMERATOR --get-service-for-device "$2"`" || exit ; shift ; fi + start|stop) + if [ -n "$2" ] ; then + SVCINST="`$ENUMERATOR --get-service-for-device "$2"`" || exit + shift + fi ACTION="$1" ;; shutdown) echo "Action '$1' is not implemented via services currently" >&2 ; exit 1 ;; -t) DRYRUN="echo" ;; From ed6743f1a826b86b5b14a8a968d520e83473e01a Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 4 Dec 2017 10:38:30 +0100 Subject: [PATCH 094/165] Rename Solaris SMF services to match systemd patterns and ease life for sysadmins --- configure.ac | 7 +- scripts/Solaris/.gitignore | 7 +- scripts/Solaris/Makefile.am | 7 +- .../{nut-client.xml.in => nut-monitor.xml.in} | 6 +- scripts/Solaris/nut-server.xml.in | 148 ++++++++++++++++++ scripts/Solaris/nut.xml.in | 89 ++--------- scripts/Solaris/postinstall.in | 10 +- scripts/Solaris/preremove.in | 2 +- .../{svc-nut-client.in => svc-nut-monitor.in} | 0 .../Solaris/{svc-nut.in => svc-nut-server.in} | 0 scripts/systemd/nut-driver-enumerator.sh.in | 6 + 11 files changed, 189 insertions(+), 93 deletions(-) rename scripts/Solaris/{nut-client.xml.in => nut-monitor.xml.in} (93%) create mode 100644 scripts/Solaris/nut-server.xml.in rename scripts/Solaris/{svc-nut-client.in => svc-nut-monitor.in} (100%) rename scripts/Solaris/{svc-nut.in => svc-nut-server.in} (100%) diff --git a/configure.ac b/configure.ac index 35380ea9be..a2eab79752 100644 --- a/configure.ac +++ b/configure.ac @@ -1741,10 +1741,11 @@ AC_OUTPUT([ scripts/systemd/upsdrvsvcctl scripts/Solaris/nut-driver-enumerator.xml scripts/Solaris/nut-driver.xml - scripts/Solaris/nut-client.xml + scripts/Solaris/nut-monitor.xml + scripts/Solaris/nut-server.xml scripts/Solaris/nut.xml - scripts/Solaris/svc-nut - scripts/Solaris/svc-nut-client + scripts/Solaris/svc-nut-server + scripts/Solaris/svc-nut-monitor scripts/Solaris/Makefile scripts/Solaris/pkginfo scripts/Solaris/preinstall diff --git a/scripts/Solaris/.gitignore b/scripts/Solaris/.gitignore index 4bf01c06b2..4bfd7c9314 100644 --- a/scripts/Solaris/.gitignore +++ b/scripts/Solaris/.gitignore @@ -5,10 +5,11 @@ /preremove /postremove /preproto.pl -/svc-nut -/svc-nut-client +/svc-nut-server +/svc-nut-monitor /nut-driver.xml /nut-driver-enumerator.xml -/nut-client.xml +/nut-monitor.xml +/nut-server.xml /nut.xml /NUT*.local.gz diff --git a/scripts/Solaris/Makefile.am b/scripts/Solaris/Makefile.am index a9e20c51c0..3a127f0018 100644 --- a/scripts/Solaris/Makefile.am +++ b/scripts/Solaris/Makefile.am @@ -4,14 +4,15 @@ SOLARIS_CHECK_TARGETS = SOLARIS_SMF_MANIFESTS = \ nut.xml \ - nut-client.xml \ + nut-server.xml \ + nut-monitor.xml \ nut-driver.xml \ nut-driver-enumerator.xml SOLARIS_SMF_METHODSCRIPTS = \ ../systemd/nut-driver-enumerator.sh \ - svc-nut \ - svc-nut-client + svc-nut-server \ + svc-nut-monitor if WITH_SOLARIS_SMF # OS equivalent of /lib/svc/method and /var/svc/manifest/application diff --git a/scripts/Solaris/nut-client.xml.in b/scripts/Solaris/nut-monitor.xml.in similarity index 93% rename from scripts/Solaris/nut-client.xml.in rename to scripts/Solaris/nut-monitor.xml.in index f957382f51..fceb8af700 100644 --- a/scripts/Solaris/nut-client.xml.in +++ b/scripts/Solaris/nut-monitor.xml.in @@ -7,9 +7,9 @@ # --> - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/Solaris/nut.xml.in b/scripts/Solaris/nut.xml.in index 4cadcbd662..cb35a761d2 100644 --- a/scripts/Solaris/nut.xml.in +++ b/scripts/Solaris/nut.xml.in @@ -3,7 +3,7 @@ @@ -15,102 +15,39 @@ Configure a default instance for the service since it doesn't require additional configuration intervention before it starts. --> - + - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - + + exec='/usr/sbin/svcadm disable -ts svc:/system/power/nut-monitor:default ; /usr/sbin/svcadm disable -ts svc:/system/power/nut-server:default ; @sbindir@/upsdrvsvcctl stop' + timeout_seconds='120' /> @@ -36,13 +36,16 @@ The nut start/stop methods. --> - + + - NUT ups information service + Service for common startup or shutdown of NUT-related services From 457823bd0eb6ec6ec3539d4a5b9a9b8953d45d93 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 14 Dec 2017 10:32:10 +0100 Subject: [PATCH 104/165] nut-driver-enumerator.sh.in : when amending service unit instance config for systemd, update the Description to state the NUT device section name --- scripts/systemd/nut-driver-enumerator.sh.in | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index 3e2860b58a..32c12db3ef 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -398,6 +398,7 @@ systemd_registerInstance() { # Customization generated `date -u` by nut-driver-enumerator for NUT device '$DEVICE' # DO NOT EDIT: This file would be removed or overwritten by that service [Unit] +Description=Network UPS Tools - device driver for NUT device '$DEVICE' ${DEPREQ}=${DEPSVC} After=${DEPSVC} EOF From cb13743ac9f9bf14af33cad8cf4b1efd5f3aca69 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 8 Mar 2018 11:26:24 +0100 Subject: [PATCH 105/165] nut-driver-enumerator.sh.in : support common NUT_CONFPATH envvar --- scripts/systemd/nut-driver-enumerator.sh.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/systemd/nut-driver-enumerator.sh.in index 32c12db3ef..c4b342d262 100755 --- a/scripts/systemd/nut-driver-enumerator.sh.in +++ b/scripts/systemd/nut-driver-enumerator.sh.in @@ -69,7 +69,7 @@ # Directory where NUT configs are located, e.g. /etc/nut or /etc/ups # Set at package configuration, compiled into daemons and drivers prefix="@prefix@" -[ -n "${NUT_CONF_DIR-}" ] || NUT_CONF_DIR="@sysconfdir@" +[ -n "${NUT_CONFPATH-}" ] || NUT_CONFPATH="@sysconfdir@" # Third-party services to depend on (can be overridden by config file) ### Note that for systemd+udev integration, it may be better to set up @@ -104,14 +104,14 @@ DEPREQ_NET_LOCAL_SMF="optional_all" SVCNAME_SMF="svc:/system/power/nut-driver" [ -z "${NUT_DRIVER_ENUMERATOR_CONF-}" ] && \ - NUT_DRIVER_ENUMERATOR_CONF="${NUT_CONF_DIR}/nut-driver-enumerator.conf" + NUT_DRIVER_ENUMERATOR_CONF="${NUT_CONFPATH}/nut-driver-enumerator.conf" [ -s "${NUT_DRIVER_ENUMERATOR_CONF}" ] && \ echo "Sourcing config file: ${NUT_DRIVER_ENUMERATOR_CONF}" && \ . "${NUT_DRIVER_ENUMERATOR_CONF}" [ -z "${UPSCONF-}" ] && \ - UPSCONF="${NUT_CONF_DIR}/ups.conf" + UPSCONF="${NUT_CONFPATH}/ups.conf" # Start a freshly-registered unit? [ -z "${AUTO_START-}" ] && AUTO_START=yes From 712b6cf76ef15b132c3a6ebb42a81a559d096147 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 8 Mar 2018 11:51:43 +0100 Subject: [PATCH 106/165] Add upsdrvsvcctl.txt manpage and references to upsdrvsvcctl in other docs --- README | 16 +++- docs/FAQ.txt | 4 + docs/features.txt | 7 +- docs/man/Makefile.am | 3 + docs/man/upsdrvctl.txt | 5 +- docs/man/upsdrvsvcctl.txt | 161 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 192 insertions(+), 4 deletions(-) create mode 100644 docs/man/upsdrvsvcctl.txt diff --git a/README b/README index 247dc0a166..0253accc2a 100644 --- a/README +++ b/README @@ -120,8 +120,9 @@ The entry in `ups.conf` looks like this: driver = apcsmart port = /dev/ttyS1 -To start and stop drivers, use upsdrvctl. By default, it will start or -stop every UPS in the config file: +To start and stop drivers, use upsdrvctl of upsdrvsvcctl (on operating +systems with a supported service management framework). By default, +it will start or stop every UPS in the config file: /usr/local/ups/sbin/upsdrvctl start /usr/local/ups/sbin/upsdrvctl stop @@ -131,6 +132,17 @@ However, you can also just start or stop one by adding its name: /usr/local/ups/sbin/upsdrvctl start sparky /usr/local/ups/sbin/upsdrvctl stop sparky +On operating systems with a supported service management framework, +you might wrap your NUT drivers into individual services instances +with: + + /usr/local/ups/sbin/upsdrvsvcctl resync + +and then manage those service instances with commands like: + + /usr/local/ups/sbin/upsdrvsvcctl start sparky + /usr/local/ups/sbin/upsdrvsvcctl stop sparky + To find the driver name for your device, refer to the section below called "HARDWARE SUPPORT TABLE". diff --git a/docs/FAQ.txt b/docs/FAQ.txt index 6649bed64b..970f67e4b4 100644 --- a/docs/FAQ.txt +++ b/docs/FAQ.txt @@ -271,6 +271,10 @@ connect to a driver, and it should say why it can't connect. Note: if you jumped in with both feet and didn't follow the INSTALL.nut document, you probably started upsd by itself. You have to run 'upsdrvctl start' to start the drivers after configuring ups.conf. +On operating systems with a supported service management framework, +you might wrap your NUT drivers into individual services instances +with 'upsdrvsvcctl resync' and then manage those with commands like +'upsdrvsvcctl stop' and 'upsdrvsvcctl start'. == Why don't the pathnames in your documentation match the package I installed? diff --git a/docs/features.txt b/docs/features.txt index eef38b6d21..be67292908 100644 --- a/docs/features.txt +++ b/docs/features.txt @@ -137,9 +137,14 @@ supported by the UPS hardware. - All drivers are started and stopped with one common program. Starting one is as easy as starting ten: 'upsdrvctl start'. +- For operating systems with a supported service management framework, you can +manage the NUT drivers wrapped into independent service instances using the +'upsdrvsvcctl' instead, and gain the benefits of automated restart as well as +possibility to define further dependencies between your OS components. + - Shutdowns and other procedures may be tested without stressing actual UPS hardware by simulating status values with the dummy-ups pseudo-driver. Anything -which can happen in a driver can be replicated with dummy-ups. +which can happen in a driver can be replicated with dummy-ups. Monitoring diagrams ------------------- diff --git a/docs/man/Makefile.am b/docs/man/Makefile.am index 94a16b4d9c..aa38906af0 100644 --- a/docs/man/Makefile.am +++ b/docs/man/Makefile.am @@ -51,6 +51,7 @@ SRC_CLIENT_PAGES = \ upscmd.txt \ upsd.txt \ upsdrvctl.txt \ + upsdrvsvcctl.txt \ upslog.txt \ upsmon.txt \ upsrw.txt \ @@ -63,6 +64,7 @@ MAN_CLIENT_PAGES = \ upscmd.8 \ upsd.8 \ upsdrvctl.8 \ + upsdrvsvcctl.8 \ upslog.8 \ upsmon.8 \ upsrw.8 \ @@ -77,6 +79,7 @@ HTML_CLIENT_MANS = \ upscmd.html \ upsd.html \ upsdrvctl.html \ + upsdrvsvcctl.html \ upslog.html \ upsmon.html \ upsrw.html \ diff --git a/docs/man/upsdrvctl.txt b/docs/man/upsdrvctl.txt index 68a4b8c473..7a788c41c6 100644 --- a/docs/man/upsdrvctl.txt +++ b/docs/man/upsdrvctl.txt @@ -22,6 +22,9 @@ whenever possible. When used properly, upsdrvctl lets you maintain identical startup scripts across multiple systems with different UPS configurations. +Note: For operating systems with service management frameworks, such as +Solaris SMF or Linux systemd, the *upsdrvsvcctl* may be a better choice. + OPTIONS ------- @@ -97,7 +100,7 @@ background. SEE ALSO -------- -linkman:nutupsdrv[8], linkman:upsd[8], linkman:ups.conf[5] +linkman:upsdrvsvcctl[8], linkman:nutupsdrv[8], linkman:upsd[8], linkman:ups.conf[5] Internet resources: ~~~~~~~~~~~~~~~~~~~ diff --git a/docs/man/upsdrvsvcctl.txt b/docs/man/upsdrvsvcctl.txt new file mode 100644 index 0000000000..5b88b6b29c --- /dev/null +++ b/docs/man/upsdrvsvcctl.txt @@ -0,0 +1,161 @@ +UPSDRVSVCCTL(8) +=============== + +NAME +---- + +upsdrvsvcctl - UPS driver service instance controller + +SYNOPSIS +-------- +*upsdrvsvcctl* -h + +*upsdrvsvcctl* ['OPTIONS'] {start | stop } ['ups'] + +DESCRIPTION +----------- + +*upsdrvsvcctl* provides a uniform interface for controlling your UPS +drivers wrapped into service instances on platforms which support that +(currently this covers Linux distributions with systemd and systems +derived from Solaris 10 codebase, including proprietary Sun/Oracle +Solaris and numerous open-source illumos distributions with SMF). + +When used properly, upsdrvsvcctl lets you maintain identical startup +scripts across multiple systems with different UPS configurations. +The goal of this solution is to allow the services of *upsd* data +server to start up even if some of the power devices are currently +not accessible, and for NUT drivers to be automatically restarted +by the system in case of problems (driver bug, startup failure). + +Independent service instances for each NUT driver also allow one +to configure further dependencies, such as that networking must be +available for SNMP and similar drivers (but is not needed for +local-medium drivers such as serial or USB). + +The old monolithic "all or nothing" solution requiring that all +drivers must be running, which sufficed for deployments with a few +UPSes, did not really work well for monitoring larger deployments. +It was also not easy to strike a pre-packaged balance between early +UPS protection for USB/serial home setups vs. waiting for network +on larger ones. + +*upsdrvsvcctl* is a script which mimicks the operation of *upsdrvctl* +program (where possible) to provide similar end-user experience when +manipulating drivers wrapped into service instances rather than as +directly executed daemons. It relies on *nut-driver-enumerator.sh* +for a large part of actual operations. + +You should use upsdrvsvcctl instead of direct calls to the drivers +and daemon-based management with *upsdrvctl* whenever possible (that +is, for "production" use on compatible OSes). Otherwise (testing, +other OSes) the *upsdrvctl* is a recommended option. + +OPTIONS +------- + +*-h*:: +Display the help text. + +*-t*:: +Enable testing mode. Testing mode makes upsdrvsvcctl display the actions +it would execute without actually doing them. + + + +OPTIONS OF UPSDRVCTL NOT (CURRENTLY) APPLICABLE TO UPSDRVSVCCTL +--------------------------------------------------------------- + +Options like '-r', '-u' or '-D' could be handled by properties of the +service instances themselves, with this script helping to configure +them (assuming proper privileges of the user who called it). This is +not a "production" use case, though, to change such options on a +configured system -- so for experiments and troubleshooting, it may +be better to stop the service instance and play with *upsdrvctl* +directly. + +*-r* 'directory':: +If starting a driver, this value will direct it to *chroot*(2) into +'directory'. This can be useful when securing systems. + +This may be set in the ups.conf with "chroot" in the global section. + +*-u* 'username':: +If starting a driver, this value will direct it to *setuid*(2) to +the user id associated with 'username'. + +If the driver is started as root without specifying this value, it will +use the username that was compiled into the binary. This defaults to +"nobody", and is far from ideal. + +This may be set in ups.conf with "user" in the global section. + +*-D*:: +Raise the driver debug level. Use this multiple times for additional +details. + +COMMANDS +-------- + +*upsdrvsvcctl* supports two of the commands processed by *upsdrvctl* -- +start and stop (Note: shutdown is not currently supported; it may be better +to use *upsdrvctl* directly for that, at this time). +They take an optional argument which is a UPS name from linkman:ups.conf[5]. +Without that argument, they operate on every UPS that is currently +configured. + +*start*:: +Start the UPS driver(s). In case of failure, further attempts may be executed +by using the 'maxretry' and 'retrydelay' options - see linkman:ups.conf[5]. + +*stop*:: +Stop the UPS driver(s). + +*upsdrvsvcctl* also supports further operations for troubleshooting the +mapping of NUT driver section names to the service instance names (which +may differ due to limitations of various systems). + +*list*:: +list the currently active mapping of service instances to device sections + +*resync*:: +update the mapping of service instances for NUT drivers to device section +names used in 'ups.conf' (register new instances, tear down obsoleted ones). + + +COMMANDS OF UPSDRVCTL NOT (CURRENTLY) APPLICABLE TO UPSDRVSVCCTL +---------------------------------------------------------------- + +*shutdown*:: +Command the UPS driver(s) to run their shutdown sequence. Drivers are +stopped according to their sdorder value - see linkman:ups.conf[5]. + +WARNING: this will probably power off your computers, so don't +play around with this option. Only use it when your systems are prepared +to lose power. + +NOTE: refer to linkman:ups.conf[5] for using the *nowait* parameter. + +ENVIRONMENT VARIABLES +--------------------- + +*NUT_CONFPATH* is the path name of the directory that contains +`upsd.conf` and other configuration files. If this variable is not set, +*upsdrvsvcctl* (or rather *nut-driver-enumerator.sh*) would use a built-in +default, which is often `/usr/local/ups/etc`. + +DIAGNOSTICS +----------- + +upsdrvsvcctl will return a nonzero exit code if it encounters an error +while performing the desired operation. This will also happen if a +driver takes longer than the 'maxstartdelay' period to enter the +background. + +SEE ALSO +-------- +linkman:upsdrvctl[8], linkman:nutupsdrv[8], linkman:upsd[8], linkman:ups.conf[5] + +Internet resources: +~~~~~~~~~~~~~~~~~~~ +The NUT (Network UPS Tools) home page: http://www.networkupstools.org/ From b5dc03d63f8fd6774379c04dbccf6aa341c6efc7 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 8 Mar 2018 13:42:58 +0100 Subject: [PATCH 107/165] upsdrvsvcctl.txt manpage : refer to service management system logs --- docs/man/upsdrvsvcctl.txt | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/man/upsdrvsvcctl.txt b/docs/man/upsdrvsvcctl.txt index 5b88b6b29c..103e64e730 100644 --- a/docs/man/upsdrvsvcctl.txt +++ b/docs/man/upsdrvsvcctl.txt @@ -152,6 +152,30 @@ while performing the desired operation. This will also happen if a driver takes longer than the 'maxstartdelay' period to enter the background. +Any messages issued by the *upsdrvctl* program used to start the NUT +drivers as part of the service instances' implementations, or by the +drivers themselves, will be logged by the service management framework +facilities and will not appear in your interactive terminal used to +manage the driver. Use 'upsdrvsvcctl list' to find out the service +instance name for the NUT driver (section name) you are interested in. +Then look up the service logs (where the outputs of the service +implementation program as well as the framework messages about +this service are stored), as suggested below: + +*Linux systemd*:: +Messages will normally be kept in the service journal, so: + + journalctl -lu nut-driver@instancename + +Note that your local system configuration may be impacted by such +nuances as passing the journal data to a standard syslog server, +and/or by having a small cache for locally stored journal messages +(so older entries would disappear). There may also be or not be a +copy of the journals stored in the filesystem. + +*Solaris SMF*:: +Look for `/var/svc/log/system-power-nut-driver:instancename.log` file. + SEE ALSO -------- linkman:upsdrvctl[8], linkman:nutupsdrv[8], linkman:upsd[8], linkman:ups.conf[5] From 5f4db6c009c844ec5c167b12aa0eae5a3416372c Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 8 Mar 2018 14:40:14 +0100 Subject: [PATCH 108/165] upsdrvsvcctl : support "list upsname" CLI action to help troubleshooting --- docs/man/upsdrvsvcctl.txt | 10 ++++++---- scripts/systemd/upsdrvsvcctl.in | 9 ++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/man/upsdrvsvcctl.txt b/docs/man/upsdrvsvcctl.txt index 103e64e730..ec3ca06cdd 100644 --- a/docs/man/upsdrvsvcctl.txt +++ b/docs/man/upsdrvsvcctl.txt @@ -156,10 +156,12 @@ Any messages issued by the *upsdrvctl* program used to start the NUT drivers as part of the service instances' implementations, or by the drivers themselves, will be logged by the service management framework facilities and will not appear in your interactive terminal used to -manage the driver. Use 'upsdrvsvcctl list' to find out the service -instance name for the NUT driver (section name) you are interested in. -Then look up the service logs (where the outputs of the service -implementation program as well as the framework messages about +manage the driver. + +Use `upsdrvsvcctl list` or `upsdrvsvcctl list NUTdevice` to find out +the service instance name for the NUT driver (section name) you are +interested in. Then look up the service logs (where the outputs of the +service implementation program as well as the framework messages about this service are stored), as suggested below: *Linux systemd*:: diff --git a/scripts/systemd/upsdrvsvcctl.in b/scripts/systemd/upsdrvsvcctl.in index 92befaa242..330990157e 100755 --- a/scripts/systemd/upsdrvsvcctl.in +++ b/scripts/systemd/upsdrvsvcctl.in @@ -70,6 +70,7 @@ usage: $0 [OPTIONS] resync NUT drivers to device sections in 'ups.conf' list call $ENUMERATOR to list the mapping of service instances to device sections + list (optionally return the service instance name for one device) Note: the "shutdown" options from original upsdrvctl are not currently supported by this service management framework wrapper: @@ -86,7 +87,13 @@ DEBUG=0 while [ $# -gt 0 ]; do case "$1" in resync) eval $DRYRUN $ENUMERATOR ; exit $? ;; - list) eval $ENUMERATOR --list-services-for-devices ; exit $? ;; + list) + if [ -n "$2" ] ; then + eval $ENUMERATOR --get-service-for-device "$2" ; exit $? + else + eval $ENUMERATOR --list-services-for-devices ; exit $? + fi + ;; start|stop) if [ -n "$2" ] ; then SVCINST="`$ENUMERATOR --get-service-for-device "$2"`" || exit From 47f8a4d5171889cb50862775819e3e85fc02052d Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 8 Mar 2018 15:01:00 +0100 Subject: [PATCH 109/165] upsdrvsvcctl : add handling for "shutdown" command --- docs/man/upsdrvsvcctl.txt | 16 ++++++++++------ scripts/systemd/upsdrvsvcctl.in | 23 +++++++++++++++++------ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/docs/man/upsdrvsvcctl.txt b/docs/man/upsdrvsvcctl.txt index ec3ca06cdd..3298ca9888 100644 --- a/docs/man/upsdrvsvcctl.txt +++ b/docs/man/upsdrvsvcctl.txt @@ -97,12 +97,16 @@ details. COMMANDS -------- -*upsdrvsvcctl* supports two of the commands processed by *upsdrvctl* -- -start and stop (Note: shutdown is not currently supported; it may be better -to use *upsdrvctl* directly for that, at this time). -They take an optional argument which is a UPS name from linkman:ups.conf[5]. -Without that argument, they operate on every UPS that is currently -configured. +*upsdrvsvcctl* supports three of the commands processed by *upsdrvctl* -- +start, stop and shutdown. They take an optional argument which is a UPS +name from linkman:ups.conf[5]. Without that argument, they operate on +every UPS that is currently configured. + +Note: shutdown is currently supported by stopping the driver service +instances to release the potentially held ports etc., calling the +*upsdrvctl* directly for issuing the shutdown command, and restarting +the driver service instances to reconnect when the device comes back +online. *start*:: Start the UPS driver(s). In case of failure, further attempts may be executed diff --git a/scripts/systemd/upsdrvsvcctl.in b/scripts/systemd/upsdrvsvcctl.in index 330990157e..2849df4ffa 100755 --- a/scripts/systemd/upsdrvsvcctl.in +++ b/scripts/systemd/upsdrvsvcctl.in @@ -64,6 +64,13 @@ Options: stop stop all UPS drivers in ups.conf stop only stop driver for UPS +Note: the "shutdown" options from original upsdrvctl are not currently +directly supported by this service management framework wrapper; instead +they are passed to the native upsdrvctl binary (your current user account +should have sufficient permissions to do that all): + shutdown shutdown all UPS drivers in ups.conf + shutdown only shutdown UPS + usage: $0 [OPTIONS] resync resync call $ENUMERATOR to update the mapping of service instances for @@ -71,11 +78,6 @@ usage: $0 [OPTIONS] resync list call $ENUMERATOR to list the mapping of service instances to device sections list (optionally return the service instance name for one device) - -Note: the "shutdown" options from original upsdrvctl are not currently -supported by this service management framework wrapper: -# shutdown shutdown all UPS drivers in ups.conf -# shutdown only shutdown UPS EOF } @@ -100,7 +102,16 @@ while [ $# -gt 0 ]; do shift fi ACTION="$1" ;; - shutdown) echo "Action '$1' is not implemented via services currently" >&2 ; exit 1 ;; + shutdown) + echo "NOTE: Action '$1' is not implemented via services currently, will call upsdrvctl" >&2 + echo "Stopping the driver service instance(s) to release exclusive resources, if any..." >&2 + RES=0 + $0 stop $2 + @SBINDIR@/upsdrvctl $2 || RES=$? + echo "Starting the driver service instance(s) so they can reconnect when the UPS returns..." >&2 + $0 start $2 + exit $RES + ;; -t) DRYRUN="echo" ;; -h) usage; exit 0 ;; -d) DEBUG="`expr $DEBUG + 1`" ;; From 6893ba7d4990d9dc0a5a31067dd51a7491ef1cb9 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 8 Mar 2018 15:33:52 +0100 Subject: [PATCH 110/165] Docs about upsdrvsvcctl - clarify that it may not be preinstalled with non-SMF/non-systemd OS packages --- README | 6 +++--- docs/FAQ.txt | 4 +++- docs/config-notes.txt | 15 +++++++++------ docs/man/upsdrvsvcctl.txt | 5 +++++ 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/README b/README index 0253accc2a..685bdbd9d4 100644 --- a/README +++ b/README @@ -120,9 +120,9 @@ The entry in `ups.conf` looks like this: driver = apcsmart port = /dev/ttyS1 -To start and stop drivers, use upsdrvctl of upsdrvsvcctl (on operating -systems with a supported service management framework). By default, -it will start or stop every UPS in the config file: +To start and stop drivers, use upsdrvctl of upsdrvsvcctl (installed on +operating systems with a service management framework supported by NUT). +By default, it will start or stop every UPS in the config file: /usr/local/ups/sbin/upsdrvctl start /usr/local/ups/sbin/upsdrvctl stop diff --git a/docs/FAQ.txt b/docs/FAQ.txt index 970f67e4b4..b81fd1d141 100644 --- a/docs/FAQ.txt +++ b/docs/FAQ.txt @@ -271,10 +271,12 @@ connect to a driver, and it should say why it can't connect. Note: if you jumped in with both feet and didn't follow the INSTALL.nut document, you probably started upsd by itself. You have to run 'upsdrvctl start' to start the drivers after configuring ups.conf. + On operating systems with a supported service management framework, you might wrap your NUT drivers into individual services instances with 'upsdrvsvcctl resync' and then manage those with commands like -'upsdrvsvcctl stop' and 'upsdrvsvcctl start'. +'upsdrvsvcctl stop' and 'upsdrvsvcctl start' (note that on other +systems this tool may be not preinstalled via packaging). == Why don't the pathnames in your documentation match the package I installed? diff --git a/docs/config-notes.txt b/docs/config-notes.txt index 9df22c823c..91c5b9613f 100644 --- a/docs/config-notes.txt +++ b/docs/config-notes.txt @@ -207,12 +207,15 @@ which monitor a datacenter full of UPSes. For this reason, NUT starting with version 2.7.5 supports startup of its drivers as independent instances of a `nut-driver` service under the Linux -systemd and Solaris/illumos SMF service-management frameworks. Such service -instances have their own and independent life-cycle, including parallel -driver start and stop processing, and retries of startup in case of failure -as implemented by the service framework in the OS. The systemd solution also -includes a `nut-driver.target` as a checkpoint that all defined drivers have -indeed started up. +systemd and Solaris/illumos SMF service-management frameworks (corresponding +files and scripts may be not preinstalled in packaging for other systems). + +Such service instances have their own and independent life-cycle, including +parallel driver start and stop processing, and retries of startup in case of +failure as implemented by the service framework in the OS. The Linux systemd +solution also includes a `nut-driver.target` as a checkpoint that all defined +drivers have indeed started up (as well as being a singular way to enable or +disable startup of drivers). In both cases, a service named `nut-driver-enumerator` is registered, and when it is (re-)started it scans the currently defined device sections in diff --git a/docs/man/upsdrvsvcctl.txt b/docs/man/upsdrvsvcctl.txt index 3298ca9888..36d3301acf 100644 --- a/docs/man/upsdrvsvcctl.txt +++ b/docs/man/upsdrvsvcctl.txt @@ -20,13 +20,18 @@ drivers wrapped into service instances on platforms which support that (currently this covers Linux distributions with systemd and systems derived from Solaris 10 codebase, including proprietary Sun/Oracle Solaris and numerous open-source illumos distributions with SMF). +It may be not installed in packaging for other operating systems. When used properly, upsdrvsvcctl lets you maintain identical startup scripts across multiple systems with different UPS configurations. + The goal of this solution is to allow the services of *upsd* data server to start up even if some of the power devices are currently not accessible, and for NUT drivers to be automatically restarted by the system in case of problems (driver bug, startup failure). +It also allows for faster startup of systems which monitor several +devices, by letting each driver to start in parallel with others, +and not with a sequential loop like was done previously. Independent service instances for each NUT driver also allow one to configure further dependencies, such as that networking must be From 2a45fe90419e91dd29582e75fbf57c5865cac8da Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 8 Mar 2018 15:38:52 +0100 Subject: [PATCH 111/165] Pass spellcheck for upsdrvsvcctl doc updates --- docs/FAQ.txt | 2 +- docs/config-notes.txt | 2 +- docs/man/upsdrvsvcctl.txt | 8 ++++---- docs/nut.dict | 6 +++++- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/docs/FAQ.txt b/docs/FAQ.txt index b81fd1d141..3a14105db9 100644 --- a/docs/FAQ.txt +++ b/docs/FAQ.txt @@ -276,7 +276,7 @@ On operating systems with a supported service management framework, you might wrap your NUT drivers into individual services instances with 'upsdrvsvcctl resync' and then manage those with commands like 'upsdrvsvcctl stop' and 'upsdrvsvcctl start' (note that on other -systems this tool may be not preinstalled via packaging). +systems this tool may be not pre-installed via packaging). == Why don't the pathnames in your documentation match the package I installed? diff --git a/docs/config-notes.txt b/docs/config-notes.txt index 91c5b9613f..18c8f3894f 100644 --- a/docs/config-notes.txt +++ b/docs/config-notes.txt @@ -208,7 +208,7 @@ which monitor a datacenter full of UPSes. For this reason, NUT starting with version 2.7.5 supports startup of its drivers as independent instances of a `nut-driver` service under the Linux systemd and Solaris/illumos SMF service-management frameworks (corresponding -files and scripts may be not preinstalled in packaging for other systems). +files and scripts may be not pre-installed in packaging for other systems). Such service instances have their own and independent life-cycle, including parallel driver start and stop processing, and retries of startup in case of diff --git a/docs/man/upsdrvsvcctl.txt b/docs/man/upsdrvsvcctl.txt index 36d3301acf..0008b89487 100644 --- a/docs/man/upsdrvsvcctl.txt +++ b/docs/man/upsdrvsvcctl.txt @@ -45,7 +45,7 @@ It was also not easy to strike a pre-packaged balance between early UPS protection for USB/serial home setups vs. waiting for network on larger ones. -*upsdrvsvcctl* is a script which mimicks the operation of *upsdrvctl* +*upsdrvsvcctl* is a script which mimics the operation of *upsdrvctl* program (where possible) to provide similar end-user experience when manipulating drivers wrapped into service instances rather than as directly executed daemons. It relies on *nut-driver-enumerator.sh* @@ -167,7 +167,7 @@ drivers themselves, will be logged by the service management framework facilities and will not appear in your interactive terminal used to manage the driver. -Use `upsdrvsvcctl list` or `upsdrvsvcctl list NUTdevice` to find out +Use `upsdrvsvcctl list` or `upsdrvsvcctl list NUT-device` to find out the service instance name for the NUT driver (section name) you are interested in. Then look up the service logs (where the outputs of the service implementation program as well as the framework messages about @@ -176,7 +176,7 @@ this service are stored), as suggested below: *Linux systemd*:: Messages will normally be kept in the service journal, so: - journalctl -lu nut-driver@instancename + journalctl -lu nut-driver@instance-name Note that your local system configuration may be impacted by such nuances as passing the journal data to a standard syslog server, @@ -185,7 +185,7 @@ and/or by having a small cache for locally stored journal messages copy of the journals stored in the filesystem. *Solaris SMF*:: -Look for `/var/svc/log/system-power-nut-driver:instancename.log` file. +Look for `/var/svc/log/system-power-nut-driver:instance-name.log` file. SEE ALSO -------- diff --git a/docs/nut.dict b/docs/nut.dict index 332bd95b77..4228b99ddb 100644 --- a/docs/nut.dict +++ b/docs/nut.dict @@ -1,4 +1,4 @@ -personal_ws-1.1 en 2419 utf-8 +personal_ws-1.1 en 2423 utf-8 AAS ACFAIL ACFREQ @@ -1653,6 +1653,7 @@ ivtscd jNUT jNut jNutWebAPI +journalctl jpg jpgraph json @@ -1730,6 +1731,7 @@ lowruntime lowvoltsout lr lsusb +lu lvo lxml lxyz @@ -2187,6 +2189,7 @@ sudo suid superset sv +svc svn sw symlink @@ -2201,6 +2204,7 @@ syscalls sysconfdir sysconfig syslog +systemctl systemd systemdsystemunitdir systemhours From 4155b4a6c348a5d8faae779235f2fa77b0e4e5d7 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 8 Mar 2018 15:47:58 +0100 Subject: [PATCH 112/165] Solaris packaging of nut-driver-enumerator.sh : deliver into libexecdir same as in Linux --- scripts/Solaris/Makefile.am | 3 ++- scripts/Solaris/nut-driver-enumerator.xml.in | 6 +++--- scripts/Solaris/postinstall.in | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/Solaris/Makefile.am b/scripts/Solaris/Makefile.am index 09d36f24a3..6211160a85 100644 --- a/scripts/Solaris/Makefile.am +++ b/scripts/Solaris/Makefile.am @@ -10,7 +10,6 @@ SOLARIS_SMF_MANIFESTS = \ nut-driver-enumerator.xml SOLARIS_SMF_METHODSCRIPTS = \ - ../systemd/nut-driver-enumerator.sh \ svc-nut-server \ svc-nut-monitor @@ -22,6 +21,8 @@ solarissmfmanifestdir = @datadir@/solaris-smf/manifest solarissmfmethod_SCRIPTS = $(SOLARIS_SMF_METHODSCRIPTS) solarissmfmanifest_DATA = $(SOLARIS_SMF_MANIFESTS) +libexec_SCRIPTS = ../systemd/nut-driver-enumerator.sh + sbin_SCRIPTS = ../systemd/upsdrvsvcctl SOLARIS_CHECK_TARGETS += check-local-solaris-smf diff --git a/scripts/Solaris/nut-driver-enumerator.xml.in b/scripts/Solaris/nut-driver-enumerator.xml.in index c9c39394f4..99673c0665 100644 --- a/scripts/Solaris/nut-driver-enumerator.xml.in +++ b/scripts/Solaris/nut-driver-enumerator.xml.in @@ -2,7 +2,7 @@ @@ -65,13 +65,13 @@ diff --git a/scripts/Solaris/postinstall.in b/scripts/Solaris/postinstall.in index f00a92aa64..a0f273ec0d 100755 --- a/scripts/Solaris/postinstall.in +++ b/scripts/Solaris/postinstall.in @@ -62,7 +62,7 @@ if test -x /usr/sbin/svcadm && test -x /usr/sbin/svccfg && test -x /usr/bin/svcs # Enable services if the system already has a configuration (e.g. upgrade) if test -s "@CONFPATH@/ups.conf" ; then echo "Enable NUT drivers (if any)..." - "@datadir@/solaris-smf/method/nut-driver-enumerator.sh" + "@libexecdir@/nut-driver-enumerator.sh" /usr/sbin/svcadm enable -s nut-driver-enumerator || \ { /usr/sbin/svcadm clear nut-driver-enumerator ; \ /usr/sbin/svcadm enable -s nut-driver-enumerator; } From e8e87316e100550aa2d524253589bc054359e251 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 8 Mar 2018 15:54:41 +0100 Subject: [PATCH 113/165] Move nut-driver-enumerator.sh.in and upsdrvsvcctl.in into scripts/upsdrvsvcctl to share on par between Linux and Solaris (for starters) --- configure.ac | 4 ++-- scripts/Solaris/Makefile.am | 4 ++-- scripts/systemd/Makefile.am | 4 ++-- scripts/systemd/README | 7 ++++--- .../{systemd => upsdrvsvcctl}/nut-driver-enumerator.sh.in | 0 scripts/{systemd => upsdrvsvcctl}/upsdrvsvcctl.in | 0 6 files changed, 10 insertions(+), 9 deletions(-) rename scripts/{systemd => upsdrvsvcctl}/nut-driver-enumerator.sh.in (100%) rename scripts/{systemd => upsdrvsvcctl}/upsdrvsvcctl.in (100%) diff --git a/configure.ac b/configure.ac index 5a9b509c53..36c9068aa0 100644 --- a/configure.ac +++ b/configure.ac @@ -1731,14 +1731,14 @@ AC_OUTPUT([ scripts/HP-UX/nut.psf scripts/HP-UX/postinstall scripts/python/Makefile + scripts/upsdrvsvcctl/nut-driver-enumerator.sh + scripts/upsdrvsvcctl/upsdrvsvcctl scripts/systemd/Makefile scripts/systemd/nut-driver@.service scripts/systemd/nut-monitor.service scripts/systemd/nut-server.service scripts/systemd/nut-driver-enumerator.service - scripts/systemd/nut-driver-enumerator.sh scripts/systemd/nutshutdown - scripts/systemd/upsdrvsvcctl scripts/Solaris/nut-driver-enumerator.xml scripts/Solaris/nut-driver.xml scripts/Solaris/nut-monitor.xml diff --git a/scripts/Solaris/Makefile.am b/scripts/Solaris/Makefile.am index 6211160a85..baa4ee3713 100644 --- a/scripts/Solaris/Makefile.am +++ b/scripts/Solaris/Makefile.am @@ -21,9 +21,9 @@ solarissmfmanifestdir = @datadir@/solaris-smf/manifest solarissmfmethod_SCRIPTS = $(SOLARIS_SMF_METHODSCRIPTS) solarissmfmanifest_DATA = $(SOLARIS_SMF_MANIFESTS) -libexec_SCRIPTS = ../systemd/nut-driver-enumerator.sh +libexec_SCRIPTS = ../upsdrvsvcctl/nut-driver-enumerator.sh -sbin_SCRIPTS = ../systemd/upsdrvsvcctl +sbin_SCRIPTS = ../upsdrvsvcctl/upsdrvsvcctl SOLARIS_CHECK_TARGETS += check-local-solaris-smf endif diff --git a/scripts/systemd/Makefile.am b/scripts/systemd/Makefile.am index 0f44daccf8..1e2d20fee0 100644 --- a/scripts/systemd/Makefile.am +++ b/scripts/systemd/Makefile.am @@ -14,9 +14,9 @@ EXTRA_DIST += nut-driver.target systemdshutdown_SCRIPTS = nutshutdown -libexec_SCRIPTS = nut-driver-enumerator.sh +libexec_SCRIPTS = ../upsdrvsvcctl/nut-driver-enumerator.sh -sbin_SCRIPTS = upsdrvsvcctl +sbin_SCRIPTS = ../upsdrvsvcctl/upsdrvsvcctl else EXTRA_DIST += nut-driver@.service.in nut-monitor.service.in \ diff --git a/scripts/systemd/README b/scripts/systemd/README index 925a80da2d..b0063581d7 100644 --- a/scripts/systemd/README +++ b/scripts/systemd/README @@ -4,9 +4,10 @@ Service Manager. These files are automatically installed, upon detection (at configure time) of a systemd enabled system. -This also includes the nut-driver-enumerator.sh (service and implementation -method) and upsdrvsvcctl (tool) to manage NUT drivers as service instances. +This also uses the nut-driver-enumerator.sh (service and implementation +method) and upsdrvsvcctl (tool) to manage NUT drivers as service instances +located in ../upsdrvsvcctl/ source subdirectory. Contributed by Michal Hlavinka -Updated 2016-2017 by Michal Hrusecky and Jim Klimov +Updated 2016-2018 by Michal Hrusecky and Jim Klimov diff --git a/scripts/systemd/nut-driver-enumerator.sh.in b/scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in similarity index 100% rename from scripts/systemd/nut-driver-enumerator.sh.in rename to scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in diff --git a/scripts/systemd/upsdrvsvcctl.in b/scripts/upsdrvsvcctl/upsdrvsvcctl.in similarity index 100% rename from scripts/systemd/upsdrvsvcctl.in rename to scripts/upsdrvsvcctl/upsdrvsvcctl.in From 3cffd2a4ad5fdc9629e510a11b647e2e9e49675b Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 8 Mar 2018 16:13:18 +0100 Subject: [PATCH 114/165] Use @NUT_LIBEXECDIR@ for nut-driver-enumerator.sh --- scripts/Solaris/nut-driver-enumerator.xml.in | 4 ++-- scripts/Solaris/postinstall.in | 2 +- scripts/upsdrvsvcctl/upsdrvsvcctl.in | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/Solaris/nut-driver-enumerator.xml.in b/scripts/Solaris/nut-driver-enumerator.xml.in index 99673c0665..d421941aa2 100644 --- a/scripts/Solaris/nut-driver-enumerator.xml.in +++ b/scripts/Solaris/nut-driver-enumerator.xml.in @@ -65,13 +65,13 @@ diff --git a/scripts/Solaris/postinstall.in b/scripts/Solaris/postinstall.in index a0f273ec0d..27f3bc039b 100755 --- a/scripts/Solaris/postinstall.in +++ b/scripts/Solaris/postinstall.in @@ -62,7 +62,7 @@ if test -x /usr/sbin/svcadm && test -x /usr/sbin/svccfg && test -x /usr/bin/svcs # Enable services if the system already has a configuration (e.g. upgrade) if test -s "@CONFPATH@/ups.conf" ; then echo "Enable NUT drivers (if any)..." - "@libexecdir@/nut-driver-enumerator.sh" + "@NUT_LIBEXECDIR@/nut-driver-enumerator.sh" /usr/sbin/svcadm enable -s nut-driver-enumerator || \ { /usr/sbin/svcadm clear nut-driver-enumerator ; \ /usr/sbin/svcadm enable -s nut-driver-enumerator; } diff --git a/scripts/upsdrvsvcctl/upsdrvsvcctl.in b/scripts/upsdrvsvcctl/upsdrvsvcctl.in index 2849df4ffa..64e5b140ba 100755 --- a/scripts/upsdrvsvcctl/upsdrvsvcctl.in +++ b/scripts/upsdrvsvcctl/upsdrvsvcctl.in @@ -35,7 +35,7 @@ CMDARG="" ENUMERATOR="" case "$SERVICE_FRAMEWORK" in smf) CMD="/usr/sbin/svcadm" - ENUMERATOR="@NUT_DATADIR@/solaris-smf/method/nut-driver-enumerator.sh" + ENUMERATOR="@NUT_LIBEXECDIR@/nut-driver-enumerator.sh" ;; systemd) CMD="/bin/systemctl" ENUMERATOR="@NUT_LIBEXECDIR@/nut-driver-enumerator.sh" From 463b2600ce2bc4ee183abee772a7b275e4c648b7 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 8 Mar 2018 16:13:43 +0100 Subject: [PATCH 115/165] Introduce nut-driver-enumerator.path.in for systemd --- configure.ac | 1 + scripts/systemd/Makefile.am | 3 ++- scripts/systemd/nut-driver-enumerator.path.in | 7 +++++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 scripts/systemd/nut-driver-enumerator.path.in diff --git a/configure.ac b/configure.ac index 36c9068aa0..52cb8ac7ae 100644 --- a/configure.ac +++ b/configure.ac @@ -1738,6 +1738,7 @@ AC_OUTPUT([ scripts/systemd/nut-monitor.service scripts/systemd/nut-server.service scripts/systemd/nut-driver-enumerator.service + scripts/systemd/nut-driver-enumerator.path scripts/systemd/nutshutdown scripts/Solaris/nut-driver-enumerator.xml scripts/Solaris/nut-driver.xml diff --git a/scripts/systemd/Makefile.am b/scripts/systemd/Makefile.am index 1e2d20fee0..21aac259e6 100644 --- a/scripts/systemd/Makefile.am +++ b/scripts/systemd/Makefile.am @@ -4,6 +4,7 @@ if HAVE_SYSTEMD systemdsystemunit_DATA = \ nut-driver-enumerator.service \ + nut-driver-enumerator.path \ nut-driver@.service \ nut-monitor.service \ nut-server.service \ @@ -22,6 +23,6 @@ else EXTRA_DIST += nut-driver@.service.in nut-monitor.service.in \ nut-server.service.in nutshutdown.in nut-driver.target nut.target \ nut-driver-enumerator.sh.in nut-driver-enumerator.service.in \ - upsdrvsvcctl.in + nut-driver-enumerator.path.in upsdrvsvcctl.in endif diff --git a/scripts/systemd/nut-driver-enumerator.path.in b/scripts/systemd/nut-driver-enumerator.path.in new file mode 100644 index 0000000000..13b0b5e055 --- /dev/null +++ b/scripts/systemd/nut-driver-enumerator.path.in @@ -0,0 +1,7 @@ +# Trigger restart of nut-driver-enumerator.service whenever ups.conf is edited + +[Path] +PathModified=@CONFDIR@/ups.conf + +[Install] +WantedBy=nut.target From 3c3958acee40da4754001084410bee5f4053bf88 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 8 Mar 2018 16:14:11 +0100 Subject: [PATCH 116/165] nut-driver-enumerator.service.in : be part of nut.target, not common multi-user --- scripts/systemd/nut-driver-enumerator.service.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/systemd/nut-driver-enumerator.service.in b/scripts/systemd/nut-driver-enumerator.service.in index c12c24b93b..e1d5f65a9d 100644 --- a/scripts/systemd/nut-driver-enumerator.service.in +++ b/scripts/systemd/nut-driver-enumerator.service.in @@ -19,4 +19,4 @@ ExecStart=@NUT_LIBEXECDIR@/nut-driver-enumerator.sh ExecReload=@NUT_LIBEXECDIR@/nut-driver-enumerator.sh [Install] -WantedBy=multi-user.target +WantedBy=nut.target From 11a6f02d4e5792af7cd3e2c487ef5fc48a6b88f1 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 8 Mar 2018 16:15:35 +0100 Subject: [PATCH 117/165] Systemd services : be PartOf=nut.target to propagate service stops --- scripts/systemd/nut-driver-enumerator.service.in | 1 + scripts/systemd/nut-driver.target | 1 + scripts/systemd/nut-monitor.service.in | 1 + scripts/systemd/nut-server.service.in | 1 + 4 files changed, 4 insertions(+) diff --git a/scripts/systemd/nut-driver-enumerator.service.in b/scripts/systemd/nut-driver-enumerator.service.in index e1d5f65a9d..bc600c37df 100644 --- a/scripts/systemd/nut-driver-enumerator.service.in +++ b/scripts/systemd/nut-driver-enumerator.service.in @@ -5,6 +5,7 @@ Description=Network UPS Tools - enumeration of configure-file devices into systemd unit instances After=local-fs.target Before=nut-driver.target +PartOf=nut.target [Service] ### Script needs privileges to restart units diff --git a/scripts/systemd/nut-driver.target b/scripts/systemd/nut-driver.target index 5a799de773..d994ab9882 100644 --- a/scripts/systemd/nut-driver.target +++ b/scripts/systemd/nut-driver.target @@ -2,6 +2,7 @@ Description=Network UPS Tools - target for power device drivers on this system After=local-fs.target # network.target +PartOf=nut.target [Install] WantedBy=nut.target diff --git a/scripts/systemd/nut-monitor.service.in b/scripts/systemd/nut-monitor.service.in index f12fa866da..d19bb28c81 100644 --- a/scripts/systemd/nut-monitor.service.in +++ b/scripts/systemd/nut-monitor.service.in @@ -13,6 +13,7 @@ Wants=nut-server.service # [Unit] # Requires=network-online.target # After=network-online.target +PartOf=nut.target [Service] ExecStart=@SBINDIR@/upsmon diff --git a/scripts/systemd/nut-server.service.in b/scripts/systemd/nut-server.service.in index 29636009cb..54122a59dc 100644 --- a/scripts/systemd/nut-server.service.in +++ b/scripts/systemd/nut-server.service.in @@ -15,6 +15,7 @@ Wants=nut-driver.target # After=network-online.target Requires=network.target Before=nut-monitor.service +PartOf=nut.target [Service] ExecStart=@SBINDIR@/upsd From 4501d8fe5cae37120559235d2c713fdd10bd5f6a Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 8 Mar 2018 16:22:48 +0100 Subject: [PATCH 118/165] postinstall.in : use NUT_DATADIR --- scripts/Solaris/postinstall.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Solaris/postinstall.in b/scripts/Solaris/postinstall.in index 27f3bc039b..191d6ae6b5 100755 --- a/scripts/Solaris/postinstall.in +++ b/scripts/Solaris/postinstall.in @@ -85,7 +85,7 @@ if test -x /usr/sbin/svcadm && test -x /usr/sbin/svccfg && test -x /usr/bin/svcs /usr/sbin/svcadm enable -s nut else echo "Put init script in /etc/init.d..." - cp -pf "@datadir@/solaris-init/nut" /etc/init.d + cp -pf "@NUT_DATADIR@/solaris-init/nut" /etc/init.d chown root:bin /etc/init.d/nut chmod 744 /etc/init.d/nut From 5f3a22ff44d6acfb8b664c5a3f67d6c19e71c913 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 8 Mar 2018 23:38:37 +0100 Subject: [PATCH 119/165] nut-monitor.xml.in : depend on nut-server (if locally running) --- scripts/Solaris/nut-monitor.xml.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Solaris/nut-monitor.xml.in b/scripts/Solaris/nut-monitor.xml.in index fceb8af700..c3118d3557 100644 --- a/scripts/Solaris/nut-monitor.xml.in +++ b/scripts/Solaris/nut-monitor.xml.in @@ -78,7 +78,7 @@ grouping='optional_all' restart_on='none' type='service'> - + + and not-trigger those which were not administratively enabled. + There is nothing to do by itself, so it is not-persistent. --> + + From 3062018c609ca5d0461e1fe63acc39625f386ce5 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 9 Mar 2018 16:07:46 +0100 Subject: [PATCH 126/165] upsdrvsvcctl.in : fix parameter passing --- scripts/upsdrvsvcctl/upsdrvsvcctl.in | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/upsdrvsvcctl/upsdrvsvcctl.in b/scripts/upsdrvsvcctl/upsdrvsvcctl.in index 64e5b140ba..311ce61b5b 100755 --- a/scripts/upsdrvsvcctl/upsdrvsvcctl.in +++ b/scripts/upsdrvsvcctl/upsdrvsvcctl.in @@ -97,17 +97,18 @@ while [ $# -gt 0 ]; do fi ;; start|stop) + ACTION="$1" if [ -n "$2" ] ; then SVCINST="`$ENUMERATOR --get-service-for-device "$2"`" || exit shift fi - ACTION="$1" ;; + ;; shutdown) echo "NOTE: Action '$1' is not implemented via services currently, will call upsdrvctl" >&2 echo "Stopping the driver service instance(s) to release exclusive resources, if any..." >&2 RES=0 $0 stop $2 - @SBINDIR@/upsdrvctl $2 || RES=$? + @SBINDIR@/upsdrvctl shutdown $2 || RES=$? echo "Starting the driver service instance(s) so they can reconnect when the UPS returns..." >&2 $0 start $2 exit $RES From 911b99854dabc0d8d2ac4fb76dbdfabade9245db Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 9 Mar 2018 16:31:20 +0100 Subject: [PATCH 127/165] upsdrvsvcctl.in : "clear" the SMF service state when stopping/starting, just in case it was failed --- scripts/upsdrvsvcctl/upsdrvsvcctl.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/upsdrvsvcctl/upsdrvsvcctl.in b/scripts/upsdrvsvcctl/upsdrvsvcctl.in index 311ce61b5b..21f686c821 100755 --- a/scripts/upsdrvsvcctl/upsdrvsvcctl.in +++ b/scripts/upsdrvsvcctl/upsdrvsvcctl.in @@ -159,6 +159,9 @@ esac for INST in $SVCINST ; do echo "$VERB $INST ..." >&2 $DRYRUN $CMD $CMDARG "$INST" & + case "$SERVICE_FRAMEWORK" in + smf) sleep 1 ; $DRYRUN $CMD clear "$INST" 2>/dev/null || true ;; + esac done wait From e5b6f261fd064adfab7eac17a8e823f29dc0501b Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 9 Mar 2018 16:50:11 +0100 Subject: [PATCH 128/165] nut-driver-enumerator.sh.in : restart upsd IFF the set of known-device mappings was changed --- .../upsdrvsvcctl/nut-driver-enumerator.sh.in | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in b/scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in index 2b960a7f8e..c470d94619 100755 --- a/scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in +++ b/scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in @@ -142,6 +142,7 @@ hook_listInstances_raw="" hook_validInstanceName="" hook_validFullUnitName="" hook_validInstanceSuffixName="" +hook_restart_upsd="" case "${SERVICE_FRAMEWORK-}" in smf) @@ -152,6 +153,7 @@ case "${SERVICE_FRAMEWORK-}" in hook_validInstanceName="smf_validInstanceName" hook_validFullUnitName="smf_validFullUnitName" hook_validInstanceSuffixName="smf_validInstanceSuffixName" + hook_restart_upsd="smf_restart_upsd" ;; systemd) hook_registerInstance="systemd_registerInstance" @@ -161,6 +163,7 @@ case "${SERVICE_FRAMEWORK-}" in hook_validInstanceName="systemd_validInstanceName" hook_validFullUnitName="systemd_validFullUnitName" hook_validInstanceSuffixName="systemd_validInstanceSuffixName" + hook_restart_upsd="systemd_restart_upsd" ;; "") echo "Error detecting the service-management framework on this OS" >&2 @@ -355,6 +358,7 @@ smf_registerInstance() { /usr/sbin/svcadm refresh "${TARGET_FMRI}" || return if [ "$AUTO_START" = yes ] ; then + /usr/sbin/svcadm clear "${TARGET_FMRI}" 2>/dev/null || true /usr/sbin/svcadm enable "${TARGET_FMRI}" || return echo "Started instance: 'nut-driver:$SVCINST' for NUT configuration section '$DEVICE'" >&2 fi @@ -371,6 +375,11 @@ smf_listInstances_raw() { smf_listInstances() { smf_listInstances_raw | sed 's/^.*://' | sort -n } +smf_restart_upsd() { + echo "Restarting NUT data server to make sure it knows new configuration..." + /usr/sbin/svcadm clear "nut-server" 2>/dev/null + /usr/sbin/svcadm restart "nut-server" +} systemd_validFullUnitName() { case "$1" in @@ -440,6 +449,10 @@ systemd_listInstances_raw() { systemd_listInstances() { systemd_listInstances_raw | sed -e 's/^.*@//' -e 's/\.service$//' | sort -n } +systemd_restart_upsd() { + echo "Restarting NUT data server to make sure it knows new configuration..." + /bin/systemctl restart "nut-server" +} upslist_readFile() { # Read the ups.conf file and find all defined sections (names of @@ -528,6 +541,11 @@ nut_driver_enumerator_main() { echo "$UPSLIST_FILE" fi + # We had some changes to the config file; upsd must be made aware + if [ "$AUTO_START" = yes ] ; then + $hook_restart_upsd + fi + # Return 42 if there was a change applied succesfully # (but e.g. some services should restart - upsd, maybe upsmon) if upslist_equals "$UPSLIST_FILE" "$UPSLIST_SVCS" ; then From 1daa5d191dca56b07ab7d6e393014d92d9d4fd8c Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 9 Mar 2018 16:50:35 +0100 Subject: [PATCH 129/165] Revise and relax some dependencies for Solaris SMF services --- scripts/Solaris/nut-driver-enumerator.xml.in | 9 ++++++--- scripts/Solaris/nut-driver.xml.in | 9 +++++---- scripts/Solaris/nut-server.xml.in | 4 ++-- scripts/Solaris/nut.xml.in | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/scripts/Solaris/nut-driver-enumerator.xml.in b/scripts/Solaris/nut-driver-enumerator.xml.in index d421941aa2..bc6d90dcb9 100644 --- a/scripts/Solaris/nut-driver-enumerator.xml.in +++ b/scripts/Solaris/nut-driver-enumerator.xml.in @@ -49,13 +49,16 @@ - + restart_on='error'> + @@ -73,8 +74,8 @@ - + restart_on='none'> + + restart_on='none'> diff --git a/scripts/Solaris/nut.xml.in b/scripts/Solaris/nut.xml.in index 8a8465cb7f..0d3e9b60ce 100644 --- a/scripts/Solaris/nut.xml.in +++ b/scripts/Solaris/nut.xml.in @@ -26,7 +26,7 @@ From 92f7f81218d4e948003a2c4a3417d0836789598c Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 9 Mar 2018 17:30:43 +0100 Subject: [PATCH 130/165] nut-driver-enumerator.sh.in : info messages go to stderr; reply for request only goes to stdout --- scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in b/scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in index c470d94619..752f936eac 100755 --- a/scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in +++ b/scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in @@ -593,7 +593,7 @@ while [ $# -gt 0 ]; do --list-devices) upslist_readFile && \ if [ -n "$UPSLIST_FILE" ] ; then - echo "=== The currently defined configurations in '$UPSCONF' are:" + echo "=== The currently defined configurations in '$UPSCONF' are:" >&2 echo "$UPSLIST_FILE" exit 0 fi @@ -603,7 +603,7 @@ while [ $# -gt 0 ]; do --list-services) UPSLIST_SVCS_RAW="`$hook_listInstances_raw`" && \ if [ -n "$UPSLIST_SVCS_RAW" ] ; then - echo "=== The currently defined service units are:" + echo "=== The currently defined service units are:" >&2 echo "$UPSLIST_SVCS_RAW" exit 0 fi @@ -613,7 +613,7 @@ while [ $# -gt 0 ]; do --list-instances) upslist_readSvcs "by user request" && \ if [ -n "$UPSLIST_SVCS" ] ; then - echo "=== The currently defined service instances are:" + echo "=== The currently defined service instances are:" >&2 echo "$UPSLIST_SVCS" exit 0 fi From 46cc110010ff9ea08eb6771528ef792eda4ecce0 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 9 Mar 2018 20:30:28 +0100 Subject: [PATCH 131/165] nut-driver-enumerator.sh.in : complete the upslist_equals() method --- scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in b/scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in index 752f936eac..c85f33061e 100755 --- a/scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in +++ b/scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (C) 2016-2017 Eaton +# Copyright (C) 2016-2018 Eaton # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -194,8 +194,13 @@ common_isRegistered() { } upslist_equals() { - # Compare list of DEVICES ($1) and SVCINSTs ($2) including mangling + # Compare pre-sorted list of DEVICES ($1) and SVCINSTs ($2) including + # the possible mangling for service names. Return 0 if lists describe + # exactly same set of devices and their services. + + # Trivial case 1: equal strings [ "$1" = "$2" ] && return 0 + # Trivial case 2: different amount of entries [ "`echo "$1" | wc -l`" = "`echo "$2" | wc -l`" ] || return $? _TMP_DEV_SVC="" @@ -209,6 +214,9 @@ upslist_equals() { $_DEV = $_SVC" ; } done done + + # Exit code : is the built mapping as long as the source list(s)? + [ "`echo "$1" | wc -l`" = "`echo "$_TMP_DEV_SVC" | wc -l`" ] } upsconf_getValue() { From 747c7e6217278146e7e2835700a46a09edba5564 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 9 Mar 2018 20:35:28 +0100 Subject: [PATCH 132/165] nut.xml.in : never fail on stop (if component services did not stop, it is their problem) --- scripts/Solaris/nut.xml.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Solaris/nut.xml.in b/scripts/Solaris/nut.xml.in index 0d3e9b60ce..6667b7ac7d 100644 --- a/scripts/Solaris/nut.xml.in +++ b/scripts/Solaris/nut.xml.in @@ -50,7 +50,7 @@ From bb281fa9599dfc4ed011c813d2b1d8fa4e6b119f Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 9 Mar 2018 20:40:05 +0100 Subject: [PATCH 133/165] Solaris preremove.in SMF : clear sevices before stopping them, just in case --- scripts/Solaris/preremove.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/Solaris/preremove.in b/scripts/Solaris/preremove.in index fd991f655a..7dae6c02d0 100755 --- a/scripts/Solaris/preremove.in +++ b/scripts/Solaris/preremove.in @@ -9,6 +9,7 @@ if test -x /usr/sbin/svcadm && test -x /usr/sbin/svccfg && test -x /usr/bin/svcs # Unconfigure SMF services for S in nut-monitor nut-driver-enumerator nut-server nut ; do echo "Stopping NUT service: $S..." + /usr/sbin/svcadm clear "$S" /usr/sbin/svcadm disable -s "$S" echo "Removing NUT service: $S..." /usr/sbin/svccfg delete "$S" || \ @@ -17,6 +18,7 @@ if test -x /usr/sbin/svcadm && test -x /usr/sbin/svccfg && test -x /usr/bin/svcs done for S in `/usr/bin/svcs -H -o fmri '*/nut-driver:*'` ; do echo "Stopping NUT service: $S..." + /usr/sbin/svcadm clear "$S" /usr/sbin/svcadm disable -s "$S" done for S in `/usr/bin/svcs -H -o fmri '*/nut-driver:*' | grep -wv default` ; do From c9f7e99c581dc7680e33dc38af21097311a5bff0 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 9 Mar 2018 20:53:04 +0100 Subject: [PATCH 134/165] upsdrvsvcctl.in : post-process clearing of SMF service instances if any have failed --- scripts/upsdrvsvcctl/upsdrvsvcctl.in | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/upsdrvsvcctl/upsdrvsvcctl.in b/scripts/upsdrvsvcctl/upsdrvsvcctl.in index 21f686c821..dfbda183ad 100755 --- a/scripts/upsdrvsvcctl/upsdrvsvcctl.in +++ b/scripts/upsdrvsvcctl/upsdrvsvcctl.in @@ -159,9 +159,18 @@ esac for INST in $SVCINST ; do echo "$VERB $INST ..." >&2 $DRYRUN $CMD $CMDARG "$INST" & - case "$SERVICE_FRAMEWORK" in - smf) sleep 1 ; $DRYRUN $CMD clear "$INST" 2>/dev/null || true ;; - esac done +wait + +case "$SERVICE_FRAMEWORK" in + smf) + sleep 1 + echo "Post-process clearing services that failed early..." >&2 + for INST in $SVCINST ; do + echo "Clearing $INST (if it got broken) ..." >&2 + $DRYRUN $CMD clear "$INST" & + done + ;; +esac wait From 3631c5301dc7fcbdbe6ba9199e09b5788ab9e5fa Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 9 Mar 2018 20:56:24 +0100 Subject: [PATCH 135/165] nut.xml.in : never fail on stop (if component services did not stop, it is their problem) --- scripts/Solaris/nut.xml.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Solaris/nut.xml.in b/scripts/Solaris/nut.xml.in index 6667b7ac7d..270fc66c92 100644 --- a/scripts/Solaris/nut.xml.in +++ b/scripts/Solaris/nut.xml.in @@ -50,7 +50,7 @@ From c22e4ead4f8f18fedfb554361e5d52275f2d15c4 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 9 Mar 2018 20:57:18 +0100 Subject: [PATCH 136/165] Solaris preremove.in SMF : remove nut before services it depends on --- scripts/Solaris/preremove.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Solaris/preremove.in b/scripts/Solaris/preremove.in index 7dae6c02d0..a02fe76ab9 100755 --- a/scripts/Solaris/preremove.in +++ b/scripts/Solaris/preremove.in @@ -7,7 +7,7 @@ prefix="@prefix@" # expanded as part of some autoconf macros below if test -x /usr/sbin/svcadm && test -x /usr/sbin/svccfg && test -x /usr/bin/svcs ; then # Unconfigure SMF services - for S in nut-monitor nut-driver-enumerator nut-server nut ; do + for S in nut nut-monitor nut-driver-enumerator nut-server ; do echo "Stopping NUT service: $S..." /usr/sbin/svcadm clear "$S" /usr/sbin/svcadm disable -s "$S" From 56f20dc593a6582c1f28f271c6b2409bc9a74a2f Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 9 Mar 2018 21:07:37 +0100 Subject: [PATCH 137/165] main.c upsdrvctl.c : make debug messages a bit more useful --- drivers/main.c | 2 +- drivers/upsdrvctl.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/main.c b/drivers/main.c index 6c181a70a9..2b19a65d15 100644 --- a/drivers/main.c +++ b/drivers/main.c @@ -636,7 +636,7 @@ int main(int argc, char **argv) break; } - upslogx(LOG_WARNING, "Duplicate driver instance detected! Terminating other driver!"); + upslogx(LOG_WARNING, "Duplicate driver instance detected (PID file %s exists)! Terminating other driver!", buffer); /* Allow driver some time to quit */ sleep(5); diff --git a/drivers/upsdrvctl.c b/drivers/upsdrvctl.c index 116fe69c73..7dd74bfaef 100644 --- a/drivers/upsdrvctl.c +++ b/drivers/upsdrvctl.c @@ -150,13 +150,14 @@ static void stop_driver(const ups_t *ups) ret = stat(pidfn, &fs); if ((ret != 0) && (ups->port != NULL)) { + upslog_with_errno(LOG_ERR, "Can't open %s", pidfn); snprintf(pidfn, sizeof(pidfn), "%s/%s-%s.pid", altpidpath(), ups->driver, xbasename(ups->port)); ret = stat(pidfn, &fs); } if (ret != 0) { - upslog_with_errno(LOG_ERR, "Can't open %s", pidfn); + upslog_with_errno(LOG_ERR, "Can't open %s either", pidfn); exec_error++; return; } From 04afc32c69a836675e3fd1702a05308051d7de59 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 9 Mar 2018 21:19:25 +0100 Subject: [PATCH 138/165] Solaris preremove.in SMF : do not block stopping NUT driver services, but follow up with upsdrv(svc)ctl stop of everything --- scripts/Solaris/preremove.in | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/Solaris/preremove.in b/scripts/Solaris/preremove.in index a02fe76ab9..ae76462e40 100755 --- a/scripts/Solaris/preremove.in +++ b/scripts/Solaris/preremove.in @@ -19,8 +19,10 @@ if test -x /usr/sbin/svcadm && test -x /usr/sbin/svccfg && test -x /usr/bin/svcs for S in `/usr/bin/svcs -H -o fmri '*/nut-driver:*'` ; do echo "Stopping NUT service: $S..." /usr/sbin/svcadm clear "$S" - /usr/sbin/svcadm disable -s "$S" + /usr/sbin/svcadm disable "$S" done + @sbindir@/upsdrvsvcctl stop + @sbindir@/upsdrvctl -DDDDD stop for S in `/usr/bin/svcs -H -o fmri '*/nut-driver:*' | grep -wv default` ; do echo "Removing NUT service: $S..." /usr/sbin/svccfg -s "nut-driver" delete "$S" || \ From f7be5f80180786a69535a8fb19a371c23f3e1b94 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 9 Mar 2018 21:34:28 +0100 Subject: [PATCH 139/165] Solaris preremove.in SMF : sleep after stopping drivers before removing their services --- scripts/Solaris/preremove.in | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/Solaris/preremove.in b/scripts/Solaris/preremove.in index ae76462e40..0af440ebab 100755 --- a/scripts/Solaris/preremove.in +++ b/scripts/Solaris/preremove.in @@ -23,6 +23,7 @@ if test -x /usr/sbin/svcadm && test -x /usr/sbin/svccfg && test -x /usr/bin/svcs done @sbindir@/upsdrvsvcctl stop @sbindir@/upsdrvctl -DDDDD stop + sleep 5 for S in `/usr/bin/svcs -H -o fmri '*/nut-driver:*' | grep -wv default` ; do echo "Removing NUT service: $S..." /usr/sbin/svccfg -s "nut-driver" delete "$S" || \ From 6e13b88804587da94ed93681a81e642299181826 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 9 Mar 2018 21:34:54 +0100 Subject: [PATCH 140/165] Solaris preremove.in SMF : force-remove services of drivers --- scripts/Solaris/preremove.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Solaris/preremove.in b/scripts/Solaris/preremove.in index 0af440ebab..7171b1183f 100755 --- a/scripts/Solaris/preremove.in +++ b/scripts/Solaris/preremove.in @@ -26,7 +26,7 @@ if test -x /usr/sbin/svcadm && test -x /usr/sbin/svccfg && test -x /usr/bin/svcs sleep 5 for S in `/usr/bin/svcs -H -o fmri '*/nut-driver:*' | grep -wv default` ; do echo "Removing NUT service: $S..." - /usr/sbin/svccfg -s "nut-driver" delete "$S" || \ + /usr/sbin/svccfg -s "nut-driver" delete -f "$S" || \ /usr/sbin/svccfg delete "$S" done S="nut-driver" && \ From d7ed3b83e1c2af52524ffe7f8e500ebe084765f8 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 9 Mar 2018 21:42:21 +0100 Subject: [PATCH 141/165] nut-driver.xml.in : rename a dependency to avoid conflicts --- scripts/Solaris/nut-driver.xml.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Solaris/nut-driver.xml.in b/scripts/Solaris/nut-driver.xml.in index 6550ea9287..676fd24641 100644 --- a/scripts/Solaris/nut-driver.xml.in +++ b/scripts/Solaris/nut-driver.xml.in @@ -72,7 +72,7 @@ the upsd from publishing others. --> From d928f99f758b3e8a2ea44ccaf87daa60b4b0aaa3 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 9 Mar 2018 21:56:06 +0100 Subject: [PATCH 142/165] Solaris nut.xml.in : add a refresh action handler --- scripts/Solaris/nut.xml.in | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/Solaris/nut.xml.in b/scripts/Solaris/nut.xml.in index 270fc66c92..b06b2b151c 100644 --- a/scripts/Solaris/nut.xml.in +++ b/scripts/Solaris/nut.xml.in @@ -53,6 +53,14 @@ exec='/usr/sbin/svcadm disable -ts svc:/system/power/nut-monitor:default || /bin/true ; /usr/sbin/svcadm disable -ts svc:/system/power/nut-server:default || /bin/true ; @SBINDIR@/upsdrvsvcctl stop || /bin/true ; /bin/true' timeout_seconds='120' /> + + +