init script: handle ganeti-confd as well
[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 NODED_ARGS=""
25
26 MASTERD_NAME="ganeti-masterd"
27 MASTERD="@PREFIX@/sbin/${MASTERD_NAME}"
28 MASTERD_PID="${GANETIRUNDIR}/${MASTERD_NAME}.pid"
29 MASTERD_ARGS=""
30
31 CONFD_NAME="ganeti-confd"
32 CONFD="@PREFIX@/sbin/${CONFD_NAME}"
33 CONFD_PID="${GANETIRUNDIR}/${CONFD_NAME}.pid"
34 CONFD_ARGS=""
35
36 RAPI_NAME="ganeti-rapi"
37 RAPI="@PREFIX@/sbin/${RAPI_NAME}"
38 RAPI_PID="${GANETIRUNDIR}/${RAPI_NAME}.pid"
39 RAPI_ARGS=""
40
41 SCRIPTNAME="@SYSCONFDIR@/init.d/ganeti"
42
43 test -f $NODED || exit 0
44
45 . /lib/lsb/init-functions
46
47 if [ -s $GANETI_DEFAULTS_FILE ]; then
48     . $GANETI_DEFAULTS_FILE
49 fi
50
51 check_config() {
52     for fname in \
53         "@LOCALSTATEDIR@/lib/ganeti/server.pem"
54     do
55         if ! [ -f "$fname" ]; then
56             log_end_msg 0
57             log_warning_msg "Config $fname not there, will not run."
58             exit 0
59         fi
60     done
61 }
62
63 check_exitcode() {
64     RC=$1
65     case $RC in
66         0)
67             log_action_end_msg 0
68             ;;
69         11)
70             log_action_end_msg 0 "not master"
71             ;;
72         *)
73             log_action_end_msg 1 "exit code $RC"
74             ;;
75     esac
76 }
77
78 start_action() {
79     # called as start_action daemon pidfile
80     local daemon="$1"; shift
81     local pidfile="$1"; shift
82     log_action_begin_msg "$daemon"
83     start-stop-daemon --start --quiet --exec "$daemon" --pidfile "$pidfile" \
84         -- "$@"
85     check_exitcode $?
86 }
87
88 stop_action() {
89     # called as stop_action daemon pidfile
90     log_action_begin_msg "$1"
91     start-stop-daemon --stop --quiet --oknodo \
92         --retry 30 --pidfile "$2"
93     check_exitcode $?
94 }
95
96
97 case "$1" in
98     start)
99         log_daemon_msg "Starting $DESC" "$NAME"
100         check_config
101         start_action $NODED $NODED_PID $NODED_ARGS
102         start_action $MASTERD $MASTERD_PID $MASTERD_ARGS
103         start_action $CONFD $CONFD_PID $CONFD_ARGS
104         start_action $RAPI $RAPI_PID $RAPI_ARGS
105         ;;
106     stop)
107         log_daemon_msg "Stopping $DESC" "$NAME"
108         stop_action $RAPI $RAPI_PID
109         stop_action $MASTERD $MASTERD_PID
110         stop_action $CONFD $CONFD_PID
111         stop_action $NODED $NODED_PID
112         ;;
113     restart|force-reload)
114         log_daemon_msg "Reloading $DESC"
115         stop_action $RAPI $RAPI_PID
116         stop_action $MASTERD $MASTERD_PID
117         stop_action $CONFD $CONFD_PID
118         stop_action $NODED $NODED_PID
119         check_config
120         start_action $NODED $NODED_PID $NODED_ARGS
121         start_action $MASTERD $MASTERD_PID $MASTERD_ARGS
122         start_action $CONFD $CONFD_PID $CONFD_ARGS
123         start_action $RAPI $RAPI_PID $RAPI_ARGS
124         ;;
125     *)
126         log_success_msg "Usage: $SCRIPTNAME {start|stop|force-reload|restart}"
127         exit 1
128         ;;
129 esac
130
131 exit 0