dot

packages and services management
Log | Files | Refs | README

commit 4161d093ebf677d70fa924c1f18b1fa656ba327d
parent 6f320b62908816756b5f819a32097f4114123cc2
Author: Josuah Demangeon <josuah.demangeon@gandi.net>
Date:   Wed,  9 Aug 2017 03:17:17 +0200

pkg/bin/pkg-service: fail if the program did not start correctly.

Diffstat:
Mpkg/bin/pkg-service | 23+++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/pkg/bin/pkg-service b/pkg/bin/pkg-service @@ -1,32 +1,31 @@ +set -x usage() { - echo 'service start|stop|restart|status name' + printf '%s ( start | stop | restart | status ) [name]\n' "${0##*/}" exit 1 } # --- arguments ---------------------------------------------------------------- -[ $# -lt 2 ] && usage - +[ $# -ge 2 ] || usage cmd=$1 srv=${2%/} shift 2 -case "$cmd" in ( start | stop | restart | status ) : ;; ( * ) usage ;; esac - -[ ! -f "$PKG/$srv/start" ] && echo "no start script in $PKG/$1" && exit 1 +case "$cmd" in (start | stop | restart | status) ;; ( * ) usage ;; esac +[ -f "$PKG/$srv/start" ] || usage # --- main --------------------------------------------------------------------- mkdir -p "$VAR/pid" "$VAR/log" -run=0 act=0 +running=0 act=0 [ -d "$VAR/pid/$srv" ] && for pid in $(ls "$VAR/pid/$srv") do for arg in "$@" - do grep -q -F "$arg" "$VAR/pid/$srv/$pid" || continue 2 + do grep -qF "$arg" "$VAR/pid/$srv/$pid" || continue 2 done if cmp "$VAR/pid/$srv/$pid" "/proc/$pid/cmdline" 2> /dev/null @@ -38,7 +37,7 @@ do kill "$pid" && printf '%-15s [stopped] %s\n' "$srv" "$cmdline" else - run=1 + running=1 printf '%-15s [running] %s\n' "$srv" "$cmdline" fi fi @@ -46,11 +45,11 @@ done [ "$act""$cmd" = '0''status' ] && printf '%-15s [stopped]\n' "$srv" -if [ "$run" = 0 ] && [ "$cmd" = start ] || [ "$cmd" = restart ] +if [ "$running" = 0 ] && [ "$cmd" = start ] || [ "$cmd" = restart ] then mkdir -p "$VAR/pid/$srv" . "$PKG/$srv/start" "$@" >> "$VAR/log/$srv" 2>&1 && - cp "/proc/$PID/cmdline" "$VAR/pid/$srv/$PID" + cp "/proc/$PID/cmdline" "$VAR/pid/$srv/$PID" || exit 1 printf '%-15s [started] ' "$srv" tr '\0' ' ' < "$VAR/pid/$srv/$PID" @@ -64,4 +63,4 @@ find "$VAR/pid" -type f | while IFS='' read path do cmp "$path" "/proc/${path##*/}/cmdline" 2> /dev/null || rm -f "$path" done -find "$VAR/pid" -depth -type d | xargs rmdir 2> /dev/null || true +find "$VAR/pid" -depth -type d -exec rmdir {} + 2> /dev/null || true