1 |
commit: a428c325a902bba55a849a07a59c0c1567404db2 |
2 |
Author: William Hubbs <w.d.hubbs <AT> gmail <DOT> com> |
3 |
AuthorDate: Wed Oct 25 20:07:19 2017 +0000 |
4 |
Commit: William Hubbs <williamh <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Oct 25 20:09:42 2017 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/openrc.git/commit/?id=a428c325 |
7 |
|
8 |
add "unsupervised" status and return code 64 to supervise-daemon status function |
9 |
|
10 |
This is to be used if the service is being supervised and the |
11 |
supervisor is somehow killed. |
12 |
|
13 |
Currently, this is very linux specific, but I will expand to other |
14 |
platforms, patches are welcome. |
15 |
|
16 |
sh/supervise-daemon.sh | 45 ++++++++++++++++++++++++++++++++++++++++++++- |
17 |
1 file changed, 44 insertions(+), 1 deletion(-) |
18 |
|
19 |
diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh |
20 |
index 1c1b840d..bccfd06a 100644 |
21 |
--- a/sh/supervise-daemon.sh |
22 |
+++ b/sh/supervise-daemon.sh |
23 |
@@ -56,7 +56,50 @@ supervise_stop() |
24 |
eend $? "Failed to stop ${name:-$RC_SVCNAME}" |
25 |
} |
26 |
|
27 |
+_check_supervised() |
28 |
+{ |
29 |
+ [ "$RC_UNAME" != Linux ] && return 0 |
30 |
+ local child_pid="$(service_get_value "child_pid")" |
31 |
+ local pid="$(cat ${pidfile})" |
32 |
+ if [ -n "${child_pid}" ]; then |
33 |
+ if ! [ -e "/proc/${pid}" ] && [ -e "/proc/${child_pid}" ]; then |
34 |
+ if [ -e "/proc/self/ns/pid" ] && [ -e "/proc/${child_pid}/ns/pid" ]; then |
35 |
+ local n1 n2 |
36 |
+ n1=$(readlink "/proc/self/ns/pid") |
37 |
+ n2=$(readlink "/proc/${child_pid}/ns/pid") |
38 |
+ if [ "${n1}" = "${n2}" ]; then |
39 |
+ return 1 |
40 |
+ fi |
41 |
+ fi |
42 |
+ fi |
43 |
+ fi |
44 |
+ return 0 |
45 |
+} |
46 |
+ |
47 |
supervise_status() |
48 |
{ |
49 |
- _status |
50 |
+ if service_stopping; then |
51 |
+ ewarn "status: stopping" |
52 |
+ return 4 |
53 |
+ elif service_starting; then |
54 |
+ ewarn "status: starting" |
55 |
+ return 8 |
56 |
+ elif service_inactive; then |
57 |
+ ewarn "status: inactive" |
58 |
+ return 16 |
59 |
+ elif service_started; then |
60 |
+ if service_crashed; then |
61 |
+ if ! _check_supervised; then |
62 |
+ eerror "status: unsupervised" |
63 |
+ return 64 |
64 |
+ fi |
65 |
+ eerror "status: crashed" |
66 |
+ return 32 |
67 |
+ fi |
68 |
+ einfo "status: started" |
69 |
+ return 0 |
70 |
+ else |
71 |
+ einfo "status: stopped" |
72 |
+ return 3 |
73 |
+ fi |
74 |
} |