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
|
2021-12-21 06:37:00 +05:30
|
|
|
# https://github.com/OpenRC/openrc/blob/HEAD/AUTHORS
|
2016-02-02 00:12:58 +05:30
|
|
|
#
|
|
|
|
# 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
|
2021-12-21 06:37:00 +05:30
|
|
|
# distribution and at https://github.com/OpenRC/openrc/blob/HEAD/LICENSE
|
2016-02-02 00:12:58 +05:30
|
|
|
# This file may not be copied, modified, propagated, or distributed
|
|
|
|
# except according to the terms contained in the LICENSE file.
|
|
|
|
|
2018-10-10 04:19:02 +05:30
|
|
|
extra_commands="healthcheck unhealthy ${extra_commands}"
|
|
|
|
|
2016-02-02 00:12:58 +05:30
|
|
|
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 \
|
2018-12-03 02:45:51 +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 \
|
2018-10-10 04:19:02 +05:30
|
|
|
${healthcheck_delay:+--healthcheck-delay} $healthcheck_delay \
|
|
|
|
${healthcheck_timer:+--healthcheck-timer} $healthcheck_timer \
|
2021-06-13 22:56:24 +05:30
|
|
|
${capabilities+--capabilities} "$capabilities" \
|
2022-01-03 21:11:57 +05:30
|
|
|
${secbits:+--secbits} "$secbits" \
|
2016-02-02 00:12:58 +05:30
|
|
|
${command_user+--user} $command_user \
|
2017-11-21 04:15:51 +05:30
|
|
|
${umask+--umask} $umask \
|
2018-05-30 21:41:10 +05:30
|
|
|
${supervise_daemon_args:-${start_stop_daemon_args}} \
|
2016-02-02 00:12:58 +05:30
|
|
|
$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}"
|
2018-12-03 02:45:51 +05:30
|
|
|
[ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}"
|
2016-05-20 04:29:40 +05:30
|
|
|
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")"
|
2018-12-03 02:45:51 +05:30
|
|
|
local startpidfile="$(service_get_value "pidfile")"
|
2016-05-20 04:29:40 +05:30
|
|
|
chroot="${startchroot:-$chroot}"
|
2018-12-03 02:45:51 +05:30
|
|
|
pidfile="${startpidfile:-$pidfile}"
|
2016-02-02 00:12:58 +05:30
|
|
|
ebegin "Stopping ${name:-$RC_SVCNAME}"
|
2017-10-28 05:52:09 +05:30
|
|
|
supervise-daemon "${RC_SVCNAME}" --stop \
|
2018-12-04 00:13:12 +05:30
|
|
|
${pidfile:+--pidfile} $chroot$pidfile
|
2016-02-02 00:12:58 +05:30
|
|
|
|
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
|
|
|
}
|
2018-10-10 04:19:02 +05:30
|
|
|
|
|
|
|
healthcheck()
|
|
|
|
{
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
unhealthy()
|
|
|
|
{
|
|
|
|
return 0
|
|
|
|
}
|