commit:     a428c325a902bba55a849a07a59c0c1567404db2
Author:     William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
AuthorDate: Wed Oct 25 20:07:19 2017 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Wed Oct 25 20:09:42 2017 +0000
URL:        https://gitweb.gentoo.org/proj/openrc.git/commit/?id=a428c325

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.

 sh/supervise-daemon.sh | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)

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
 }

Reply via email to