mirror of
https://github.com/novatiq/packages.git
synced 2026-04-30 15:38:40 +01:00
nut: Fix statepath handling
The statepath was getting the wrong permission and/or not created at the right time. This commit includes fixes for handling the statepath (typically /var/run/nut). Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
This commit is contained in:
@@ -31,10 +31,9 @@ get_write_driver_config() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
upsd_statepath() {
|
upsd_statepath() {
|
||||||
local cfg="$1"
|
|
||||||
local statepath
|
local statepath
|
||||||
|
|
||||||
config_get statepath "$cfg" statepath "/var/run/nut"
|
config_get statepath upsd statepath /var/run/nut
|
||||||
STATEPATH="$statepath"
|
STATEPATH="$statepath"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +63,7 @@ upsd_config() {
|
|||||||
config_get runas "$cfg" runas
|
config_get runas "$cfg" runas
|
||||||
RUNAS="$runas"
|
RUNAS="$runas"
|
||||||
|
|
||||||
config_get statepath "$cfg" statepath "/var/run/nut"
|
config_get statepath "$cfg" statepath /var/run/nut
|
||||||
STATEPATH="$statepath"
|
STATEPATH="$statepath"
|
||||||
|
|
||||||
config_get maxage "$cfg" maxage
|
config_get maxage "$cfg" maxage
|
||||||
@@ -128,13 +127,14 @@ build_server_config() {
|
|||||||
chmod 0644 /var/etc/nut/nut.conf
|
chmod 0644 /var/etc/nut/nut.conf
|
||||||
|
|
||||||
[ -d "${STATEPATH}" ] || {
|
[ -d "${STATEPATH}" ] || {
|
||||||
mkdir -m 0750 -p "${STATEPATH}"
|
mkdir -p "${STATEPATH}"
|
||||||
|
chmod 0750 "${STATEPATH}"
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ -n "$RUNAS" ]; then
|
if [ -n "$RUNAS" ]; then
|
||||||
chown $RUNAS:$(id -gn $RUNAS) "${STATEPATH}"
|
chown "$RUNAS":"$(id -gn "$RUNAS")" "${STATEPATH}"
|
||||||
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
|
haveserver=1
|
||||||
}
|
}
|
||||||
@@ -235,13 +235,11 @@ build_config() {
|
|||||||
chmod 0640 "$UPS_C"
|
chmod 0640 "$UPS_C"
|
||||||
|
|
||||||
config_load nut_server
|
config_load nut_server
|
||||||
config_foreach upsd_statepath upsd
|
|
||||||
|
|
||||||
upsd_runas
|
upsd_runas
|
||||||
config_foreach build_global_driver_config driver_global
|
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"
|
upsd_statepath
|
||||||
|
|
||||||
build_server_config
|
build_server_config
|
||||||
[ -n "$RUNAS" ] && chgrp "$(id -gn "$RUNAS")" "$UPS_C"
|
[ -n "$RUNAS" ] && chgrp "$(id -gn "$RUNAS")" "$UPS_C"
|
||||||
}
|
}
|
||||||
@@ -260,18 +258,19 @@ start_driver_instance() {
|
|||||||
|
|
||||||
mkdir -m 0755 -p "$(dirname "$UPS_C")"
|
mkdir -m 0755 -p "$(dirname "$UPS_C")"
|
||||||
|
|
||||||
[ ! -s "$UPS_C" ] && build_config
|
upsd_statepath
|
||||||
|
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
|
if [ -d /var/run/nut ] && [ -f /var/run/nut/disable-hotplug ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
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}"
|
||||||
|
chgrp "$(id -gn "$RUNAS")" "$UPS_C"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
config_get driver "$cfg" driver "usbhid-ups"
|
config_get driver "$cfg" driver "usbhid-ups"
|
||||||
|
|||||||
Reference in New Issue
Block a user