dot

packages and services management
Log | Files | Refs | README

commit 30d2bb8505b0ea836424636d701f2b0afce56fdf
parent a9dc8bd1aa43a9aa47c18fba6592fe6676b7ff88
Author: Josuah Demangeon <josuah.demangeon@gandi.net>
Date:   Mon, 19 Jun 2017 18:35:13 +0200

fixed start / stop / restart / status

Diffstat:
MSERVICE | 27++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/SERVICE b/SERVICE @@ -10,10 +10,17 @@ die() status() { - [ -f "$VAR/pid/$1" ] && - grep -qF "$1" "/proc/$(cat "$VAR/pid/$1")/cmdline" && - printf '%-20s [running]\n' "$1" && return 0 || - printf '%-20s [stopped]\n' "$1" && rm -f "$VAR/$1/pid" && return 1 + if + [ -f "$VAR/pid/$1" ] && + grep -qF "$1" "/proc/$(cat "$VAR/pid/$1")/cmdline" + then + printf '%-20s [running]\n' "$1" + return 0 + else + printf '%-20s [stopped]\n' "$1" + rm -f "$VAR/$1/pid" + return 1 + fi } @@ -24,14 +31,18 @@ start() service="$1" shift + status "$service" && return 1 + . "$ETC/$service/start" "$@" > "$VAR/log/$service" 2>&1 printf %s $! > "$VAR/pid/$service" + + status "$service" } stop() { - status "$1" || exit 1 + status "$1" || return 1 read pid < "$VAR/pid/$1" @@ -40,7 +51,7 @@ stop() else kill -14 "$pid" fi && rm "$VAR/pid/$1" - status "$1" || exit 0 + status "$1" && return 1 || return 0 } @@ -61,9 +72,11 @@ command=$1 shift case "$command" in -( start ) start "$@" ;; +( start ) start "$@" ;; ( stop ) stop "$@" ;; ( restart ) stop "$@" && start "$@" ;; ( status ) status "$1" ;; ( * ) usage ;; esac + +# we do not execute anything to keep the last exit status