Statistics
| Branch: | Tag: | Revision:

root / doc / examples / ganeti.initd.in @ 10c5c1c3

History | View | Annotate | Download (2.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
NODED="ganeti-noded"
18
MASTERD="ganeti-masterd"
19
CONFD="ganeti-confd"
20
RAPI="ganeti-rapi"
21

    
22
DAEMON_UTIL=@PKGLIBDIR@/daemon-util
23

    
24
SCRIPTNAME="@SYSCONFDIR@/init.d/ganeti"
25

    
26
test -f "@PREFIX@/sbin/$NODED" || exit 0
27

    
28
. /lib/lsb/init-functions
29

    
30
check_exitcode() {
31
    RC=$1
32

    
33
    if errmsg=$($DAEMON_UTIL check-exitcode $RC)
34
    then
35
        log_action_end_msg 0 "$errmsg"
36
    else
37
        log_action_end_msg 1 "$errmsg"
38
    fi
39
}
40

    
41
start_action() {
42
    # called as start_action daemon-name
43
    local daemon="$1"
44
    log_action_begin_msg "$daemon"
45
    $DAEMON_UTIL start "$@"
46
    check_exitcode $?
47
}
48

    
49
stop_action() {
50
    # called as stop_action daemon-name
51
    local daemon="$1"
52
    log_action_begin_msg "$daemon"
53
    $DAEMON_UTIL stop "$@"
54
    check_exitcode $?
55
}
56

    
57
maybe_do() {
58
    requested="$1"; shift
59
    action="$1"; shift
60
    target="$1"
61
    if [ -z "$requested" -o "$requested" = "$target" ]; then
62
        $action "$@"
63
    fi
64
}
65

    
66
start_all() {
67
    if ! $DAEMON_UTIL check-config; then
68
        log_warning_msg "Incomplete configuration, will not run."
69
        exit 0
70
    fi
71

    
72
    for i in $NODED $MASTERD $CONFD $RAPI; do \
73
        maybe_do "$1" start_action $i
74
    done
75
}
76

    
77
stop_all() {
78
    for i in $RAPI $CONFD $MASTERD $NODED; do \
79
        maybe_do "$1" stop_action $i
80
    done
81
}
82

    
83
if [ -n "$2" -a \
84
    "$2" != "$NODED" -a \
85
    "$2" != "$CONFD" -a \
86
    "$2" != "$MASTERD" -a \
87
    "$2" != "$RAPI" ]; then
88
    log_failure_msg "Unknown daemon '$2' requested"
89
    exit 1
90
fi
91

    
92
case "$1" in
93
    start)
94
        log_daemon_msg "Starting $DESC" "$2"
95
        start_all "$2"
96
        ;;
97
    stop)
98
        log_daemon_msg "Stopping $DESC" "$2"
99
        stop_all "$2"
100
        ;;
101
    restart|force-reload)
102
        log_daemon_msg "Restarting $DESC" "$2"
103
        stop_all "$2"
104
        start_all "$2"
105
        ;;
106
    *)
107
        log_success_msg "Usage: $SCRIPTNAME {start|stop|force-reload|restart}"
108
        exit 1
109
        ;;
110
esac
111

    
112
exit 0