aboutsummaryrefslogtreecommitdiff
path: root/sh
diff options
context:
space:
mode:
authorWilliam Hubbs <w.d.hubbs@gmail.com>2017-10-25 15:07:19 -0500
committerWilliam Hubbs <w.d.hubbs@gmail.com>2017-10-25 15:09:42 -0500
commita428c325a902bba55a849a07a59c0c1567404db2 (patch)
treea97f08b6efd0538e7f2e7ee2059d737f2294eb94 /sh
parent3219ecd6085231d7cc1268323a5be6a69f8c9143 (diff)
add "unsupervised" status and return code 64 to supervise-daemon status function
This is to be used if the service is being supervised and the supervisor is somehow killed. Currently, this is very linux specific, but I will expand to other platforms, patches are welcome.
Diffstat (limited to 'sh')
-rw-r--r--sh/supervise-daemon.sh45
1 files changed, 44 insertions, 1 deletions
diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh
index 1c1b840d..bccfd06a 100644
--- a/sh/supervise-daemon.sh
+++ b/sh/supervise-daemon.sh
@@ -56,7 +56,50 @@ supervise_stop()
eend $? "Failed to stop ${name:-$RC_SVCNAME}"
}
+_check_supervised()
+{
+ [ "$RC_UNAME" != Linux ] && return 0
+ local child_pid="$(service_get_value "child_pid")"
+ local pid="$(cat ${pidfile})"
+ if [ -n "${child_pid}" ]; then
+ if ! [ -e "/proc/${pid}" ] && [ -e "/proc/${child_pid}" ]; then
+ if [ -e "/proc/self/ns/pid" ] && [ -e "/proc/${child_pid}/ns/pid" ]; then
+ local n1 n2
+ n1=$(readlink "/proc/self/ns/pid")
+ n2=$(readlink "/proc/${child_pid}/ns/pid")
+ if [ "${n1}" = "${n2}" ]; then
+ return 1
+ fi
+ fi
+ fi
+ fi
+ return 0
+}
+
supervise_status()
{
- _status
+ 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
}