root / doc / examples / ganeti.initd.in @ e91cfc2a
History | View | Annotate | Download (2.5 kB)
1 | c1671c0e | Michael Hanselmann | #!/bin/sh |
---|---|---|---|
2 | a8083063 | Iustin Pop | # ganeti node daemon starter 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 | 82cd7760 | Iustin Pop | NODED="ganeti-noded" |
18 | 82cd7760 | Iustin Pop | MASTERD="ganeti-masterd" |
19 | 5c566e17 | Michael Hanselmann | CONFD="ganeti-confd" |
20 | 82cd7760 | Iustin Pop | RAPI="ganeti-rapi" |
21 | f154a7a3 | Michael Hanselmann | |
22 | f154a7a3 | Michael Hanselmann | DAEMON_UTIL=@PKGLIBDIR@/daemon-util |
23 | b1b6ea87 | Iustin Pop | |
24 | b1b6ea87 | Iustin Pop | SCRIPTNAME="@SYSCONFDIR@/init.d/ganeti" |
25 | a8083063 | Iustin Pop | |
26 | 82cd7760 | Iustin Pop | test -f "@PREFIX@/sbin/$NODED" || exit 0 |
27 | a8083063 | Iustin Pop | |
28 | a8083063 | Iustin Pop | . /lib/lsb/init-functions |
29 | a8083063 | Iustin Pop | |
30 | a8083063 | Iustin Pop | check_config() { |
31 | c1671c0e | Michael Hanselmann | for fname in \ |
32 | c1671c0e | Michael Hanselmann | "@LOCALSTATEDIR@/lib/ganeti/server.pem" |
33 | c1671c0e | Michael Hanselmann | do |
34 | 3c9a0742 | Michael Hanselmann | if ! [ -f "$fname" ]; then |
35 | 3c9a0742 | Michael Hanselmann | log_end_msg 0 |
36 | 3c9a0742 | Michael Hanselmann | log_warning_msg "Config $fname not there, will not run." |
37 | 3c9a0742 | Michael Hanselmann | exit 0 |
38 | 3c9a0742 | Michael Hanselmann | fi |
39 | 3c9a0742 | Michael Hanselmann | done |
40 | a8083063 | Iustin Pop | } |
41 | a8083063 | Iustin Pop | |
42 | b1b6ea87 | Iustin Pop | check_exitcode() { |
43 | b1b6ea87 | Iustin Pop | RC=$1 |
44 | 9bd7f742 | Iustin Pop | case $RC in |
45 | 9bd7f742 | Iustin Pop | 0) |
46 | 9bd7f742 | Iustin Pop | log_action_end_msg 0 |
47 | 9bd7f742 | Iustin Pop | ;; |
48 | 9bd7f742 | Iustin Pop | 11) |
49 | 9bd7f742 | Iustin Pop | log_action_end_msg 0 "not master" |
50 | 9bd7f742 | Iustin Pop | ;; |
51 | 9bd7f742 | Iustin Pop | *) |
52 | 9bd7f742 | Iustin Pop | log_action_end_msg 1 "exit code $RC" |
53 | 9bd7f742 | Iustin Pop | ;; |
54 | 9bd7f742 | Iustin Pop | esac |
55 | 9bd7f742 | Iustin Pop | } |
56 | 9bd7f742 | Iustin Pop | |
57 | b1b6ea87 | Iustin Pop | start_action() { |
58 | 82cd7760 | Iustin Pop | # called as start_action daemon-name |
59 | f154a7a3 | Michael Hanselmann | local daemon="$1" |
60 | e10a3aea | Iustin Pop | log_action_begin_msg "$daemon" |
61 | f154a7a3 | Michael Hanselmann | $DAEMON_UTIL start "$@" |
62 | b1b6ea87 | Iustin Pop | check_exitcode $? |
63 | b1b6ea87 | Iustin Pop | } |
64 | b1b6ea87 | Iustin Pop | |
65 | b1b6ea87 | Iustin Pop | stop_action() { |
66 | 82cd7760 | Iustin Pop | # called as stop_action daemon-name |
67 | 82cd7760 | Iustin Pop | local daemon="$1" |
68 | 82cd7760 | Iustin Pop | log_action_begin_msg "$daemon" |
69 | f154a7a3 | Michael Hanselmann | $DAEMON_UTIL stop "$@" |
70 | b1b6ea87 | Iustin Pop | check_exitcode $? |
71 | b1b6ea87 | Iustin Pop | } |
72 | b1b6ea87 | Iustin Pop | |
73 | 82cd7760 | Iustin Pop | maybe_do() { |
74 | 82cd7760 | Iustin Pop | requested="$1"; shift |
75 | 82cd7760 | Iustin Pop | action="$1"; shift |
76 | 82cd7760 | Iustin Pop | target="$1" |
77 | 82cd7760 | Iustin Pop | if [ -z "$requested" -o "$requested" = "$target" ]; then |
78 | 82cd7760 | Iustin Pop | $action "$@" |
79 | 82cd7760 | Iustin Pop | fi |
80 | 82cd7760 | Iustin Pop | } |
81 | 82cd7760 | Iustin Pop | |
82 | f154a7a3 | Michael Hanselmann | start_all() { |
83 | f154a7a3 | Michael Hanselmann | check_config |
84 | f154a7a3 | Michael Hanselmann | for i in $NODED $MASTERD $CONFD $RAPI; do \ |
85 | bd14a6ac | Iustin Pop | maybe_do "$1" start_action $i |
86 | f154a7a3 | Michael Hanselmann | done |
87 | f154a7a3 | Michael Hanselmann | } |
88 | f154a7a3 | Michael Hanselmann | |
89 | f154a7a3 | Michael Hanselmann | stop_all() { |
90 | f154a7a3 | Michael Hanselmann | for i in $RAPI $CONFD $MASTERD $NODED; do \ |
91 | f154a7a3 | Michael Hanselmann | maybe_do "$1" stop_action $i |
92 | f154a7a3 | Michael Hanselmann | done |
93 | f154a7a3 | Michael Hanselmann | } |
94 | f154a7a3 | Michael Hanselmann | |
95 | 82cd7760 | Iustin Pop | if [ -n "$2" -a \ |
96 | 82cd7760 | Iustin Pop | "$2" != "$NODED" -a \ |
97 | e58b56ad | Guido Trotter | "$2" != "$CONFD" -a \ |
98 | 82cd7760 | Iustin Pop | "$2" != "$MASTERD" -a \ |
99 | 82cd7760 | Iustin Pop | "$2" != "$RAPI" ]; then |
100 | 82cd7760 | Iustin Pop | log_failure_msg "Unknown daemon '$2' requested" |
101 | 82cd7760 | Iustin Pop | exit 1 |
102 | 82cd7760 | Iustin Pop | fi |
103 | b1b6ea87 | Iustin Pop | |
104 | a8083063 | Iustin Pop | case "$1" in |
105 | 3c9a0742 | Michael Hanselmann | start) |
106 | 82cd7760 | Iustin Pop | log_daemon_msg "Starting $DESC" "$2" |
107 | f154a7a3 | Michael Hanselmann | start_all "$2" |
108 | 84d6ea9b | Guido Trotter | ;; |
109 | 3c9a0742 | Michael Hanselmann | stop) |
110 | 82cd7760 | Iustin Pop | log_daemon_msg "Stopping $DESC" "$2" |
111 | f154a7a3 | Michael Hanselmann | stop_all "$2" |
112 | 84d6ea9b | Guido Trotter | ;; |
113 | 3c9a0742 | Michael Hanselmann | restart|force-reload) |
114 | f154a7a3 | Michael Hanselmann | stop_all "$2" |
115 | f154a7a3 | Michael Hanselmann | start_all "$2" |
116 | 84d6ea9b | Guido Trotter | ;; |
117 | 3c9a0742 | Michael Hanselmann | *) |
118 | 3c9a0742 | Michael Hanselmann | log_success_msg "Usage: $SCRIPTNAME {start|stop|force-reload|restart}" |
119 | 3c9a0742 | Michael Hanselmann | exit 1 |
120 | 84d6ea9b | Guido Trotter | ;; |
121 | a8083063 | Iustin Pop | esac |
122 | a8083063 | Iustin Pop | |
123 | a8083063 | Iustin Pop | exit 0 |