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