Statistics
| Branch: | Tag: | Revision:

root / doc / examples / ganeti.initd.in @ 679008e7

History | View | Annotate | Download (3.4 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
CONFD="ganeti-confd"
28
CONFD_ARGS=""
29

    
30
RAPI="ganeti-rapi"
31
RAPI_ARGS=""
32

    
33
SCRIPTNAME="@SYSCONFDIR@/init.d/ganeti"
34

    
35
test -f "@PREFIX@/sbin/$NODED" || exit 0
36

    
37
. /lib/lsb/init-functions
38

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

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

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

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

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

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

    
100
if [ -n "$2" -a \
101
    "$2" != "$NODED" -a \
102
    "$2" != "$CONFD" -a \
103
    "$2" != "$MASTERD" -a \
104
    "$2" != "$RAPI" ]; then
105
    log_failure_msg "Unknown daemon '$2' requested"
106
    exit 1
107
fi
108

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

    
142
exit 0