root / doc / examples / ganeti.initd.in @ cd30f3e6
History | View | Annotate | Download (2.8 kB)
1 | c1671c0e | Michael Hanselmann | #!/bin/sh |
---|---|---|---|
2 | 45e22998 | Guido Trotter | # ganeti daemons init script |
3 | 47834a4f | René Nussbaumer | # |
4 | 47834a4f | René Nussbaumer | # chkconfig: 2345 99 01 |
5 | 47834a4f | René Nussbaumer | # description: Ganeti Cluster Manager |
6 | 24d48647 | Guido Trotter | ### BEGIN INIT INFO |
7 | 24d48647 | Guido Trotter | # Provides: ganeti |
8 | a02b4427 | Iustin Pop | # Required-Start: $syslog $remote_fs |
9 | a02b4427 | Iustin Pop | # Required-Stop: $syslog $remote_fs |
10 | 24d48647 | Guido Trotter | # Default-Start: 2 3 4 5 |
11 | e71d6323 | Iustin Pop | # Default-Stop: 0 1 6 |
12 | a02b4427 | Iustin Pop | # Short-Description: Ganeti Cluster Manager |
13 | a02b4427 | Iustin Pop | # Description: Ganeti Cluster Manager |
14 | 24d48647 | Guido Trotter | ### END INIT INFO |
15 | a8083063 | Iustin Pop | |
16 | 880478f8 | Iustin Pop | PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin |
17 | 9bd7f742 | Iustin Pop | DESC="Ganeti cluster" |
18 | b1b6ea87 | Iustin Pop | |
19 | f154a7a3 | Michael Hanselmann | DAEMON_UTIL=@PKGLIBDIR@/daemon-util |
20 | b1b6ea87 | Iustin Pop | |
21 | b1b6ea87 | Iustin Pop | SCRIPTNAME="@SYSCONFDIR@/init.d/ganeti" |
22 | a8083063 | Iustin Pop | |
23 | 5d8acbdd | Michael Hanselmann | test -f "$DAEMON_UTIL" || exit 0 |
24 | a8083063 | Iustin Pop | |
25 | 47834a4f | René Nussbaumer | if [ -r /lib/lsb/init-functions ]; then |
26 | 47834a4f | René Nussbaumer | . /lib/lsb/init-functions |
27 | 47834a4f | René Nussbaumer | elif [ -r /etc/rc.d/init.d/functions ]; then |
28 | 47834a4f | René Nussbaumer | . /etc/rc.d/init.d/functions |
29 | 47834a4f | René Nussbaumer | else |
30 | 47834a4f | René Nussbaumer | echo "Unable to find init functions" |
31 | 47834a4f | René Nussbaumer | exit 1 |
32 | 47834a4f | René Nussbaumer | fi |
33 | a8083063 | Iustin Pop | |
34 | b1b6ea87 | Iustin Pop | check_exitcode() { |
35 | b1b6ea87 | Iustin Pop | RC=$1 |
36 | 10c5c1c3 | Michael Hanselmann | |
37 | 10c5c1c3 | Michael Hanselmann | if errmsg=$($DAEMON_UTIL check-exitcode $RC) |
38 | 10c5c1c3 | Michael Hanselmann | then |
39 | 10c5c1c3 | Michael Hanselmann | log_action_end_msg 0 "$errmsg" |
40 | 10c5c1c3 | Michael Hanselmann | else |
41 | 10c5c1c3 | Michael Hanselmann | log_action_end_msg 1 "$errmsg" |
42 | 10c5c1c3 | Michael Hanselmann | fi |
43 | 9bd7f742 | Iustin Pop | } |
44 | 9bd7f742 | Iustin Pop | |
45 | b1b6ea87 | Iustin Pop | start_action() { |
46 | 82cd7760 | Iustin Pop | # called as start_action daemon-name |
47 | f154a7a3 | Michael Hanselmann | local daemon="$1" |
48 | e10a3aea | Iustin Pop | log_action_begin_msg "$daemon" |
49 | f154a7a3 | Michael Hanselmann | $DAEMON_UTIL start "$@" |
50 | b1b6ea87 | Iustin Pop | check_exitcode $? |
51 | b1b6ea87 | Iustin Pop | } |
52 | b1b6ea87 | Iustin Pop | |
53 | b1b6ea87 | Iustin Pop | stop_action() { |
54 | 82cd7760 | Iustin Pop | # called as stop_action daemon-name |
55 | 82cd7760 | Iustin Pop | local daemon="$1" |
56 | 82cd7760 | Iustin Pop | log_action_begin_msg "$daemon" |
57 | f154a7a3 | Michael Hanselmann | $DAEMON_UTIL stop "$@" |
58 | b1b6ea87 | Iustin Pop | check_exitcode $? |
59 | b1b6ea87 | Iustin Pop | } |
60 | b1b6ea87 | Iustin Pop | |
61 | 82cd7760 | Iustin Pop | maybe_do() { |
62 | 82cd7760 | Iustin Pop | requested="$1"; shift |
63 | 82cd7760 | Iustin Pop | action="$1"; shift |
64 | 82cd7760 | Iustin Pop | target="$1" |
65 | 82cd7760 | Iustin Pop | if [ -z "$requested" -o "$requested" = "$target" ]; then |
66 | 82cd7760 | Iustin Pop | $action "$@" |
67 | 82cd7760 | Iustin Pop | fi |
68 | 82cd7760 | Iustin Pop | } |
69 | 82cd7760 | Iustin Pop | |
70 | f154a7a3 | Michael Hanselmann | start_all() { |
71 | d2baa21d | Michael Hanselmann | if ! $DAEMON_UTIL check-config; then |
72 | d2baa21d | Michael Hanselmann | log_warning_msg "Incomplete configuration, will not run." |
73 | d2baa21d | Michael Hanselmann | exit 0 |
74 | d2baa21d | Michael Hanselmann | fi |
75 | d2baa21d | Michael Hanselmann | |
76 | 5d8acbdd | Michael Hanselmann | for i in $($DAEMON_UTIL list-start-daemons); do |
77 | bd14a6ac | Iustin Pop | maybe_do "$1" start_action $i |
78 | f154a7a3 | Michael Hanselmann | done |
79 | f154a7a3 | Michael Hanselmann | } |
80 | f154a7a3 | Michael Hanselmann | |
81 | f154a7a3 | Michael Hanselmann | stop_all() { |
82 | 5d8acbdd | Michael Hanselmann | for i in $($DAEMON_UTIL list-stop-daemons); do |
83 | f154a7a3 | Michael Hanselmann | maybe_do "$1" stop_action $i |
84 | f154a7a3 | Michael Hanselmann | done |
85 | f154a7a3 | Michael Hanselmann | } |
86 | f154a7a3 | Michael Hanselmann | |
87 | 8e2ed2e8 | Michael Hanselmann | status_all() { |
88 | 8e2ed2e8 | Michael Hanselmann | local daemons="$1" status ret |
89 | 8e2ed2e8 | Michael Hanselmann | |
90 | 8e2ed2e8 | Michael Hanselmann | if [ -z "$daemons" ]; then |
91 | 8e2ed2e8 | Michael Hanselmann | daemons=$($DAEMON_UTIL list-start-daemons) |
92 | 8e2ed2e8 | Michael Hanselmann | fi |
93 | 8e2ed2e8 | Michael Hanselmann | |
94 | 8e2ed2e8 | Michael Hanselmann | status=0 |
95 | 8e2ed2e8 | Michael Hanselmann | |
96 | 8e2ed2e8 | Michael Hanselmann | for i in $daemons; do |
97 | 8e2ed2e8 | Michael Hanselmann | if status_of_proc $($DAEMON_UTIL daemon-executable $i) $i; then |
98 | 8e2ed2e8 | Michael Hanselmann | ret=0 |
99 | 8e2ed2e8 | Michael Hanselmann | else |
100 | 8e2ed2e8 | Michael Hanselmann | ret=$? |
101 | 8e2ed2e8 | Michael Hanselmann | # Use exit code from first failed call |
102 | 8e2ed2e8 | Michael Hanselmann | if [ "$status" -eq 0 ]; then |
103 | 8e2ed2e8 | Michael Hanselmann | status=$ret |
104 | 8e2ed2e8 | Michael Hanselmann | fi |
105 | 8e2ed2e8 | Michael Hanselmann | fi |
106 | 8e2ed2e8 | Michael Hanselmann | done |
107 | 8e2ed2e8 | Michael Hanselmann | |
108 | 8e2ed2e8 | Michael Hanselmann | exit $status |
109 | 8e2ed2e8 | Michael Hanselmann | } |
110 | 8e2ed2e8 | Michael Hanselmann | |
111 | 5d8acbdd | Michael Hanselmann | if [ -n "$2" ] && ! errmsg=$($DAEMON_UTIL is-daemon-name "$2" 2>&1); then |
112 | 5d8acbdd | Michael Hanselmann | log_failure_msg "$errmsg" |
113 | 82cd7760 | Iustin Pop | exit 1 |
114 | 82cd7760 | Iustin Pop | fi |
115 | b1b6ea87 | Iustin Pop | |
116 | a8083063 | Iustin Pop | case "$1" in |
117 | 3c9a0742 | Michael Hanselmann | start) |
118 | 82cd7760 | Iustin Pop | log_daemon_msg "Starting $DESC" "$2" |
119 | f154a7a3 | Michael Hanselmann | start_all "$2" |
120 | 84d6ea9b | Guido Trotter | ;; |
121 | 3c9a0742 | Michael Hanselmann | stop) |
122 | 82cd7760 | Iustin Pop | log_daemon_msg "Stopping $DESC" "$2" |
123 | f154a7a3 | Michael Hanselmann | stop_all "$2" |
124 | 84d6ea9b | Guido Trotter | ;; |
125 | 3c9a0742 | Michael Hanselmann | restart|force-reload) |
126 | d2baa21d | Michael Hanselmann | log_daemon_msg "Restarting $DESC" "$2" |
127 | f154a7a3 | Michael Hanselmann | stop_all "$2" |
128 | f154a7a3 | Michael Hanselmann | start_all "$2" |
129 | 84d6ea9b | Guido Trotter | ;; |
130 | 8e2ed2e8 | Michael Hanselmann | status) |
131 | 8e2ed2e8 | Michael Hanselmann | status_all "$2" |
132 | 8e2ed2e8 | Michael Hanselmann | ;; |
133 | 3c9a0742 | Michael Hanselmann | *) |
134 | 3c9a0742 | Michael Hanselmann | log_success_msg "Usage: $SCRIPTNAME {start|stop|force-reload|restart}" |
135 | 3c9a0742 | Michael Hanselmann | exit 1 |
136 | 84d6ea9b | Guido Trotter | ;; |
137 | a8083063 | Iustin Pop | esac |
138 | a8083063 | Iustin Pop | |
139 | a8083063 | Iustin Pop | exit 0 |