From 858dd56218b277ff14ba6c1d4ba1f7416f4935b8 Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Mon, 31 Jul 2023 13:48:38 +0200 Subject: Improve svc utils --- lib/util/svc.bash | 113 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 78 insertions(+), 35 deletions(-) (limited to 'lib/util') diff --git a/lib/util/svc.bash b/lib/util/svc.bash index 02d869c..be1f003 100644 --- a/lib/util/svc.bash +++ b/lib/util/svc.bash @@ -34,12 +34,18 @@ svc_disable() { local service=$1 - case "${BASHTARD_PLATFORM[key]}" in - linux-alpine_linux) set -- /sbin/rc-update del "$service" ;; - linux-gentoo) set -- /sbin/rc-update del "$service" ;; - linux-*) set -- systemctl disable "$service" ;; + case "${BASHTARD_PLATFORM[os]}" in + linux) + case "${BASHTARD_PLATFORM[init]}" in + openrc) set -- /sbin/rc-update del "$service" ;; + systemd) set -- systemctl disable "$service" ;; + *) + crit "$system" "No service manager support to disable with ${BASHTARD_PLATFORM[init]}" + return 1 + esac + ;; *) - crit "$system" "No service manager configured for ${BASHTARD_PLATFORM[key]}" + crit "$system" "No service manager support to enable for ${BASHTARD_PLATFORM[key]}" return 1 esac @@ -54,7 +60,16 @@ svc_enable() { local service=$1 local rc - case "${BASHTARD_PLATFORM[key]}" in + case "${BASHTARD_PLATFORM[os]}" in + linux) + case "${BASHTARD_PLATFORM[init]}" in + openrc) set -- /sbin/rc-update del "$service" ;; + systemd) set -- systemctl disable "$service" ;; + *) + crit "$system" "No service manager support to enable with ${BASHTARD_PLATFORM[init]}" + return 1 + esac + ;; freebsd) rc="$(printf '%s_enable="YES"' "$service")" @@ -64,13 +79,9 @@ svc_enable() { fi return 0 - ;; - linux-alpine_linux) set -- /sbin/rc-update add "$service" ;; - linux-gentoo) set -- /sbin/rc-update add "$service" ;; - linux-*) set -- systemctl enable "$service" ;; *) - crit "$system" "No service manager configured for ${BASHTARD_PLATFORM[key]}" + crit "$system" "No service manager support to enable for ${BASHTARD_PLATFORM[key]}" return 1 esac @@ -84,13 +95,21 @@ svc_reload() { local service=$1 - case "${BASHTARD_PLATFORM[key]}" in - freebsd) set -- service "$service" reload ;; - linux-alpine_linux) set -- /sbin/rc-service "$service" reload ;; - linux-gentoo) set -- /sbin/rc-service "$service" reload ;; - linux-*) set -- systemctl reload "$service" ;; + case "${BASHTARD_PLATFORM[os]}" in + linux) + case "${BASHTARD_PLATFORM[init]}" in + openrc) set -- /sbin/rc-service "$service" reload ;; + systemd) set -- systemctl reload "$service" ;; + *) + crit "$system" "No service manager support to reload with ${BASHTARD_PLATFORM[init]}" + return 1 + esac + ;; + freebsd) + set -- service "$service" reload + ;; *) - crit "$system" "No service manager configured for ${BASHTARD_PLATFORM[key]}" + crit "$system" "No service manager support to reload for ${BASHTARD_PLATFORM[key]}" return 1 esac @@ -104,13 +123,21 @@ svc_restart() { local service=$1 - case "${BASHTARD_PLATFORM[key]}" in - freebsd) set -- service "$service" restart ;; - linux-alpine_linux) set -- /sbin/rc-service "$service" restart ;; - linux-gentoo) set -- /sbin/rc-service "$service" restart ;; - linux-*) set -- systemctl restart "$service" ;; + case "${BASHTARD_PLATFORM[os]}" in + linux) + case "${BASHTARD_PLATFORM[init]}" in + openrc) set -- /sbin/rc-service "$service" restart ;; + systemd) set -- systemctl restart "$service" ;; + *) + crit "$system" "No service manager support to restart with ${BASHTARD_PLATFORM[init]}" + return 1 + esac + ;; + freebsd) + set -- service "$service" restart + ;; *) - crit "$system" "No service manager configured for ${BASHTARD_PLATFORM[key]}" + crit "$system" "No service manager support to restart for ${BASHTARD_PLATFORM[key]}" return 1 esac @@ -124,13 +151,21 @@ svc_start() { local service=$1 - case "${BASHTARD_PLATFORM[key]}" in - freebsd) set -- service "$service" start ;; - linux-alpine_linux) set -- /sbin/rc-service "$service" start ;; - linux-gentoo) set -- /sbin/rc-service "$service" start ;; - linux-*) set -- systemctl start "$service" ;; + case "${BASHTARD_PLATFORM[os]}" in + linux) + case "${BASHTARD_PLATFORM[init]}" in + openrc) set -- /sbin/rc-service "$service" start ;; + systemd) set -- systemctl start "$service" ;; + *) + crit "$system" "No service manager support to start with ${BASHTARD_PLATFORM[init]}" + return 1 + esac + ;; + freebsd) + set -- service "$service" start + ;; *) - crit "$system" "No service manager configured for ${BASHTARD_PLATFORM[key]}" + crit "$system" "No service manager support to start for ${BASHTARD_PLATFORM[key]}" return 1 esac @@ -144,13 +179,21 @@ svc_stop() { local service=$1 - case "${BASHTARD_PLATFORM[key]}" in - freebsd) set -- service "$service" stop ;; - linux-alpine_linux) set -- /sbin/rc-service "$service" stop ;; - linux-gentoo) set -- /sbin/rc-service "$service" stop ;; - linux-*) set -- systemctl stop "$service" ;; + case "${BASHTARD_PLATFORM[os]}" in + linux) + case "${BASHTARD_PLATFORM[init]}" in + openrc) set -- /sbin/rc-service "$service" stop ;; + systemd) set -- systemctl stop "$service" ;; + *) + crit "$system" "No service manager support to stop with ${BASHTARD_PLATFORM[init]}" + return 1 + esac + ;; + freebsd) + set -- service "$service" stop + ;; *) - crit "$system" "No service manager configured for ${BASHTARD_PLATFORM[key]}" + crit "$system" "No service manager support to stop for ${BASHTARD_PLATFORM[key]}" return 1 esac -- cgit v1.1