2015-05-12 07:07:28 +08:00
|
|
|
# Start / stop / status functions for s6 support
|
2015-12-05 06:52:19 +08:00
|
|
|
|
|
|
|
# Copyright (c) 2015 The OpenRC Authors.
|
|
|
|
# See the Authors file at the top-level directory of this distribution and
|
2021-12-21 09:07:00 +08:00
|
|
|
# https://github.com/OpenRC/openrc/blob/HEAD/AUTHORS
|
2015-12-05 06:52:19 +08:00
|
|
|
#
|
|
|
|
# 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 09:07:00 +08:00
|
|
|
# distribution and at https://github.com/OpenRC/openrc/blob/HEAD/LICENSE
|
2015-12-05 06:52:19 +08:00
|
|
|
# This file may not be copied, modified, propagated, or distributed
|
|
|
|
# except according to the terms contained in the LICENSE file.
|
2015-05-12 07:07:28 +08:00
|
|
|
|
2015-05-14 03:47:35 +08:00
|
|
|
[ -z "${s6_service_path}" ] && s6_service_path="/var/svc.d/${RC_SVCNAME}"
|
2015-05-12 07:07:28 +08:00
|
|
|
|
2017-11-17 05:35:35 +08:00
|
|
|
_s6_force_kill() {
|
|
|
|
local pid
|
|
|
|
s6_service_link="${RC_SVCDIR}/s6-scan/${s6_service_path##*/}"
|
|
|
|
pid="${3%)}"
|
|
|
|
[ -z "${pid}" ] && return 0
|
|
|
|
if kill -0 "${pid}" 2> /dev/null; then
|
|
|
|
ewarn "Sending DOWN & KILL for ${RC_SVCNAME}"
|
|
|
|
s6-svc -dk "${s6_service_link}"
|
|
|
|
sleep 1
|
|
|
|
kill -0 "${pid}" 2>/dev/null && return 1
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2015-05-12 07:07:28 +08:00
|
|
|
s6_start()
|
|
|
|
{
|
|
|
|
if [ ! -d "${s6_service_path}" ]; then
|
|
|
|
eerror "${s6_service_path} does not exist."
|
|
|
|
return 1
|
|
|
|
fi
|
2015-05-14 03:47:35 +08:00
|
|
|
s6_service_link="${RC_SVCDIR}/s6-scan/${s6_service_path##*/}"
|
2015-05-12 07:07:28 +08:00
|
|
|
ebegin "Starting ${name:-$RC_SVCNAME}"
|
2015-05-14 03:47:35 +08:00
|
|
|
ln -sf "${s6_service_path}" "${s6_service_link}"
|
2015-05-15 03:26:52 +08:00
|
|
|
s6-svscanctl -na "${RC_SVCDIR}"/s6-scan
|
|
|
|
sleep 1.5
|
2015-05-14 03:47:35 +08:00
|
|
|
s6-svc -u "${s6_service_link}"
|
2015-05-12 07:07:28 +08:00
|
|
|
if [ -n "$s6_svwait_options_start" ]; then
|
2015-05-14 03:47:35 +08:00
|
|
|
s6-svwait ${s6_svwait_options_start} "${s6_service_link}"
|
2015-05-12 07:07:28 +08:00
|
|
|
fi
|
2015-05-14 03:47:35 +08:00
|
|
|
sleep 1.5
|
|
|
|
set -- $(s6-svstat "${s6_service_link}")
|
|
|
|
[ "$1" = "up" ]
|
2016-09-14 01:27:08 +08:00
|
|
|
eend $? "Failed to start ${name:-$RC_SVCNAME}"
|
2015-05-12 07:07:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
s6_stop()
|
|
|
|
{
|
|
|
|
if [ ! -d "${s6_service_path}" ]; then
|
|
|
|
eerror "${s6_service_path} does not exist."
|
|
|
|
return 1
|
|
|
|
fi
|
2015-05-14 03:47:35 +08:00
|
|
|
s6_service_link="${RC_SVCDIR}/s6-scan/${s6_service_path##*/}"
|
2015-05-12 07:07:28 +08:00
|
|
|
ebegin "Stopping ${name:-$RC_SVCNAME}"
|
2017-11-17 05:35:35 +08:00
|
|
|
s6-svc -d -wD -T ${s6_service_timeout_stop:-60000} "${s6_service_link}"
|
|
|
|
set -- $(s6-svstat "${s6_service_link}")
|
2018-10-13 06:16:23 +08:00
|
|
|
[ "$1" = "up" ] &&
|
2017-11-17 05:35:35 +08:00
|
|
|
yesno "${s6_force_kill:-yes}" &&
|
|
|
|
_s6_force_kill "$@"
|
2015-05-14 03:47:35 +08:00
|
|
|
set -- $(s6-svstat "${s6_service_link}")
|
2015-05-14 05:51:55 +08:00
|
|
|
[ "$1" = "down" ]
|
2016-09-14 01:27:08 +08:00
|
|
|
eend $? "Failed to stop ${name:-$RC_SVCNAME}"
|
2015-05-12 07:07:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
s6_status()
|
|
|
|
{
|
2015-05-14 03:47:35 +08:00
|
|
|
s6_service_link="${RC_SVCDIR}/s6-scan/${s6_service_path##*/}"
|
2015-05-14 05:51:55 +08:00
|
|
|
if [ -L "${s6_service_link}" ]; then
|
|
|
|
s6-svstat "${s6_service_link}"
|
|
|
|
else
|
|
|
|
_status
|
|
|
|
fi
|
2015-05-12 07:07:28 +08:00
|
|
|
}
|