Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (3.2 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="ganeti-noded"
22
NODED_ARGS=""
23

    
24
MASTERD="ganeti-masterd"
25
MASTERD_ARGS=""
26

    
27
RAPI="ganeti-rapi"
28
RAPI_ARGS=""
29

    
30
SCRIPTNAME="@SYSCONFDIR@/init.d/ganeti"
31

    
32
test -f "@PREFIX@/sbin/$NODED" || exit 0
33

    
34
. /lib/lsb/init-functions
35

    
36
if [ -s $GANETI_DEFAULTS_FILE ]; then
37
    . $GANETI_DEFAULTS_FILE
38
fi
39

    
40
check_config() {
41
    for fname in \
42
        "@LOCALSTATEDIR@/lib/ganeti/server.pem"
43
    do
44
        if ! [ -f "$fname" ]; then
45
            log_end_msg 0
46
            log_warning_msg "Config $fname not there, will not run."
47
            exit 0
48
        fi
49
    done
50
}
51

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

    
67
start_action() {
68
    # called as start_action daemon-name
69
    local daemon="$1"; shift
70
    log_action_begin_msg "$daemon"
71
    start-stop-daemon --start --quiet \
72
        --pidfile "${GANETIRUNDIR}/${daemon}.pid" \
73
        --startas "@PREFIX@/sbin/$daemon" \
74
        --oknodo \
75
        -- "$@"
76
    check_exitcode $?
77
}
78

    
79
stop_action() {
80
    # called as stop_action daemon-name
81
    local daemon="$1"
82
    log_action_begin_msg "$daemon"
83
    start-stop-daemon --stop --quiet --oknodo \
84
        --retry 30 --pidfile "${GANETIRUNDIR}/${daemon}.pid"
85
    check_exitcode $?
86
}
87

    
88
maybe_do() {
89
    requested="$1"; shift
90
    action="$1"; shift
91
    target="$1"
92
    if [ -z "$requested" -o "$requested" = "$target" ]; then
93
        $action "$@"
94
    fi
95
}
96

    
97
if [ -n "$2" -a \
98
    "$2" != "$NODED" -a \
99
    "$2" != "$MASTERD" -a \
100
    "$2" != "$RAPI" ]; then
101
    log_failure_msg "Unknown daemon '$2' requested"
102
    exit 1
103
fi
104

    
105
case "$1" in
106
    start)
107
        log_daemon_msg "Starting $DESC" "$2"
108
        check_config
109
        maybe_do "$2" start_action $NODED $NODED_ARGS
110
        maybe_do "$2" start_action $MASTERD $MASTERD_ARGS
111
        maybe_do "$2" start_action $RAPI $RAPI_ARGS
112
        ;;
113
    stop)
114
        log_daemon_msg "Stopping $DESC" "$2"
115
        maybe_do "$2" stop_action $RAPI
116
        maybe_do "$2" stop_action $MASTERD
117
        maybe_do "$2" stop_action $NODED
118
        ;;
119
    restart|force-reload)
120
        log_daemon_msg "Reloading $DESC" "$2"
121
        maybe_do "$2" stop_action $RAPI
122
        maybe_do "$2" stop_action $MASTERD
123
        maybe_do "$2" stop_action $NODED
124
        check_config
125
        maybe_do "$2" start_action $NODED $NODED_ARGS
126
        maybe_do "$2" start_action $MASTERD $MASTERD_ARGS
127
        maybe_do "$2" start_action $RAPI $RAPI_ARGS
128
        ;;
129
    *)
130
        log_success_msg "Usage: $SCRIPTNAME {start|stop|force-reload|restart}"
131
        exit 1
132
        ;;
133
esac
134

    
135
exit 0