Statistics
| Branch: | Tag: | Revision:

root / doc / examples / ganeti.initd.in @ 84d6ea9b

History | View | Annotate | Download (2.8 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 24d48647 Guido Trotter
# Required-Start:    $syslog $remote_fs xend
7 24d48647 Guido Trotter
# Required-Stop:     $syslog $remote_fs xend
8 24d48647 Guido Trotter
# Default-Start:     2 3 4 5
9 e71d6323 Iustin Pop
# Default-Stop:      0 1 6
10 24d48647 Guido Trotter
# Short-Description: Ganeti Xen Cluster Manager
11 e71d6323 Iustin Pop
# Description:       Ganeti Xen 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 5947d6ec Guido Trotter
GANETIRUNDIR="@LOCALSTATEDIR@/run/ganeti"
18 b1b6ea87 Iustin Pop
19 b1b6ea87 Iustin Pop
NODED_NAME="ganeti-noded"
20 b1b6ea87 Iustin Pop
NODED="@PREFIX@/sbin/${NODED_NAME}"
21 b1b6ea87 Iustin Pop
NODED_PID="${GANETIRUNDIR}/${NODED_NAME}.pid"
22 b1b6ea87 Iustin Pop
23 b1b6ea87 Iustin Pop
MASTERD_NAME="ganeti-masterd"
24 b1b6ea87 Iustin Pop
MASTERD="@PREFIX@/sbin/${MASTERD_NAME}"
25 b1b6ea87 Iustin Pop
MASTERD_PID="${GANETIRUNDIR}/${MASTERD_NAME}.pid"
26 b1b6ea87 Iustin Pop
27 b1b6ea87 Iustin Pop
RAPI_NAME="ganeti-rapi"
28 b1b6ea87 Iustin Pop
RAPI="@PREFIX@/sbin/${RAPI_NAME}"
29 b1b6ea87 Iustin Pop
RAPI_PID="${GANETIRUNDIR}/${RAPI_NAME}.pid"
30 b1b6ea87 Iustin Pop
31 b1b6ea87 Iustin Pop
SCRIPTNAME="@SYSCONFDIR@/init.d/ganeti"
32 a8083063 Iustin Pop
33 9bd7f742 Iustin Pop
test -f $NODED || exit 0
34 a8083063 Iustin Pop
35 a8083063 Iustin Pop
. /lib/lsb/init-functions
36 a8083063 Iustin Pop
37 a8083063 Iustin Pop
check_config() {
38 c1671c0e Michael Hanselmann
    for fname in \
39 c1671c0e Michael Hanselmann
        "@LOCALSTATEDIR@/lib/ganeti/server.pem"
40 c1671c0e Michael Hanselmann
    do
41 3c9a0742 Michael Hanselmann
        if ! [ -f "$fname" ]; then
42 3c9a0742 Michael Hanselmann
            log_end_msg 0
43 3c9a0742 Michael Hanselmann
            log_warning_msg "Config $fname not there, will not run."
44 3c9a0742 Michael Hanselmann
            exit 0
45 3c9a0742 Michael Hanselmann
        fi
46 3c9a0742 Michael Hanselmann
    done
47 a8083063 Iustin Pop
}
48 a8083063 Iustin Pop
49 b1b6ea87 Iustin Pop
check_exitcode() {
50 b1b6ea87 Iustin Pop
    RC=$1
51 9bd7f742 Iustin Pop
    case $RC in
52 9bd7f742 Iustin Pop
        0)
53 9bd7f742 Iustin Pop
            log_action_end_msg 0
54 9bd7f742 Iustin Pop
            ;;
55 9bd7f742 Iustin Pop
        11)
56 9bd7f742 Iustin Pop
            log_action_end_msg 0 "not master"
57 9bd7f742 Iustin Pop
            ;;
58 9bd7f742 Iustin Pop
        *)
59 9bd7f742 Iustin Pop
            log_action_end_msg 1 "exit code $RC"
