Skip to content

Commit

Permalink
scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in: introduce *_setDocL…
Browse files Browse the repository at this point in the history
…ink() to refer to specific driver man pages, provide systemd implementation [#722]

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Dec 22, 2024
1 parent 1a8c0f2 commit 6915fc2
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ if [ -z "${TIMEOUT_CMD+x}" ]; then
fi
fi

# Should be populated by configure script during NUT build:
NUT_WEBSITE_BASE='@NUT_WEBSITE_BASE@'
# Fallback, no trailing slash!
[ -n "${NUT_WEBSITE_BASE-}" ] || NUT_WEBSITE_BASE='https://www.networkupstools.org'

# 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=""
Expand All @@ -195,6 +200,7 @@ hook_validInstanceSuffixName=""
hook_getSavedDeviceName=""
hook_findSavedDeviceName=""
hook_setSavedDeviceName=""
hook_setDocLink=""
hook_getSavedMD5=""
hook_setSavedMD5=""
hook_restart_upsd=""
Expand All @@ -213,6 +219,7 @@ case "${SERVICE_FRAMEWORK-}" in
hook_getSavedDeviceName="smf_getSavedDeviceName"
hook_findSavedDeviceName="smf_findSavedDeviceName"
hook_setSavedDeviceName="smf_setSavedDeviceName"
hook_setDocLink="smf_setDocLink"
hook_getSavedMD5="smf_getSavedMD5"
hook_setSavedMD5="smf_setSavedMD5"
hook_restart_upsd="smf_restart_upsd"
Expand All @@ -230,6 +237,7 @@ case "${SERVICE_FRAMEWORK-}" in
hook_getSavedDeviceName="systemd_getSavedDeviceName"
hook_findSavedDeviceName="systemd_findSavedDeviceName"
hook_setSavedDeviceName="systemd_setSavedDeviceName"
hook_setDocLink="systemd_setDocLink"
hook_getSavedMD5="systemd_getSavedMD5"
hook_setSavedMD5="systemd_setSavedMD5"
hook_restart_upsd="systemd_restart_upsd"
Expand All @@ -247,6 +255,7 @@ case "${SERVICE_FRAMEWORK-}" in
hook_getSavedDeviceName="selftest_NOOP"
hook_findSavedDeviceName="selftest_NOOP"
hook_setSavedDeviceName="selftest_NOOP"
hook_setDocLink="selftest_NOOP"
hook_getSavedMD5="selftest_NOOP"
hook_setSavedMD5="selftest_NOOP"
hook_restart_upsd="selftest_NOOP"
Expand Down Expand Up @@ -739,6 +748,7 @@ smf_registerInstance() {
smf_setSavedMD5 "$SVCINST" "`upsconf_getSection_MD5 "$DEVICE"`"
# Save original device (config section) name to speed up some searches
smf_setSavedDeviceName "$SVCINST" "$DEVICE"
smf_setDocLink "$SVCINST" "$DEVICE"

/usr/sbin/svcadm refresh "${TARGET_FMRI}" || return
if [ "$AUTO_START" = yes ] ; then
Expand Down Expand Up @@ -853,6 +863,16 @@ smf_setSavedDeviceName() {
[ -n "$1" ] || return # No-op for global section
smf_setSavedUniq "nut-driver:$1" "nut-driver-enumerator-generated-devicename" "DEVICE" astring "$2"
}
smf_setDocLink() {
# Save device (config section) name $2 into service instance $1
[ -n "$1" ] || return # No-op for global section
__TARGET_FMRI="$1"
__DRV=`"upsconf_getDriver "$2"`"
#Documentation=man:${__DRV}(8)
#Documentation=${NUT_WEBSITE_BASE}/docs/man/${__DRV}.html
unset __DRV
[ $? = 0 ] && echo "OK" || { echo "FAILED to stash the device doc links">&2 ; return 1 ; }
}
smf_restart_upsd() {
echo "Reloading or restarting NUT data server to make sure it knows new configuration..."
/usr/sbin/svcadm enable "nut-server" 2>/dev/null
Expand Down Expand Up @@ -924,6 +944,7 @@ EOF
systemd_setSavedMD5 "$SVCINST" "`upsconf_getSection_MD5 "$DEVICE"`"
systemd_setSavedDeviceName "$SVCINST" "$DEVICE"
systemd_setDocLink "$SVCINST" "$DEVICE"
if [ "$AUTO_START" = yes ] ; then
systemd_refreshSupervizor || echo "WARNING: Somehow managed to fail systemd_refreshSupervizor()" >&2
Expand Down Expand Up @@ -994,6 +1015,20 @@ Environment='DEVICE="$2"'
EOF
[ $? = 0 ] && echo "OK" || { echo "FAILED to stash the device name">&2 ; return 1 ; }
}
systemd_setDocLink() {
# Save device (config section) name $2 into service instance $1
[ -n "$1" ] || return # No-op for global section
PROPFILE="${SYSTEMD_CONFPATH}/nut-driver@$1.service.d/nut-driver-enumerator-generated-doclink.conf"
mkdir -p "${SYSTEMD_CONFPATH}/nut-driver@$1.service.d" && \
__DRV=`"upsconf_getDriver "$2"`"
cat > "${PROPFILE}" << EOF
[Unit]
Documentation=man:${__DRV}(8)
Documentation=${NUT_WEBSITE_BASE}/docs/man/${__DRV}.html
EOF
unset __DRV
[ $? = 0 ] && echo "OK" || { echo "FAILED to stash the device name">&2 ; return 1 ; }
}
systemd_setSavedMD5() {
# Save checksum value $2 into service instance $1
PROP="SECTION_CHECKSUM"
Expand Down

0 comments on commit 6915fc2

Please sign in to comment.