Browse Source

Merge pull request #7167 from cshoredaniel/pr-nut-more-fixes

nut: Various fixes
lilik-openwrt-22.03
Hannu Nyman 6 years ago
committed by GitHub
parent
commit
ee8f345477
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 121 additions and 48 deletions
  1. +1
    -1
      net/nut/Config.in
  2. +2
    -2
      net/nut/Makefile
  3. +9
    -8
      net/nut/files/30-libhid-ups.head
  4. +2
    -2
      net/nut/files/30-libhid-ups.tail
  5. +6
    -2
      net/nut/files/nut-cgi.init
  6. +18
    -9
      net/nut/files/nut-monitor.init
  7. +83
    -24
      net/nut/files/nut-server.init

+ 1
- 1
net/nut/Config.in View File

@ -29,4 +29,4 @@
bool "Build with suport for serial drivers" bool "Build with suport for serial drivers"
help help
If you have a UPS connected via serial cable, select this. If you have a UPS connected via serial cable, select this.
default n
default y

+ 2
- 2
net/nut/Makefile View File

@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=nut PKG_NAME:=nut
PKG_VERSION:=2.7.4 PKG_VERSION:=2.7.4
PKG_RELEASE:=8
PKG_RELEASE:=9
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://www.networkupstools.org/source/2.7/ PKG_SOURCE_URL:=http://www.networkupstools.org/source/2.7/
@ -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 $(CP) $(PKG_INSTALL_DIR)/etc/hotplug/usb/libhid.usermap $(PKG_BUILD_DIR)/30-libhid-ups.middle
$(SED) '/^$$$$/d' \ $(SED) '/^$$$$/d' \
-e '/^#/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 $(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 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 cat ./files/30-libhid-ups.tail >>$(1)/etc/hotplug.d/usb/30-libhid-ups


+ 9
- 8
net/nut/files/30-libhid-ups.head View File

@ -15,22 +15,23 @@ nut_driver_config() {
chown ${runas:-root}:$(id -gn "${runas:-root}") /dev/"$DEVNAME" 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 [ "$(printf "%04x" 0x"$pprodid")" = "$productid" ]; then
[ "$ACTION" = "add" ] && { [ "$ACTION" = "add" ] && {
/etc/init.d/nut-server start "$cfg" /etc/init.d/nut-server start "$cfg"
/etc/init.d/nut-server reload upsd
} }
[ "$ACTION" = "remove" ] && { [ "$ACTION" = "remove" ] && {
/etc/init.d/nut-server stop "$cfg" /etc/init.d/nut-server stop "$cfg"
} }
found=1 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 fi
} }


+ 2
- 2
net/nut/files/30-libhid-ups.tail View File

@ -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 esac

+ 6
- 2
net/nut/files/nut-cgi.init View File