60 9bd7f742 Iustin Pop
            ;;
61 9bd7f742 Iustin Pop
    esac
62 9bd7f742 Iustin Pop
}
63 9bd7f742 Iustin Pop
64 b1b6ea87 Iustin Pop
start_action() {
65 b1b6ea87 Iustin Pop
    # called as start_action daemon pidfile
66 e10a3aea Iustin Pop
    local daemon="$1"; shift
67 949bdabe Iustin Pop
    local pidfile="$1"; shift
68 e10a3aea Iustin Pop
    log_action_begin_msg "$daemon"
69 e10a3aea Iustin Pop
    start-stop-daemon --start --quiet --exec "$daemon" --pidfile "$pidfile" \
70 e10a3aea Iustin Pop
        -- "$@"
71 b1b6ea87 Iustin Pop
    check_exitcode $?
72 b1b6ea87 Iustin Pop
}
73 b1b6ea87 Iustin Pop
74 b1b6ea87 Iustin Pop
stop_action() {
75 b1b6ea87 Iustin Pop
    # called as stop_action daemon pidfile
76 b1b6ea87 Iustin Pop
    log_action_begin_msg "$1"
77 b1b6ea87 Iustin Pop
    start-stop-daemon --stop --quiet --oknodo \
78 b1b6ea87 Iustin Pop
        --retry 30 --pidfile "$2"
79 b1b6ea87 Iustin Pop
    check_exitcode $?
80 b1b6ea87 Iustin Pop
}
81 b1b6ea87 Iustin Pop
82 b1b6ea87 Iustin Pop
83 a8083063 Iustin Pop
case "$1" in
84 3c9a0742 Michael Hanselmann
    start)
85 9bd7f742 Iustin Pop
        log_daemon_msg "Starting $DESC" "$NAME"
86 3c9a0742 Michael Hanselmann
        check_config
87 b1b6ea87 Iustin Pop
        start_action $NODED $NODED_PID
88 b1b6ea87 Iustin Pop
        start_action $MASTERD $MASTERD_PID
89 b1b6ea87 Iustin Pop
        start_action $RAPI $RAPI_PID
90 84d6ea9b Guido Trotter
        ;;
91 3c9a0742 Michael Hanselmann
    stop)
92 9bd7f742 Iustin Pop
        log_daemon_msg "Stopping $DESC" "$NAME"
93 b1b6ea87 Iustin Pop
        stop_action $RAPI $RAPI_PID
94 b1b6ea87 Iustin Pop
        stop_action $MASTERD $MASTERD_PID
95 b1b6ea87 Iustin Pop
        stop_action $NODED $NODED_PID
96 84d6ea9b Guido Trotter
        ;;
97 3c9a0742 Michael Hanselmann
    restart|force-reload)
98 9bd7f742 Iustin Pop
        log_daemon_msg "Reloading $DESC"
99 b1b6ea87 Iustin Pop
        stop_action $RAPI $RAPI_PID
100 b1b6ea87 Iustin Pop
        stop_action $MASTERD $MASTERD_PID
101 b1b6ea87 Iustin Pop
        stop_action $NODED $NODED_PID
102 3c9a0742 Michael Hanselmann
        check_config
103 b1b6ea87 Iustin Pop
        start_action $NODED $NODED_PID
104 b1b6ea87 Iustin Pop
        start_action $MASTERD $MASTERD_PID
105 b1b6ea87 Iustin Pop
        start_action $RAPI $RAPI_PID
106 84d6ea9b Guido Trotter
        ;;
107 3c9a0742 Michael Hanselmann
    *)
108 3c9a0742 Michael Hanselmann
        log_success_msg "Usage: $SCRIPTNAME {start|stop|force-reload|restart}"
109 3c9a0742 Michael Hanselmann
        exit 1
110 84d6ea9b Guido Trotter
        ;;
111 a8083063 Iustin Pop
esac
112 a8083063 Iustin Pop
113 a8083063 Iustin Pop
exit 0