dot

packages and services management
Log | Files | Refs | README

commit efd44e5a833a26e2504bec28956f93965a096676
parent b205683ecc9e272e6bcb50e02435fb0d169d22b6
Author: Josuah Demangeon <josuah.demangeon@gandi.net>
Date:   Wed, 21 Jun 2017 13:47:14 +0200

Works at least with scripts without arguments

Diffstat:
MSERVICE | 35+++++++++++++++++++++--------------
1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/SERVICE b/SERVICE @@ -17,44 +17,51 @@ shift 2 case "$cmd" in ( start | stop | restart | status ) : ;; ( * ) usage ;; esac -[ -f "$ETC/$srv/start" ] || echo "no start script in $ETC/$1" && exit 1 +[ ! -f "$ETC/$srv/start" ] && echo "no start script in $ETC/$1" && exit 1 # --- main --------------------------------------------------------------------- mkdir -p "$VAR/pid" "$VAR/log" -return=1 +run=0 -ls "$VAR/pid/$srv" | while read -r pid arguments +[ -d "$VAR/pid/$srv" ] && for pid in $(ls "$VAR/pid/$srv") do for arg in "$@" - do grep -F "$@" "$VAR/pid/$srv/$pid" || continue 2 + do grep -q -F "$@" "$VAR/pid/$srv/$pid" || continue 2 done - if cmp "$VAR/pid/$srv/$pid" "/proc/$pid/cmdline" + if cmp "$VAR/pid/$srv/$pid" "/proc/$pid/cmdline" 2> /dev/null then - printf '%-20s [running] ' - tr '\0' ' ' "$VAR/pid/$srv/$pid" + printf '%-15s [running] %s' "$srv" + tr '\0' ' ' < "$VAR/pid/$srv/$pid" printf '\n' - return=0 + run=1 if [ "$cmd" = stop ] || [ "$cmd" = restart ] - then kill -14 "$pid" && rm "$VAR/pid/$srv/$pid" + then kill -14 "$pid" && rm -f "$VAR/pid/$srv/$pid" && run=0 fi fi done -if [ "$return" = 1 ] +if [ "$run" = 0 ] then - printf '%-20s [stopped]\n' "$1" + printf '%-15s [stopped]\n' "$srv" if [ "$cmd" = start ] || [ "$cmd" = restart ] then mkdir -p "$VAR/pid/$srv" - sh "$ETC/$srv/start" "$@" >> "$VAR/log/$srv" 2>&1 && - cp "/proc/$!/cmdline" "$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 fi -return "$return" +find "$VAR/pid" -depth -type d -exec rmdir {} + 2> /dev/null + +if [ "$cmd" = restart ] || [ "$cmd" = start ] && [ "$run" = 0 ] +then : #$0 status "$srv" "$@" +fi