Statistics
| Branch: | Tag: | Revision:

root / doc / examples / ganeti.initd.in @ a02b4427

History | View | Annotate | Download (3 kB)

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
7
# Required-Stop:     $syslog $remote_fs
8
# Default-Start:     2 3 4 5
9
# Default-Stop:      0 1 6
10
# Short-Description: Ganeti Cluster Manager
11
# Description:       Ganeti 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
RAPI_NAME="ganeti-rapi"
32
RAPI="@PREFIX@/sbin/${RAPI_NAME}"
33
RAPI_PID="${GANETIRUNDIR}/${RAPI_NAME}.pid"
34
RAPI_ARGS=""
35

    
36
SCRIPTNAME="@SYSCONFDIR@/init.d/ganeti"
37

    
38
test -f $NODED || exit 0
39

    
40
. /lib/lsb/init-functions
41

    
42
if [ -s $GANETI_DEFAULTS_FILE ]; then
43
    . $GANETI_DEFAULTS_FILE
44
fi
45

    
46
check_config() {
47
    for fname in \
48
        "@LOCALSTATEDIR@/lib/ganeti/server.pem"
49
    do
50
        if ! [ -f "$fname" ]; then
51
            log_end_msg 0
52
            log_warning_msg "Config $fname not there, will not run."
53
            exit 0
54
        fi
55
    done
56
}
57

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

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

    
83
stop_action() {
84
    # called as stop_action daemon pidfile
85
    log_action_begin_msg "$1"
86
    start-stop-daemon --stop --quiet --oknodo \
87
        --retry 30 --pidfile "$2"
88
    check_exitcode $?
89
}
90

    
91

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

    
122
exit 0