ganeti.initd: include defaults file, if present
[ganeti-local] / doc / examples / ganeti.initd.in
1 #!/bin/sh
2 # ganeti node daemon starter script
3 # based on skeleton from Debian GNU/Linux
4 ### BEGIN INIT INFO
5 # Provides:          ganeti
6 # Required-Start:    $syslog $remote_fs xend
7 # Required-Stop:     $syslog $remote_fs xend
8 # Default-Start:     2 3 4 5
9 # Default-Stop:      0 1 6
10 # Short-Description: Ganeti Xen Cluster Manager
11 # Description:       Ganeti Xen Cluster Manager
12 ### END INIT INFO
13
14 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
15 DESC="Ganeti cluster"
16
17 GANETIRUNDIR="@LOCALSTATEDIR@/run/ganeti"
18
19 GANETI_DEFAULTS_FILE="@SYSCONFDIR@/default/ganeti"
20
21 NODED_NAME="ganeti-noded"
22 NODED="@PREFIX@/sbin/${NODED_NAME}"
23 NODED_PID="${GANETIRUNDIR}/${NODED_NAME}.pid"
24
25 MASTERD_NAME="ganeti-masterd"
26 MASTERD="@PREFIX@/sbin/${MASTERD_NAME}"
27 MASTERD_PID="${GANETIRUNDIR}/${MASTERD_NAME}.pid"
28
29 RAPI_NAME="ganeti-rapi"
30 RAPI="@PREFIX@/sbin/${RAPI_NAME}"
31 RAPI_PID="${GANETIRUNDIR}/${RAPI_NAME}.pid"
32
33 SCRIPTNAME="@SYSCONFDIR@/init.d/ganeti"
34
35 test -f $NODED || exit 0
36
37 . /lib/lsb/init-functions
38
39 if [ -s $GANETI_DEFAULTS_FILE ]; then
40     . $GANETI_DEFAULTS_FILE
41 fi
42
43 check_config() {
44     for fname in \
45         "@LOCALSTATEDIR@/lib/ganeti/server.pem"
46     do
47         if ! [ -f "$fname" ]; then
48             log_end_msg 0
49             log_warning_msg "Config $fname not there, will not run."
50             exit 0
51         fi
52     done
53 }
54
55 check_exitcode() {
56     RC=$1
57     case $RC in
58         0)
59             log_action_end_msg 0
60             ;;
61         11)
62             log_action_end_msg 0 "not master"
63             ;;
64         *)
65             log_action_end_msg 1 "exit code $RC"
66             ;;
67     esac
68 }
69
70 start_action() {
71     # called as start_action daemon pidfile
72     local daemon="$1"; shift
73     local pidfile="$1"; shift
74     log_action_begin_msg "$daemon"
75     start-stop-daemon --start --quiet --exec "$daemon" --pidfile "$pidfile" \
76         -- "$@"
77     check_exitcode $?
78 }
79
80 stop_action() {
81     # called as stop_action daemon pidfile
82     log_action_begin_msg "$1"
83     start-stop-daemon --stop --quiet --oknodo \
84         --retry 30 --pidfile "$2"
85     check_exitcode $?
86 }
87
88
89 case "$1" in
90     start)
91         log_daemon_msg "Starting $DESC" "$NAME"
92         check_config
93         start_action $NODED $NODED_PID
94         start_action $MASTERD $MASTERD_PID
95         start_action $RAPI $RAPI_PID
96         ;;
97     stop)
98         log_daemon_msg "Stopping $DESC" "$NAME"
99         stop_action $RAPI $RAPI_PID
100         stop_action $MASTERD $MASTERD_PID
101         stop_action $NODED $NODED_PID
102         ;;
103     restart|force-reload)
104         log_daemon_msg "Reloading $DESC"
105         stop_action $RAPI $RAPI_PID
106         stop_action $MASTERD $MASTERD_PID
107         stop_action $NODED $NODED_PID
108         check_config
109         start_action $NODED $NODED_PID
110         start_action $MASTERD $MASTERD_PID
111         start_action $RAPI $RAPI_PID
112         ;;
113     *)
114         log_success_msg "Usage: $SCRIPTNAME {start|stop|force-reload|restart}"
115         exit 1
116         ;;
117 esac
118
119 exit 0