@ -4,7 +4,7 @@
# This is free software, licensed under the GNU General Public License v2. # This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information. # See /LICENSE for more information.
# #
START=51
START=60
USE_PROCD=1 USE_PROCD=1
DEFAULT=/etc/default/nut DEFAULT=/etc/default/nut
@ -53,13 +53,17 @@ service_reload() {
config_foreach nut_upscgi_add host config_foreach nut_upscgi_add host
config_foreach nut_upscgi_upsset upsset config_foreach nut_upscgi_upsset upsset
chmod 640 /var/etc/nut/hosts.conf
[ -s "$UPSCGI_C" ] && chmod 640 "$UPSCGI_C"
} }
start_service() { start_service() {
service_reload service_reload
} }
reload_service() {
service_reload
}
stop_service() { stop_service() {
rm -f "$UPSCGI_C" rm -f "$UPSCGI_C"
rm -f "$UPSCGI_S" rm -f "$UPSCGI_S"


+ 18
- 9
net/nut/files/nut-monitor.init View File

@ -1,6 +1,6 @@
#!/bin/sh /etc/rc.common #!/bin/sh /etc/rc.common
START=60
START=51
USE_PROCD=1 USE_PROCD=1
UPSMON_C=/var/etc/nut/upsmon.conf UPSMON_C=/var/etc/nut/upsmon.conf
@ -114,6 +114,8 @@ nut_upsmon_conf() {
config_get_bool val "$cfg" forcessl 0 config_get_bool val "$cfg" forcessl 0
if [ -n "$val" ]; then echo "FORCESSL $val" >> "$UPSMON_C"; fi if [ -n "$val" ]; then echo "FORCESSL $val" >> "$UPSMON_C"; fi
havemon=1
} }
nut_upsmon_add() { nut_upsmon_add() {
@ -138,6 +140,8 @@ nut_upsmon_add() {
system="$system:$port"; system="$system:$port";
fi fi
echo "MONITOR $system $powervalue $username $password $type" >> "$UPSMON_C" echo "MONITOR $system $powervalue $username $password $type" >> "$UPSMON_C"
havems=1
} }
build_config() { build_config() {
@ -149,19 +153,24 @@ build_config() {
config_foreach nut_upsmon_add master master config_foreach nut_upsmon_add master master
config_foreach nut_upsmon_add slave slave 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 echo "MODE=netclient" >>/var/etc/nut/nut.conf
chmod 640 /var/etc/nut/nut.conf chmod 640 /var/etc/nut/nut.conf
chgrp $(id -gn ${runas:-root}) /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() { start_service() {
local havemon havems
build_config build_config
procd_open_instance
[ "$havemon" != 1 ] && return
[ "$havems" != 1 ] && return
procd_open_instance "upsmon"
procd_set_param respawn procd_set_param respawn
procd_set_param stderr 0 procd_set_param stderr 0
procd_set_param stdout 1 procd_set_param stdout 1
@ -172,14 +181,14 @@ start_service() {
reload_service() { reload_service() {
if pgrep upsmon >/dev/null 2>/dev/null; then if pgrep upsmon >/dev/null 2>/dev/null; then
build_config build_config
upsmon -c reload
/usr/sbin/upsmon -c reload
else else
stop stop
sleep 1
start
sleep 2
start_service
fi fi
} }
service_triggers() { service_triggers() {
procd_add_reload_trigger nut_monitor
procd_add_reload_trigger "nut_monitor"
} }

+ 83
- 24
net/nut/files/nut-server.init View File

@ -61,7 +61,6 @@ upsd_config() {
config_get maxage "$cfg" maxage config_get maxage "$cfg" maxage
[ -n "$maxage" ] && echo "MAXAGE $maxage" >>"$UPSD_C" [ -n "$maxage" ] && echo "MAXAGE $maxage" >>"$UPSD_C"
config_get statepath "$cfg" statepath
[ -n "$statepath" ] && echo "STATEPATH $statepath" >>"$UPSD_C" [ -n "$statepath" ] && echo "STATEPATH $statepath" >>"$UPSD_C"
config_get maxconn "$cfg" maxconn config_get maxconn "$cfg" maxconn
@ -117,7 +116,7 @@ build_server_config() {
chmod 0640 "$USERS_C" chmod 0640 "$USERS_C"
chmod 0640 "$UPSD_C" chmod 0640 "$UPSD_C"
chmod 0640 /var/etc/nut/nut.conf
chmod 0644 /var/etc/nut/nut.conf
[ -d "${STATEPATH}" ] || { [ -d "${STATEPATH}" ] || {
mkdir -m 0750 -p "${STATEPATH}" mkdir -m 0750 -p "${STATEPATH}"
@ -128,50 +127,109 @@ build_server_config() {
chgrp $(id -gn $RUNAS) "$USERS_C" chgrp $(id -gn $RUNAS) "$USERS_C"
chgrp $(id -gn $RUNAS) "$UPSD_C" chgrp $(id -gn $RUNAS) "$UPSD_C"
fi fi
haveserver=1
} }
build_driver_config() { build_driver_config() {
local cfg="$1" local cfg="$1"
local runas
echo "[$cfg]" >>"$UPS_C" 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" driver "usbhid-ups"
get_write_driver_config "$cfg" port "auto" 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" mfr
get_write_driver_config "$cfg" model get_write_driver_config "$cfg" model
get_write_driver_config "$cfg" serial get_write_driver_config "$cfg" serial
get_write_driver_config "$cfg" sdtime 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" vendor
get_write_driver_config "$cfg" product get_write_driver_config "$cfg" product
get_write_driver_config "$cfg" bus get_write_driver_config "$cfg" bus
get_write_driver_config "$cfg" interruptonly 0 1 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" maxreport
get_write_driver_config "$cfg" vendorid get_write_driver_config "$cfg" vendorid
get_write_driver_config "$cfg" productid get_write_driver_config "$cfg" productid
get_write_driver_config "$cfg" community get_write_driver_config "$cfg" community
get_write_driver_config "$cfg" snmp_version 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" 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" 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 echo "" >>$UPS_C
} }
build_config() { build_config() {
local RUNAS=nut
local STATEPATH=/var/run/nut
mkdir -m 0755 -p "$(dirname "$UPS_C")" mkdir -m 0755 -p "$(dirname "$UPS_C")"
rm -f "$UPS_C" rm -f "$UPS_C"
echo "# Config file automatically generated from UCI config" > "$UPS_C" echo "# Config file automatically generated from UCI config" > "$UPS_C"
chmod 0640 "$UPS_C" chmod 0640 "$UPS_C"
config_load nut_server config_load nut_server
config_foreach upsd_statepath upsd
config_foreach build_global_driver_config driver_global
config_foreach build_driver_config driver config_foreach build_driver_config driver
[ -n "$RUNAS" ] && chgrp $(id -gn $RUNAS) "$UPS_C" [ -n "$RUNAS" ] && chgrp $(id -gn $RUNAS) "$UPS_C"
@ -181,26 +239,29 @@ build_config() {
start_driver_instance() { start_driver_instance() {
local cfg="$1" local cfg="$1"
local requested="$2" local requested="$2"
local RUNAS=nut
local driver local driver
local STATEPATH=/var/run/nut
local RUNAS=nut
[ "$havedriver" != 1 ] && return
# If wanting a specific instance, only start it # 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")" mkdir -m 0755 -p "$(dirname "$UPS_C")"
[ ! -s "$UPS_C" ] && build_config [ ! -s "$UPS_C" ] && build_config
# Avoid hotplug inadvertenly restarting driver during # Avoid hotplug inadvertenly restarting driver during
# forced shutdown # forced shutdown
[ -f /var/run/killpower ] && return 0 [ -f /var/run/killpower ] && return 0
[ -d /var/run/nut ] && [ -f /var/run/nut/disable-hotplug ] && return 0 [ -d /var/run/nut ] && [ -f /var/run/nut/disable-hotplug ] && return 0
config_foreach upsd_statepath upsd
if [ -n "$RUNAS" ]; then if [ -n "$RUNAS" ]; then
chown $RUNAS:$(id -gn $RUNAS) "${STATEPATH}" chown $RUNAS:$(id -gn $RUNAS) "${STATEPATH}"
chown $RUNAS:$(id -gn $RUNAS) "$(dirname "$UPS_C")"
fi fi
config_get driver "$cfg" driver "usbhid-ups" config_get driver "$cfg" driver "usbhid-ups"
@ -213,9 +274,11 @@ start_driver_instance() {
} }
start_server_instance() { start_server_instance() {
local RUNAS STATEPATH
local RUNAS
build_config build_config
[ "$haveserver" != 1 ] && return
procd_open_instance "upsd" procd_open_instance "upsd"
procd_set_param respawn procd_set_param respawn
procd_set_param stderr 0 procd_set_param stderr 0
@ -225,30 +288,26 @@ start_server_instance() {
} }
start_service() { start_service() {
local havedriver haveserver
local STATEPATH=/var/run/nut local STATEPATH=/var/run/nut
# Avoid hotplug inadvertenly restarting driver during # Avoid hotplug inadvertenly restarting driver during
# forced shutdown # forced shutdown
[ -f /var/run/killpower ] && return 0 [ -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_load nut_server
config_foreach upsd_statepath upsd
[ -d "${STATEPATH}" ] || {
mkdir -m 0750 -p "${STATEPATH}"
}
build_config build_config
config_foreach start_driver_instance driver "$@" config_foreach start_driver_instance driver "$@"
[ "$1" != "upsd" ] && [ x"$1" != x"" ] && return 0
start_server_instance "upsd" start_server_instance "upsd"
} }
reload_service() { reload_service() {
stop stop
sleep 2 sleep 2
local havedriver haveserver
start start
} }


Loading…
Cancel
Save