From daa974cff0bef94c71277e703c32b3fd36f1411b Mon Sep 17 00:00:00 2001 From: "Daniel F. Dickinson" Date: Tue, 9 Oct 2018 21:43:33 -0400 Subject: [PATCH 1/8] nut: Fix undetected UPS hardware Leading zeroes left in ProductId results in some UPS hardware not being matched by the hotplug script lead to bad permissions and driver not starting. Closes: #6966 Signed-off-by: Daniel F. Dickinson --- net/nut/Makefile | 2 +- net/nut/files/30-libhid-ups.head | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/net/nut/Makefile b/net/nut/Makefile index 6108e2705..199014b2f 100644 --- a/net/nut/Makefile +++ b/net/nut/Makefile @@ -85,7 +85,7 @@ define Package/nut-server/install $(CP) $(PKG_INSTALL_DIR)/etc/hotplug/usb/libhid.usermap $(PKG_BUILD_DIR)/30-libhid-ups.middle $(SED) '/^$$$$/d' \ -e '/^#/d' \ - -E -e 's:^[^ ][^ ]* *0x0003 *0x0{0,3}([^ ][^ ]*) *0x{0,3}*([^ ][^ ]*).*:\1/\2/* | \\:' \ + -E -e 's:^[^ ][^ ]* *0x0003 *0x0{0,3}([^ ][^ ]*) *0x0{0,3}*([^ ][^ ]*).*:\1/\2/* | \\:' \ $(PKG_BUILD_DIR)/30-libhid-ups.middle tail -n+2 $(PKG_BUILD_DIR)/30-libhid-ups.middle >>$(1)/etc/hotplug.d/usb/30-libhid-ups cat ./files/30-libhid-ups.tail >>$(1)/etc/hotplug.d/usb/30-libhid-ups diff --git a/net/nut/files/30-libhid-ups.head b/net/nut/files/30-libhid-ups.head index efcbcf66b..a65094646 100755 --- a/net/nut/files/30-libhid-ups.head +++ b/net/nut/files/30-libhid-ups.head @@ -15,22 +15,23 @@ nut_driver_config() { chown ${runas:-root}:$(id -gn "${runas:-root}") /dev/"$DEVNAME" } - if [ "$(printf "%04x" 0x"$pvendid")" = "$vendorid" ] && \ + if [ "$nomatch" = "1" ]; then + [ "$ACTION" = "add" ] && { + /etc/init.d/nut-server start "$cfg" + } + [ "$ACTION" = "remove" ] && { + /etc/init.d/nut-server stop "$cfg" + } + elif [ "$(printf "%04x" 0x"$pvendid")" = "$vendorid" ] && \ [ "$(printf "%04x" 0x"$pprodid")" = "$productid" ]; then [ "$ACTION" = "add" ] && { /etc/init.d/nut-server start "$cfg" + /etc/init.d/nut-server reload upsd } [ "$ACTION" = "remove" ] && { /etc/init.d/nut-server stop "$cfg" } found=1 - elif [ "$nomatch" = "1" ]; then - [ "$ACTION" = "add" ] && { - /etc/init.d/nut-server start "$cfg" - } - [ "$ACTION" = "remove" ] && { - /etc/init.d/nut-server stop "$cfg" - } fi } From 0a49d0ffbbe1081005a8307b0643b0048a217229 Mon Sep 17 00:00:00 2001 From: "Daniel F. Dickinson" Date: Tue, 9 Oct 2018 21:47:46 -0400 Subject: [PATCH 2/8] nut: Fix checking for path before it exists The mechanism for making sure hotplug doesn't execute during forced shutdown was interfering with initial start of hotplug script due to checking for path that doesn't exist at initial start. This fixes that and closes #6966. Signed-off-by: Daniel F. Dickinson --- net/nut/files/30-libhid-ups.tail | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/nut/files/30-libhid-ups.tail b/net/nut/files/30-libhid-ups.tail index 24c2a9670..343fd0963 100644 --- a/net/nut/files/30-libhid-ups.tail +++ b/net/nut/files/30-libhid-ups.tail @@ -1,5 +1,5 @@ "") - [ -d /var/run/nut ] && [ ! -f /var/run/nut/disable-hotplug ] && \ - /etc/init.d/nut-server enabled && perform_libhid_action + [ ! -f /var/run/nut/disable-hotplug ] && \ + /etc/init.d/nut-server enabled && perform_libhid_action ;; esac From 8ff6a83a541b114437eab170a0760c1c04263aa2 Mon Sep 17 00:00:00 2001 From: "Daniel F. Dickinson" Date: Tue, 9 Oct 2018 22:01:05 -0400 Subject: [PATCH 3/8] nut: Build serial drivers by default Serial drivers don't add much to main NUT and appear to be common, so make it possible for users to use NUT with serial UPS drivers without a custom build. Signed-off-by: Daniel F. Dickinson --- net/nut/Config.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/nut/Config.in b/net/nut/Config.in index b7f403b78..cd2f43ec7 100644 --- a/net/nut/Config.in +++ b/net/nut/Config.in @@ -29,4 +29,4 @@ bool "Build with suport for serial drivers" help If you have a UPS connected via serial cable, select this. - default n + default y From 3b5a8eee84d222f116bcc84c2399c8ea892f4e6c Mon Sep 17 00:00:00 2001 From: "Daniel F. Dickinson" Date: Tue, 9 Oct 2018 22:07:11 -0400 Subject: [PATCH 4/8] nut: Various startup fixes for monitor and server Various path and permissions fixes to properly allow nut-server and nut-monitor to start properly. Signed-off-by: Daniel F. Dickinson --- net/nut/files/nut-monitor.init | 27 ++++++++++++++++-------- net/nut/files/nut-server.init | 38 +++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/net/nut/files/nut-monitor.init b/net/nut/files/nut-monitor.init index 513d70305..21e7002ea 100755 --- a/net/nut/files/nut-monitor.init +++ b/net/nut/files/nut-monitor.init @@ -1,6 +1,6 @@ #!/bin/sh /etc/rc.common -START=60 +START=51 USE_PROCD=1 UPSMON_C=/var/etc/nut/upsmon.conf @@ -114,6 +114,8 @@ nut_upsmon_conf() { config_get_bool val "$cfg" forcessl 0 if [ -n "$val" ]; then echo "FORCESSL $val" >> "$UPSMON_C"; fi + + havemon=1 } nut_upsmon_add() { @@ -138,6 +140,8 @@ nut_upsmon_add() { system="$system:$port"; fi echo "MONITOR $system $powervalue $username $password $type" >> "$UPSMON_C" + + havems=1 } build_config() { @@ -149,19 +153,24 @@ build_config() { config_foreach nut_upsmon_add master master config_foreach nut_upsmon_add slave slave - [ -z "$(cat /var/etc/nut/nut.conf)" ] && { + [ ! -s "$(cat /var/etc/nut/nut.conf)" ] && { echo "MODE=netclient" >>/var/etc/nut/nut.conf chmod 640 /var/etc/nut/nut.conf chgrp $(id -gn ${runas:-root}) /var/etc/nut/nut.conf } - chmod 640 "$UPSMON_C" - chgrp $(id -gn ${runas:-root}) "$UPSMON_C" + [ -s "$UPSMON_C" ] && chmod 640 "$UPSMON_C" + [ -s "$UPSMON_C" ] && chgrp $(id -gn ${runas:-root}) "$UPSMON_C" } start_service() { + local havemon havems build_config - procd_open_instance + + [ "$havemon" != 1 ] && return + [ "$havems" != 1 ] && return + + procd_open_instance "upsmon" procd_set_param respawn procd_set_param stderr 0 procd_set_param stdout 1 @@ -172,14 +181,14 @@ start_service() { reload_service() { if pgrep upsmon >/dev/null 2>/dev/null; then build_config - upsmon -c reload + /usr/sbin/upsmon -c reload else stop - sleep 1 - start + sleep 2 + start_service fi } service_triggers() { - procd_add_reload_trigger nut_monitor + procd_add_reload_trigger "nut_monitor" } diff --git a/net/nut/files/nut-server.init b/net/nut/files/nut-server.init index 73bf30ea1..54958e230 100755 --- a/net/nut/files/nut-server.init +++ b/net/nut/files/nut-server.init @@ -117,7 +117,7 @@ build_server_config() { chmod 0640 "$USERS_C" chmod 0640 "$UPSD_C" - chmod 0640 /var/etc/nut/nut.conf + chmod 0644 /var/etc/nut/nut.conf [ -d "${STATEPATH}" ] || { mkdir -m 0750 -p "${STATEPATH}" @@ -128,17 +128,14 @@ build_server_config() { chgrp $(id -gn $RUNAS) "$USERS_C" chgrp $(id -gn $RUNAS) "$UPSD_C" fi + haveserver=1 } build_driver_config() { local cfg="$1" - local runas echo "[$cfg]" >>"$UPS_C" - config_get runas "$cfg" runas "nut" - RUNAS="$runas" - get_write_driver_config "$cfg" driver "usbhid-ups" get_write_driver_config "$cfg" port "auto" get_write_driver_config "$cfg" mfr @@ -166,12 +163,18 @@ build_driver_config() { } build_config() { + local RUNAS=nut + local STATEPATH=/var/run/nut + mkdir -m 0755 -p "$(dirname "$UPS_C")" rm -f "$UPS_C" echo "# Config file automatically generated from UCI config" > "$UPS_C" chmod 0640 "$UPS_C" config_load nut_server + config_foreach upsd_statepath upsd + + config_foreach build_global_driver_config driver_global config_foreach build_driver_config driver [ -n "$RUNAS" ] && chgrp $(id -gn $RUNAS) "$UPS_C" @@ -181,26 +184,29 @@ build_config() { start_driver_instance() { local cfg="$1" local requested="$2" - local RUNAS=nut local driver + local STATEPATH=/var/run/nut + local RUNAS=nut + + [ "$havedriver" != 1 ] && return # If wanting a specific instance, only start it - [ "$requested" != "$cfg" ] && [ x"$requested" != x"" ] && return 0 + [ "$requested" != "$cfg" ] && [ x"$requested" != x ] && return 0 mkdir -m 0755 -p "$(dirname "$UPS_C")" [ ! -s "$UPS_C" ] && build_config - # Avoid hotplug inadvertenly restarting driver during # forced shutdown [ -f /var/run/killpower ] && return 0 [ -d /var/run/nut ] && [ -f /var/run/nut/disable-hotplug ] && return 0 + config_foreach upsd_statepath upsd + if [ -n "$RUNAS" ]; then chown $RUNAS:$(id -gn $RUNAS) "${STATEPATH}" - chown $RUNAS:$(id -gn $RUNAS) "$(dirname "$UPS_C")" fi config_get driver "$cfg" driver "usbhid-ups" @@ -213,9 +219,11 @@ start_driver_instance() { } start_server_instance() { - local RUNAS STATEPATH + local RUNAS build_config + [ "$haveserver" != 1 ] && return + procd_open_instance "upsd" procd_set_param respawn procd_set_param stderr 0 @@ -225,30 +233,26 @@ start_server_instance() { } start_service() { + local havedriver haveserver local STATEPATH=/var/run/nut # Avoid hotplug inadvertenly restarting driver during # forced shutdown [ -f /var/run/killpower ] && return 0 - [ -d /var/run/nut ] && [ -f /var/run/nut/disable-hotplug ] && return 0 + [ -f /var/run/nut/disable-hotplug ] && return 0 config_load nut_server - config_foreach upsd_statepath upsd - - [ -d "${STATEPATH}" ] || { - mkdir -m 0750 -p "${STATEPATH}" - } build_config config_foreach start_driver_instance driver "$@" - [ "$1" != "upsd" ] && [ x"$1" != x"" ] && return 0 start_server_instance "upsd" } reload_service() { stop sleep 2 + local havedriver haveserver start } From 44e57d4bdfe93214e9c031f181533bb0e4ef25ca Mon Sep 17 00:00:00 2001 From: "Daniel F. Dickinson" Date: Tue, 9 Oct 2018 22:10:52 -0400 Subject: [PATCH 5/8] nut: Fix variables for NUT drivers Avoid specifying variables that are not specificy set in order to avoid breaking drivers for which those variables do not exist. Closes: #7096. As part of these fixes make sure we have all the variables we need. Closes: #7001. Signed-off-by: Daniel F. Dickinson --- net/nut/files/nut-server.init | 68 +++++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 6 deletions(-) diff --git a/net/nut/files/nut-server.init b/net/nut/files/nut-server.init index 54958e230..4f1219a1b 100755 --- a/net/nut/files/nut-server.init +++ b/net/nut/files/nut-server.init @@ -138,27 +138,83 @@ build_driver_config() { get_write_driver_config "$cfg" driver "usbhid-ups" get_write_driver_config "$cfg" port "auto" + get_write_driver_config "$cfg" sdorder + get_write_driver_config "$cfg" desc + get_write_driver_config "$cfg" nolock 0 1 + get_write_driver_config "$cfg" ignorelb 0 1 get_write_driver_config "$cfg" mfr get_write_driver_config "$cfg" model get_write_driver_config "$cfg" serial get_write_driver_config "$cfg" sdtime - get_write_driver_config "$cfg" offdelay 20 - get_write_driver_config "$cfg" ondelay 30 - get_write_driver_config "$cfg" pollfreq 30 + get_write_driver_config "$cfg" offdelay + get_write_driver_config "$cfg" ondelay + get_write_driver_config "$cfg" pollfreq get_write_driver_config "$cfg" vendor get_write_driver_config "$cfg" product get_write_driver_config "$cfg" bus get_write_driver_config "$cfg" interruptonly 0 1 - get_write_driver_config "$cfg" interruptsize 0 + get_write_driver_config "$cfg" interruptsize get_write_driver_config "$cfg" maxreport get_write_driver_config "$cfg" vendorid get_write_driver_config "$cfg" productid get_write_driver_config "$cfg" community get_write_driver_config "$cfg" snmp_version - get_write_driver_config "$cfg" snmp_retries 0 - get_write_driver_config "$cfg" snmp_timeout 0 + get_write_driver_config "$cfg" snmp_retries + get_write_driver_config "$cfg" snmp_timeout get_write_driver_config "$cfg" notransferoids 0 1 + get_write_driver_config "$cfg" maxstartdelay + get_write_driver_config "$cfg" retrydelay + get_write_driver_config "$cfg" synchronous get_write_driver_config "$cfg" other + get_write_driver_config "$cfg" otherflag + + defoverride() { + local overvar="$1" + local defover="$2" + local overtype="$(echo "$overvar" | tr '.' '_')" + + config_get overval "${defover}_${overtype}" value + [ -n "$overval" ] && echo "${defover}.${overvar} = $overval" >>"$UPS_C" + } + + config_list_foreach "$cfg" override defoverride override + config_list_foreach "$cfg" default defoverride default + + other() { + local othervar="$1" + local othervarflag="$2" + + if [ "$othervarflag" = "otherflag" ]; then + config_get_bool otherval "${othervarflag}_${overtype}" value + [ "$otherval" = "1" ] && echo "${othervarflag}_${othervar}" >>"$UPS_C" + else + config_get otherval "${othervarflag}_${overtype}" value + [ -n "$otherval" ] && echo "${othervarflag}_${othervar} = $otherval" >>"$UPS_C" + fi + } + + config_list_foreach "$cfg" override defoverride override + config_list_foreach "$cfg" default defoverride default + config_list_foreach "$cfg" default other other + config_list_foreach "$cfg" default other otherflag + echo "" >>$UPS_C + havedriver=1 +} + +build_global_driver_config() { + local cfg="$1" + + # Global driver config + get_write_driver_config "$cfg" chroot + get_write_driver_config "$cfg" driverpath + get_write_driver_config "$cfg" maxstartdelay + get_write_driver_config "$cfg" maxretry + get_write_driver_config "$cfg" retrydelay + get_write_driver_config "$cfg" pollinterval + get_write_dirver_config "$cfg" synchronous + config_get runas "$cfg" user "nut" + RUNAS="$runas" + echo "" >>$UPS_C } From 58e33b02a83c78c42742bc857815899d32d296af Mon Sep 17 00:00:00 2001 From: "Daniel F. Dickinson" Date: Tue, 9 Oct 2018 22:11:54 -0400 Subject: [PATCH 6/8] nut: Fix nut-cgi config creation (startup) Signed-off-by: Daniel F. Dickinson --- net/nut/files/nut-cgi.init | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/nut/files/nut-cgi.init b/net/nut/files/nut-cgi.init index ceb7cce22..9d408bb6a 100755 --- a/net/nut/files/nut-cgi.init +++ b/net/nut/files/nut-cgi.init @@ -4,7 +4,7 @@ # This is free software, licensed under the GNU General Public License v2. # See /LICENSE for more information. # -START=51 +START=60 USE_PROCD=1 DEFAULT=/etc/default/nut @@ -53,13 +53,17 @@ service_reload() { config_foreach nut_upscgi_add host config_foreach nut_upscgi_upsset upsset - chmod 640 /var/etc/nut/hosts.conf + [ -s "$UPSCGI_C" ] && chmod 640 "$UPSCGI_C" } start_service() { service_reload } +reload_service() { + service_reload +} + stop_service() { rm -f "$UPSCGI_C" rm -f "$UPSCGI_S" From 36fd59dc78fa14f10d06d9d14eee4598633d5dfa Mon Sep 17 00:00:00 2001 From: "Daniel F. Dickinson" Date: Tue, 9 Oct 2018 22:12:55 -0400 Subject: [PATCH 7/8] nut: Fix extraneous config_get nut-server initscript had a duplicate config_get statepath, so remove it Signed-off-by: Daniel F. Dickinson --- net/nut/files/nut-server.init | 1 - 1 file changed, 1 deletion(-) diff --git a/net/nut/files/nut-server.init b/net/nut/files/nut-server.init index 4f1219a1b..437108e49 100755 --- a/net/nut/files/nut-server.init +++ b/net/nut/files/nut-server.init @@ -61,7 +61,6 @@ upsd_config() { config_get maxage "$cfg" maxage [ -n "$maxage" ] && echo "MAXAGE $maxage" >>"$UPSD_C" - config_get statepath "$cfg" statepath [ -n "$statepath" ] && echo "STATEPATH $statepath" >>"$UPSD_C" config_get maxconn "$cfg" maxconn From 3aa67b3ca3199d7596a4f55134e7389ba7e49184 Mon Sep 17 00:00:00 2001 From: "Daniel F. Dickinson" Date: Tue, 9 Oct 2018 22:13:36 -0400 Subject: [PATCH 8/8] nut: Bump PKG_RELEASE Signed-off-by: Daniel F. Dickinson --- net/nut/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/nut/Makefile b/net/nut/Makefile index 199014b2f..d35f713ad 100644 --- a/net/nut/Makefile +++ b/net/nut/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=nut PKG_VERSION:=2.7.4 -PKG_RELEASE:=8 +PKG_RELEASE:=9 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=http://www.networkupstools.org/source/2.7/