From: Michael Gebetsroither Date: Fri, 1 Aug 2008 11:41:57 +0000 (+0200) Subject: zshrc: add runit sysv emulation support to Start/Stop/Restart/... X-Git-Tag: 0.3.51~8 X-Git-Url: https://git.grml.org/?a=commitdiff_plain;h=f3f939938a90cc7b0dfd6cd8e83710c8c32edeb5;hp=892d64f3a2883ef700e573b425f1b8b12dd0d079;p=grml-etc-core.git zshrc: add runit sysv emulation support to Start/Stop/Restart/... --- diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 9a2a6c8..3554d99 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -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