From 8f3224ef57423bad6a2fc9dbe38ced628591a6ca Mon Sep 17 00:00:00 2001 From: zachir Date: Thu, 9 Feb 2023 21:23:46 -0600 Subject: add runit support --- servicectl | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/servicectl b/servicectl index df96506..c26d5f2 100755 --- a/servicectl +++ b/servicectl @@ -20,15 +20,26 @@ reverse_array () { ## FIND INIT INIT="$(readlink $(type init) )" -if `type s6-rc >/dev/null`; then +if `type s6-rc >/dev/null 2>&1`; then S6=y else unset S6 fi -if [ "$INIT" = "openrc-init" ]; then - OPENRC=y - unset RUNIT DINIT +case "$INIT" in + "openrc-init") OPENRC=y ; unset RUNIT DINIT ;; + "runit-init") RUNIT=y ; unset OPENRC DINIT ;; + "*") print "Unknown init!\n" +esac + +## CHECK INIT HELPER + +if [ -n "$RUNIT" ]; then + if `type rsm >/dev/null 2>&1`; then + RSM=y + else + unset RSM + fi fi ## CHECK PRIVS @@ -45,6 +56,12 @@ start_service () { fi if [ -n "$OPENRC" ]; then $ROOTCMD rc-service $1 start + elif [ -n "$RUNIT" ]; then + if [ -n "$RSM" ]; then + $ROOTCMD rsm start $1 + else + $ROOTCMD sv start $1 + fi fi } @@ -54,6 +71,12 @@ stop_service () { fi if [ -n "$OPENRC" ]; then $ROOTCMD rc-service $1 stop + elif [ -n "$RUNIT" ]; then + if [ -n "$RSM" ]; then + $ROOTCMD rsm stop $1 + else + $ROOTCMD sv stop $1 + fi fi } @@ -63,6 +86,12 @@ enable_service () { fi if [ -n "$OPENRC" ]; then $ROOTCMD rc-update add $1 default + elif [ -n "$RUNIT" ]; then + if [ -n "$RSM" ]; then + $ROOTCMD rsm enable $1 + else + print "enabling runit services manually not presently supported; use rsm\n" + fi fi } @@ -72,6 +101,12 @@ disable_service () { fi if [ -n "$OPENRC" ]; then $ROOTCMD rc-update del $1 default + elif [ -n "$RUNIT" ]; then + if [ -n "$RSM" ]; then + $ROOTCMD rsm disable $1 + else + print "disabling runit services manually not presently supported; use rsm\n" + fi fi } @@ -81,6 +116,12 @@ status_service () { fi if [ -n "$OPENRC" ]; then $ROOTCMD rc-service status + elif [ -n "$RUNIT" ]; then + if [ -n "$RSM" ]; then + $ROOTCMD rsm status + else + print "getting status of runit services manually not presently supported; use rsm\n" + fi fi } -- cgit v1.2.3