2016-02-02 00:12:58 +05:30
|
|
|
# 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}"
|
2016-09-20 21:53:46 +05:30
|
|
|
# The eval call is necessary for cases like:
|
|
|
|
# command_args="this \"is a\" test"
|
|
|
|
# to work properly.
|
2017-10-28 05:52:09 +05:30
|
|
|
eval supervise-daemon "${RC_SVCNAME}" --start \
|
2017-09-06 23:52:30 +05:30
|
|
|
${retry:+--retry} $retry \
|
2017-11-21 04:15:51 +05:30
|
|
|
${directory:+--chdir} $directory \
|
2016-05-20 04:29:40 +05:30
|
|
|
${chroot:+--chroot} $chroot \
|
2017-11-21 04:15:51 +05:30
|
|
|
${output_log+--stdout} ${output_log} \
|
|
|
|
${error_log+--stderr} $error_log \
|
2016-02-02 00:12:58 +05:30
|
|
|
${pidfile:+--pidfile} $pidfile \
|
2017-05-11 04:31:10 +05:30
|
|
|
${respawn_delay:+--respawn-delay} $respawn_delay \
|
|
|
|
${respawn_max:+--respawn-max} $respawn_max \
|
|
|
|
${respawn_period:+--respawn-period} $respawn_period \
|
2016-02-02 00:12:58 +05:30
|
|
|
${command_user+--user} $command_user \
|
2017-11-21 04:15:51 +05:30
|
|
|
${umask+--umask} $umask \
|
2016-02-02 00:12:58 +05:30
|
|
|
$supervise_daemon_args \
|
|
|
|
$command \
|
|
|
|
-- $command_args $command_args_foreground
|
|
|
|
rc=$?
|
2016-05-20 04:29:40 +05:30
|
|
|
if [ $rc = 0 ]; then
|
|
|
|
[ -n "${chroot}" ] && service_set_value "chroot" "${chroot}"
|
|
|
|
[ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}"
|
|
|
|
fi
|
2016-09-13 22:57:08 +05:30
|
|
|
eend $rc "failed to start ${name:-$RC_SVCNAME}"
|
2016-02-02 00:12:58 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
supervise_stop()
|
|
|
|
{
|
2016-05-20 04:29:40 +05:30
|
|
|
local startchroot="$(service_get_value "chroot")"
|
2016-02-02 00:12:58 +05:30
|
|
|
local startpidfile="$(service_get_value "pidfile")"
|
2016-05-20 04:29:40 +05:30
|
|
|
chroot="${startchroot:-$chroot}"
|
2016-02-02 00:12:58 +05:30
|
|
|
pidfile="${startpidfile:-$pidfile}"
|
|
|
|
[ -n "$pidfile" ] || return 0
|
|
|
|
ebegin "Stopping ${name:-$RC_SVCNAME}"
|
2017-10-28 05:52:09 +05:30
|
|
|
supervise-daemon "${RC_SVCNAME}" --stop \
|
2016-05-20 04:29:40 +05:30
|
|
|
${pidfile:+--pidfile} $chroot$pidfile \
|
2016-02-02 00:12:58 +05:30
|
|
|
${stopsig:+--signal} $stopsig
|
|
|
|
|
2016-09-13 22:57:08 +05:30
|
|
|
eend $? "Failed to stop ${name:-$RC_SVCNAME}"
|
2016-02-02 00:12:58 +05:30
|
|
|
}
|
|
|
|
|
2017-10-26 01:37:19 +05:30
|
|
|
_check_supervised()
|
|
|
|
{
|
2017-10-26 23:41:12 +05:30
|
|
|
local child_pid start_time
|
|
|
|
child_pid="$(service_get_value "child_pid")"
|
|
|
|
start_time="$(service_get_value "start_time")"
|
|
|
|
if [ -n "${child_pid}" ] && [ -n "${start_time}" ]; then
|
|
|
|
return 1
|
2017-10-26 01:37:19 +05:30
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2016-02-02 00:12:58 +05:30
|
|
|
supervise_status()
|
|
|
|
{
|
2017-10-26 01:37:19 +05:30
|
|
|
if service_stopping; then
|
|
|
|
ewarn "status: stopping"
|
|
|
|
return 4
|
|
|
|
elif service_starting; then
|
|
|
|
ewarn "status: starting"
|
|
|
|
return 8
|
|
|
|
elif service_inactive; then
|
|
|
|
ewarn "status: inactive"
|
|
|
|
return 16
|
|
|
|
elif service_started; then
|
|
|
|
if service_crashed; then
|
|
|
|
if ! _check_supervised; then
|
|
|
|
eerror "status: unsupervised"
|
|
|
|
return 64
|
|
|
|
fi
|
|
|
|
eerror "status: crashed"
|
|
|
|
return 32
|
|
|
|
fi
|
|
|
|
einfo "status: started"
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
einfo "status: stopped"
|
|
|
|
return 3
|
|
|
|
fi
|
2016-02-02 00:12:58 +05:30
|
|
|
}
|