sysmgr

a simplistic service supervisor (deprecated)
git clone git://git.ckyln.com/~cem/sysmgr.git
Log | Files | Refs | README | LICENSE

commit ae6c6fcc17786e2689906c9dad47bd91403eb3ba
parent 8f94a2c852f4134d593d64d1b1a09db1d131649a
Author: Cem Keylan <cem@ckyln.com>
Date:   Tue, 25 Feb 2020 23:23:17 +0300

add a function for checking processes

Diffstat:
Msysmgr | 18+++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/sysmgr b/sysmgr @@ -23,6 +23,15 @@ die() { printf 'error: %s\n' "$@" "exiting..." >&2 ; exit 1 ;} RUNDIR="${RUNDIR:-/run/sysmgr}" SYSDIR="${SYSDIR:-/var/sysmgr}" +checkprocess() { + [ -d /proc ] || { + kill -0 "$1" || return 1 + return 0 + } + [ -d "/proc/$1" ] || return 1 + return 0 +} + cleanup() { # Clean the service run directory so that it can be @@ -144,7 +153,7 @@ fn_runsyssv() { done # check whether services are alive - while kill -0 "$svpid" >/dev/null 2>&1 ; do sleep 1 ; done + while checkprocess "$svpid" ; do sleep 1 ; done # Do a cleanup when the service is killed cleanup @@ -159,6 +168,13 @@ fn_svctl() { } [ -d "${RUNDIR:?}/$2" ] || die "service $2 could not be found." case "$1" in + stat|status) + # The usage of && || is for 'if else', but since 'out' will + # always return 0, this usage is okay. + # shellcheck disable=SC2015 + checkprocess "$(cat "${RUNDIR:?}/$2/pid")" && + out "OK" || { out "DOWN" ; exit 1 ;} + ;; restart) fn_svctl kill "$2" fn_svctl start "$2"