diff options
author | William Hubbs <w.d.hubbs@gmail.com> | 2016-02-01 12:42:58 -0600 |
---|---|---|
committer | William Hubbs <w.d.hubbs@gmail.com> | 2016-04-27 11:13:50 -0500 |
commit | 62410eaf4ba92516a58a550717d7f3faf63bb79f (patch) | |
tree | a521b050c262f76ea188eaba4ce1a5caec600c52 /sh | |
parent | fd80b6fc67ec6a0fe4853167fb67ee40bb51b742 (diff) |
add daemon supervisor
The supervise-daemon process is meant to be a lightweight supervisor
which can monitor and restart a daemon if it crashes.
Diffstat (limited to 'sh')
-rw-r--r-- | sh/Makefile | 3 | ||||
-rw-r--r-- | sh/openrc-run.sh.in | 4 | ||||
-rw-r--r-- | sh/supervise-daemon.sh | 49 |
3 files changed, 55 insertions, 1 deletions
diff --git a/sh/Makefile b/sh/Makefile index b9b9fb33..24c23159 100644 --- a/sh/Makefile +++ b/sh/Makefile @@ -1,7 +1,8 @@ DIR= ${LIBEXECDIR}/sh SRCS= init.sh.in functions.sh.in gendepends.sh.in \ openrc-run.sh.in rc-functions.sh.in tmpfiles.sh.in ${SRCS-${OS}} -INC= rc-mount.sh functions.sh rc-functions.sh s6.sh start-stop-daemon.sh +INC= functions.sh rc-mount.sh rc-functions.sh s6.sh start-stop-daemon.sh \ + supervise-daemon.sh BIN= gendepends.sh init.sh openrc-run.sh tmpfiles.sh ${BIN-${OS}} INSTALLAFTER= _installafter diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in index fb6f95be..36bc3663 100644 --- a/sh/openrc-run.sh.in +++ b/sh/openrc-run.sh.in @@ -154,6 +154,7 @@ start() local func=ssd_start case "$supervisor" in s6) func=s6_start ;; + supervise-daemon) func=supervise_start ;; ?*) ewarn "Invalid supervisor, \"$supervisor\", using start-stop-daemon" ;; @@ -166,6 +167,7 @@ stop() local func=ssd_stop case "$supervisor" in s6) func=s6_stop ;; + supervise-daemon) func=supervise_stop ;; ?*) ewarn "Invalid supervisor, \"$supervisor\", using start-stop-daemon" ;; @@ -178,6 +180,7 @@ status() local func=ssd_status case "$supervisor" in s6) func=s6_status ;; + supervise-daemon) func=supervise_status ;; ?*) ewarn "Invalid supervisor, \"$supervisor\", using start-stop-daemon" ;; @@ -215,6 +218,7 @@ fi # load service supervisor functions sourcex "@LIBEXECDIR@/sh/s6.sh" sourcex "@LIBEXECDIR@/sh/start-stop-daemon.sh" +sourcex "@LIBEXECDIR@/sh/supervise-daemon.sh" # Set verbose mode if yesno "${rc_verbose:-$RC_VERBOSE}"; then diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh new file mode 100644 index 00000000..34e3ef71 --- /dev/null +++ b/sh/supervise-daemon.sh @@ -0,0 +1,49 @@ +# start / stop / status functions for supervise-daemon + +# Copyright (c) 2016 The OpenRC Authors. +# See the Authors file at the top-level directory of this distribution and +# https://github.com/OpenRC/openrc/blob/master/AUTHORS +# +# This file is part of OpenRC. It is subject to the license terms in +# the LICENSE file found in the top-level directory of this +# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE +# This file may not be copied, modified, propagated, or distributed +# except according to the terms contained in the LICENSE file. + +supervise_start() +{ + if [ -z "$command" ]; then + ewarn "The command variable is undefined." + ewarn "There is nothing for ${name:-$RC_SVCNAME} to start." + return 1 + fi + + ebegin "Starting ${name:-$RC_SVCNAME}" + eval supervise-daemon --start \ + ${pidfile:+--pidfile} $pidfile \ + ${command_user+--user} $command_user \ + $supervise_daemon_args \ + $command \ + -- $command_args $command_args_foreground + rc=$? + [ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}" + eend $rc "failed to start $RC_SVCNAME" +} + +supervise_stop() +{ + local startpidfile="$(service_get_value "pidfile")" + pidfile="${startpidfile:-$pidfile}" + [ -n "$pidfile" ] || return 0 + ebegin "Stopping ${name:-$RC_SVCNAME}" + supervise-daemon --stop \ + ${pidfile:+--pidfile} $pidfile \ + ${stopsig:+--signal} $stopsig + + eend $? "Failed to stop $RC_SVCNAME" +} + +supervise_status() +{ + _status +} |