Statistics
| Branch: | Tag: | Revision:

root / doc / examples / ganeti.initd.in @ 949bdabe

History | View | Annotate | Download (2.7 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 xend
7
# Required-Stop:     $syslog $remote_fs xend
8
# Default-Start:     2 3 4 5
9
# Default-Stop:      0 1 6
10
# Short-Description: Ganeti Xen Cluster Manager
11
# Description:       Ganeti Xen 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
NODED_NAME="ganeti-noded"
20
NODED="@PREFIX@/sbin/${NODED_NAME}"
21
NODED_PID="${GANETIRUNDIR}/${NODED_NAME}.pid"
22

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

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

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

    
33
test -f $NODED || exit 0
34

    
35
. /lib/lsb/init-functions
36

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

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

    
64
start_action() {
65
    # called as start_action daemon pidfile
66
    local daemon="$1"; shift
67
    local pidfile="$1"; shift
68
    log_action_begin_msg "$daemon"
69
    start-stop-daemon --start --quiet --exec "$daemon" --pidfile "$pidfile" \
70
        -- "$@"
71
    check_exitcode $?
72
}
73

    
74
stop_action() {
75
    # called as stop_action daemon pidfile
76
    log_action_begin_msg "$1"
77
    start-stop-daemon --stop --quiet --oknodo \
78
        --retry 30 --pidfile "$2"
79
    check_exitcode $?
80
}
81

    
82

    
83
case "$1" in
84
    start)
85
        log_daemon_msg "Starting $DESC" "$NAME"
86
        check_config
87
        start_action $NODED $NODED_PID
88
        start_action $MASTERD $MASTERD_PID
89
        start_action $RAPI $RAPI_PID
90
     ;;
91
    stop)
92
        log_daemon_msg "Stopping $DESC" "$NAME"
93
        stop_action $RAPI $RAPI_PID
94
        stop_action $MASTERD $MASTERD_PID
95
        stop_action $NODED $NODED_PID
96
    ;;
97
    restart|force-reload)
98
        log_daemon_msg "Reloading $DESC"
99
        stop_action $RAPI $RAPI_PID
100
        stop_action $MASTERD $MASTERD_PID
101
        stop_action $NODED $NODED_PID
102
        check_config
103
        start_action $NODED $NODED_PID
104
        start_action $MASTERD $MASTERD_PID
105
        start_action $RAPI $RAPI_PID
106
     ;;
107
    *)
108
        log_success_msg "Usage: $SCRIPTNAME {start|stop|force-reload|restart}"
109
        exit 1
110
    ;;
111
esac
112

    
113
exit 0