ganeti.initd.in 2.87 KB
Newer Older
1
#!/bin/sh
Iustin Pop's avatar
Iustin Pop committed
2
3
# ganeti node daemon starter script
# based on skeleton from Debian GNU/Linux
4
5
6
7
8
### BEGIN INIT INFO
# Provides:          ganeti
# Required-Start:    $syslog $remote_fs xend
# Required-Stop:     $syslog $remote_fs xend
# Default-Start:     2 3 4 5
Iustin Pop's avatar
Iustin Pop committed
9
# Default-Stop:      0 1 6
10
# Short-Description: Ganeti Xen Cluster Manager
Iustin Pop's avatar
Iustin Pop committed
11
# Description:       Ganeti Xen Cluster Manager
12
### END INIT INFO
Iustin Pop's avatar
Iustin Pop committed
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
20
GANETI_DEFAULTS_FILE="@SYSCONFDIR@/default/ganeti"

21
22
23
24
25
26
27
28
29
30
31
32
33
NODED_NAME="ganeti-noded"
NODED="@PREFIX@/sbin/${NODED_NAME}"
NODED_PID="${GANETIRUNDIR}/${NODED_NAME}.pid"

MASTERD_NAME="ganeti-masterd"
MASTERD="@PREFIX@/sbin/${MASTERD_NAME}"
MASTERD_PID="${GANETIRUNDIR}/${MASTERD_NAME}.pid"

RAPI_NAME="ganeti-rapi"
RAPI="@PREFIX@/sbin/${RAPI_NAME}"
RAPI_PID="${GANETIRUNDIR}/${RAPI_NAME}.pid"

SCRIPTNAME="@SYSCONFDIR@/init.d/ganeti"
Iustin Pop's avatar
Iustin Pop committed
34

35
test -f $NODED || exit 0
Iustin Pop's avatar
Iustin Pop committed
36
37
38

. /lib/lsb/init-functions

39
40
41
42
if [ -s $GANETI_DEFAULTS_FILE ]; then
    . $GANETI_DEFAULTS_FILE
fi

Iustin Pop's avatar
Iustin Pop committed
43
check_config() {
44
45
46
    for fname in \
        "@LOCALSTATEDIR@/lib/ganeti/server.pem"
    do
Michael Hanselmann's avatar
Michael Hanselmann committed
47
48
49
50
51
52
        if ! [ -f "$fname" ]; then
            log_end_msg 0
            log_warning_msg "Config $fname not there, will not run."
            exit 0
        fi
    done
Iustin Pop's avatar
Iustin Pop committed
53
54
}

55
56
check_exitcode() {
    RC=$1
57
58
59
60
61
62
63
64
65
66
67
68
69
    case $RC in
        0)
            log_action_end_msg 0
            ;;
        11)
            log_action_end_msg 0 "not master"
            ;;
        *)
            log_action_end_msg 1 "exit code $RC"
            ;;
    esac
}

70
71
start_action() {
    # called as start_action daemon pidfile
72
    local daemon="$1"; shift
73
    local pidfile="$1"; shift
74
75
76
    log_action_begin_msg "$daemon"
    start-stop-daemon --start --quiet --exec "$daemon" --pidfile "$pidfile" \
        -- "$@"
77
78
79
80
81
82
83
84
85
86
87
88
    check_exitcode $?
}

stop_action() {
    # called as stop_action daemon pidfile
    log_action_begin_msg "$1"
    start-stop-daemon --stop --quiet --oknodo \
        --retry 30 --pidfile "$2"
    check_exitcode $?
}


Iustin Pop's avatar
Iustin Pop committed
89
case "$1" in
Michael Hanselmann's avatar
Michael Hanselmann committed
90
    start)
91
        log_daemon_msg "Starting $DESC" "$NAME"
Michael Hanselmann's avatar
Michael Hanselmann committed
92
        check_config
93
94
95
        start_action $NODED $NODED_PID
        start_action $MASTERD $MASTERD_PID
        start_action $RAPI $RAPI_PID
96
        ;;
Michael Hanselmann's avatar
Michael Hanselmann committed
97
    stop)
98
        log_daemon_msg "Stopping $DESC" "$NAME"
99
100
101
        stop_action $RAPI $RAPI_PID
        stop_action $MASTERD $MASTERD_PID
        stop_action $NODED $NODED_PID
102
        ;;
Michael Hanselmann's avatar
Michael Hanselmann committed
103
    restart|force-reload)
104
        log_daemon_msg "Reloading $DESC"
105
106
107
        stop_action $RAPI $RAPI_PID
        stop_action $MASTERD $MASTERD_PID
        stop_action $NODED $NODED_PID
Michael Hanselmann's avatar
Michael Hanselmann committed
108
        check_config
109
110
111
        start_action $NODED $NODED_PID
        start_action $MASTERD $MASTERD_PID
        start_action $RAPI $RAPI_PID
112
        ;;
Michael Hanselmann's avatar
Michael Hanselmann committed
113
114
115
    *)
        log_success_msg "Usage: $SCRIPTNAME {start|stop|force-reload|restart}"
        exit 1
116
        ;;
Iustin Pop's avatar
Iustin Pop committed
117
118
119
esac

exit 0