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