gnu: Add ganeti.
[jackhill/guix/guix.git] / gnu / packages / patches / ganeti-shepherd-support.patch
1 Ganeti uses an internal tool to start/stop daemons during init and
2 upgrade. This patch makes the tool use native Shepherd facilities.
3
4 diff --git a/daemons/daemon-util.in b/daemons/daemon-util.in
5 --- a/daemons/daemon-util.in
6 +++ b/daemons/daemon-util.in
7 @@ -184,6 +184,21 @@ use_systemctl() {
8 return 1
9 }
10
11 +# Checks if we should use the Shepherd to start/stop daemons
12 +use_shepherd() {
13 + # Is Shepherd running as PID 1?
14 + ps --no-headers -p 1 -o cmd | grep -q shepherd || return 1
15 +
16 + type -p herd >/dev/null || return 1
17 +
18 + # Does Shepherd know about Ganeti at all?
19 + if herd status | grep -q ganeti; then
20 + return 0
21 + fi
22 +
23 + return 1
24 +}
25 +
26 # Prints path to PID file for a daemon.
27 daemon_pidfile() {
28 if [[ "$#" -lt 1 ]]; then
29 @@ -261,6 +276,13 @@ check() {
30 else
31 return 1
32 fi
33 + elif use_shepherd; then
34 + activestate="$(herd status ${name})"
35 + if echo $activestate | grep -q Running ; then
36 + return 0
37 + else
38 + return 1
39 + fi
40 elif type -p start-stop-daemon >/dev/null; then
41 start-stop-daemon --stop --signal 0 --quiet \
42 --pidfile $pidfile --name "$name"
43 @@ -291,6 +313,20 @@ start() {
44 return $?
45 fi
46
47 + if use_shepherd; then
48 + if herd status "$name" | grep -q "disabled"; then
49 + # The Shepherd will disable a service that has stopped, even if it exits
50 + # gracefully. Thus, we must re-enable it in case of a master failover.
51 + herd enable "${name}"
52 + fi
53 + # Note: unlike systemd, which happily starts a service and returns success
54 + # even if the daemon immediately exits, the Shepherd actually waits for it
55 + # to come up. Thus, ignore the exit status from 'herd start' in case of
56 + # master daemons running on the wrong node, or ganeti-kvmd disabled, etc.
57 + herd start "${name}"
58 + return 0
59 + fi
60 +
61 # Read $<daemon>_ARGS and $EXTRA_<daemon>_ARGS
62 eval local args="\"\$${ucname}_ARGS \$EXTRA_${ucname}_ARGS\""
63
64 @@ -336,6 +372,13 @@ stop() {
65
66 if use_systemctl; then
67 systemctl stop "${name}.service"
68 + elif use_shepherd; then
69 + if herd status | grep -q "$name"; then
70 + herd stop "$name"
71 + else
72 + # Do not raise an error if the service has not been enabled.
73 + return 0
74 + fi
75 elif type -p start-stop-daemon >/dev/null; then
76 start-stop-daemon --stop --quiet --oknodo --retry 30 \
77 --pidfile $pidfile --name "$name"
78 @@ -352,6 +395,9 @@ check_and_start() {
79 if use_systemctl; then
80 echo "${name} supervised by systemd but not running, will not restart."
81 return 1
82 + elif use_shepherd; then
83 + echo "${name} supervised by shepherd but not running, will not restart."
84 + return 1
85 fi
86
87 start $name