2024-11-07 19:03:21 +00:00
|
|
|
#!/bin/sh -e
|
|
|
|
|
|
|
|
checkInitManager() {
|
|
|
|
for manager in $1; do
|
|
|
|
if command_exists "$manager"; then
|
|
|
|
INIT_MANAGER="$manager"
|
|
|
|
printf "%b\n" "${CYAN}Using ${manager} to interact with init system${RC}"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -z "$INIT_MANAGER" ]; then
|
|
|
|
printf "%b\n" "${RED}Can't find a supported init system${RC}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
startService() {
|
|
|
|
case "$INIT_MANAGER" in
|
|
|
|
systemctl)
|
|
|
|
"$ESCALATION_TOOL" "$INIT_MANAGER" start "$1"
|
|
|
|
;;
|
|
|
|
rc-service)
|
|
|
|
"$ESCALATION_TOOL" "$INIT_MANAGER" "$1" start
|
|
|
|
;;
|
2024-12-24 12:51:53 +00:00
|
|
|
runit)
|
|
|
|
"$ESCALATION_TOOL" sv start "$1"
|
|
|
|
;;
|
2024-11-07 19:03:21 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
stopService() {
|
|
|
|
case "$INIT_MANAGER" in
|
|
|
|
systemctl)
|
|
|
|
"$ESCALATION_TOOL" "$INIT_MANAGER" stop "$1"
|
|
|
|
;;
|
|
|
|
rc-service)
|
|
|
|
"$ESCALATION_TOOL" "$INIT_MANAGER" "$1" stop
|
|
|
|
;;
|
2024-12-24 12:51:53 +00:00
|
|
|
runit)
|
|
|
|
"$ESCALATION_TOOL" sv stop "$1"
|
|
|
|
;;
|
2024-11-07 19:03:21 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
enableService() {
|
|
|
|
case "$INIT_MANAGER" in
|
|
|
|
systemctl)
|
|
|
|
"$ESCALATION_TOOL" "$INIT_MANAGER" enable "$1"
|
|
|
|
;;
|
|
|
|
rc-service)
|
|
|
|
"$ESCALATION_TOOL" rc-update add "$1"
|
|
|
|
;;
|
2024-12-24 12:51:53 +00:00
|
|
|
runit)
|
|
|
|
"$ESCALATION_TOOL" mkdir -p "/run/runit/supervise.$1"
|
|
|
|
"$ESCALATION_TOOL" ln -sf "/etc/sv/$1" "/var/service/"
|
2025-01-10 05:33:45 +00:00
|
|
|
sleep 5
|
2024-12-24 12:51:53 +00:00
|
|
|
;;
|
2024-11-07 19:03:21 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
disableService() {
|
|
|
|
case "$INIT_MANAGER" in
|
|
|
|
systemctl)
|
|
|
|
"$ESCALATION_TOOL" "$INIT_MANAGER" disable "$1"
|
|
|
|
;;
|
|
|
|
rc-service)
|
|
|
|
"$ESCALATION_TOOL" rc-update del "$1"
|
|
|
|
;;
|
2024-12-24 12:51:53 +00:00
|
|
|
runit)
|
|
|
|
"$ESCALATION_TOOL" rm -f "/var/service/$1"
|
|
|
|
;;
|
2024-11-07 19:03:21 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
startAndEnableService() {
|
|
|
|
case "$INIT_MANAGER" in
|
|
|
|
systemctl)
|
|
|
|
"$ESCALATION_TOOL" "$INIT_MANAGER" enable --now "$1"
|
|
|
|
;;
|
2024-12-27 03:21:31 +00:00
|
|
|
rc-service|runit)
|
2024-12-24 12:51:53 +00:00
|
|
|
enableService "$1"
|
|
|
|
startService "$1"
|
|
|
|
;;
|
2024-11-07 19:03:21 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
isServiceActive() {
|
|
|
|
case "$INIT_MANAGER" in
|
|
|
|
systemctl)
|
|
|
|
"$ESCALATION_TOOL" "$INIT_MANAGER" is-active --quiet "$1"
|
|
|
|
;;
|
|
|
|
rc-service)
|
|
|
|
"$ESCALATION_TOOL" "$INIT_MANAGER" "$1" status --quiet
|
|
|
|
;;
|
2024-12-24 12:51:53 +00:00
|
|
|
runit)
|
|
|
|
"$ESCALATION_TOOL" sv status "$1" >/dev/null 2>&1
|
|
|
|
;;
|
2024-11-07 19:03:21 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2024-12-24 12:51:53 +00:00
|
|
|
checkInitManager 'systemctl rc-service runit'
|