2015-05-12 04:37:28 +05:30
|
|
|
# Start / stop / status functions for s6 support
|
2015-12-05 04:22:19 +05:30
|
|
|
|
|
|
|
# Copyright (c) 2015 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.
|
2015-05-12 04:37:28 +05:30
|
|
|
|
2015-05-14 01:17:35 +05:30
|
|
|
[ -z "${s6_service_path}" ] && s6_service_path="/var/svc.d/${RC_SVCNAME}"
|
2015-05-12 04:37:28 +05:30
|
|
|
|
2017-11-17 03:05:35 +05:30
|
|
|
_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 04:37:28 +05:30
|
|
|
s6_start()
|
|
|
|
{
|
|
|
|
if [ ! -d "${s6_service_path}" ]; then
|
|
|
|
eerror "${s6_service_path} does not exist."
|
|
|
|
return 1
|
|
|
|
fi
|
2015-05-14 01:17:35 +05:30
|
|
|
s6_service_link="${RC_SVCDIR}/s6-scan/${s6_service_path##*/}"
|
2015-05-12 04:37:28 +05:30
|
|
|
ebegin "Starting ${name:-$RC_SVCNAME}"
|
2015-05-14 01:17:35 +05:30
|
|
|
ln -sf "${s6_service_path}" "${s6_service_link}"
|
2015-05-15 00:56:52 +05:30
|
|
|
s6-svscanctl -na "${RC_SVCDIR}"/s6-scan
|
|
|
|
sleep 1.5
|
2015-05-14 01:17:35 +05:30
|
|
|
s6-svc -u "${s6_service_link}"
|
2015-05-12 04:37:28 +05:30
|
|
|
if [ -n "$s6_svwait_options_start" ]; then
|
2015-05-14 01:17:35 +05:30
|
|
|
s6-svwait ${s6_svwait_options_start} "${s6_service_link}"
|
2015-05-12 04:37:28 +05:30
|
|
|
fi
|
2015-05-14 01:17:35 +05:30
|
|
|
sleep 1.5
|
|
|
|
set -- $(s6-svstat "${s6_service_link}")
|
|
|
|
[ "$1" = "up" ]
|
2016-09-13 22:57:08 +05:30
|
|
|
eend $? "Failed to start ${name:-$RC_SVCNAME}"
|
2015-05-12 04:37:28 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
s6_stop()
|
|
|
|
{
|
|
|
|
if [ ! -d "${s6_service_path}" ]; then
|
|
|
|
eerror "${s6_service_path} does not exist."
|
|
|
|
return 1
|
|
|
|
fi
|
2015-05-14 01:17:35 +05:30
|
|
|
s6_service_link="${RC_SVCDIR}/s6-scan/${s6_service_path##*/}"
|
2015-05-12 04:37:28 +05:30
|
|
|
ebegin "Stopping ${name:-$RC_SVCNAME}"
|
2017-11-17 03:05:35 +05:30
|
|
|
s6-svc -d -wD -T ${s6_service_timeout_stop:-60000} "${s6_service_link}"
|
|
|
|
set -- $(s6-svstat "${s6_service_link}")
|
|
|
|
[ "$1" = "up" ] &&
|
|
|
|
yesno "${s6_force_kill:-yes}" &&
|
|
|
|
_s6_force_kill "$@"
|
2015-05-14 01:17:35 +05:30
|
|
|
set -- $(s6-svstat "${s6_service_link}")
|
2015-05-14 03:21:55 +05:30
|
|
|
[ "$1" = "down" ]
|
2016-09-13 22:57:08 +05:30
|
|
|
eend $? "Failed to stop ${name:-$RC_SVCNAME}"
|
2015-05-12 04:37:28 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
s6_status()
|
|
|
|
{
|
2015-05-14 01:17:35 +05:30
|
|
|
s6_service_link="${RC_SVCDIR}/s6-scan/${s6_service_path##*/}"
|
2015-05-14 03:21:55 +05:30
|
|
|
if [ -L "${s6_service_link}" ]; then
|
|
|
|
s6-svstat "${s6_service_link}"
|
|
|
|
else
|
|
|
|
_status
|
|
|
|
fi
|
2015-05-12 04:37:28 +05:30
|
|
|
}
|