dot

packages and services management
Log | Files | Refs | README

commit 2c26fff1349aafcd274f1bf4e86e07b840046086
parent efd44e5a833a26e2504bec28956f93965a096676
Author: Josuah Demangeon <josuah.demangeon@gandi.net>
Date:   Thu, 22 Jun 2017 07:54:05 +0200

leaner command management

Diffstat:
MSERVICE | 41++++++++++++++++++++---------------------
1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/SERVICE b/SERVICE @@ -24,7 +24,7 @@ case "$cmd" in ( start | stop | restart | status ) : ;; ( * ) usage ;; esac mkdir -p "$VAR/pid" "$VAR/log" -run=0 +run=0 act=0 [ -d "$VAR/pid/$srv" ] && for pid in $(ls "$VAR/pid/$srv") do @@ -34,34 +34,33 @@ do if cmp "$VAR/pid/$srv/$pid" "/proc/$pid/cmdline" 2> /dev/null then - printf '%-15s [running] %s' "$srv" + if [ "$cmd" = stop ] || [ "$cmd" = restart ] + then + kill -14 "$pid" && rm -f "$VAR/pid/$srv/$pid" && + printf '%-15s [stoping]' "$srv" + else + run=1 + printf '%-15s [running]' "$srv" + fi + tr '\0' ' ' < "$VAR/pid/$srv/$pid" printf '\n' - run=1 - if [ "$cmd" = stop ] || [ "$cmd" = restart ] - then kill -14 "$pid" && rm -f "$VAR/pid/$srv/$pid" && run=0 - fi + act=1 fi done -if [ "$run" = 0 ] +[ "$act" = 0 ] && [ "$cmd" = status ] && printf '%-15s [stopped]\n' "$srv" + +if [ "$run" = 0 ] && [ "$cmd" = start ] || [ "$cmd" = restart ] then - printf '%-15s [stopped]\n' "$srv" + mkdir -p "$VAR/pid/$srv" + . "$ETC/$srv/start" "$@" >> "$VAR/log/$srv" 2>&1 && pid=$! && + cp "/proc/$pid/cmdline" "$VAR/pid/$srv/$pid" - if [ "$cmd" = start ] || [ "$cmd" = restart ] - then - mkdir -p "$VAR/pid/$srv" - . "$ETC/$srv/start" "$@" >> "$VAR/log/$srv" 2>&1 && pid=$! && - cp "/proc/$pid/cmdline" "$VAR/pid/$srv/$pid" - printf '%-15s [started] ' "$srv" - tr '\0' ' ' < "$VAR/pid/$srv/$pid" - printf '\n' - fi + printf '%-15s [started] ' "$srv" + tr '\0' ' ' < "$VAR/pid/$srv/$pid" + printf '\n' fi find "$VAR/pid" -depth -type d -exec rmdir {} + 2> /dev/null - -if [ "$cmd" = restart ] || [ "$cmd" = start ] && [ "$run" = 0 ] -then : #$0 status "$srv" "$@" -fi