zshrc: add runit sysv emulation support to Start/Stop/Restart/...
authorMichael Gebetsroither <michael.geb@gmx.at>
Fri, 1 Aug 2008 11:41:57 +0000 (13:41 +0200)
committerMichael Gebetsroither <michael.geb@gmx.at>
Fri, 1 Aug 2008 11:41:57 +0000 (13:41 +0200)
etc/zsh/zshrc

index 9a2a6c8..3554d99 100644 (file)
@@ -1827,9 +1827,33 @@ compdef _functions edfunc
 #m# f6 Stop() \kbd{/etc/init.d/\em{process}}\quad\kbd{stop}
 #m# f6 Reload() \kbd{/etc/init.d/\em{process}}\quad\kbd{reload}
 #m# f6 Force-Reload() \kbd{/etc/init.d/\em{process}}\quad\kbd{force-reload}
-if [[ -d /etc/init.d ]] ; then
+if [[ -d /etc/init.d || -d /etc/service ]] ; then
+    __start_stop() {
+        local action_="${1:l}"  # e.g Start/Stop/Restart
+        local service_="$2"
+        local param_="$3"
+
+        local service_target_="$(readlink /etc/init.d/$service_)"
+        if [[ $service_target_ == "/usr/bin/sv" ]]; then
+            # runit
+            case "${action_}" in
+                start) if [[ ! -e /etc/service/$service_ ]]; then
+                           $SUDO ln -s "/etc/sv/$service_" "/etc/service/"
+                       else
+                           $SUDO "/etc/init.d/$service_" "${action_}" "$param_"
+                       fi ;;
+                # there is no reload in runits sysv emulation
+                reload) $SUDO "/etc/init.d/$service_" "force-reload" "$param_" ;;
+                *) $SUDO "/etc/init.d/$service_" "${action_}" "$param_" ;;
+            esac
+        else
+            # sysvinit
+            $SUDO "/etc/init.d/$service_" "${action_}" "$param_"
+        fi
+    }
+
     for i in Start Restart Stop Force-Reload Reload ; do
-        eval "$i() { $SUDO /etc/init.d/\$1 ${i:l} \$2 ; }"
+        eval "$i() { __start_stop $i \"\$1\" \"\$2\" ; }"
     done
 fi