Statistics
| Branch: | Tag: | Revision:

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

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
    log_action_begin_msg "$1"
67
    start-stop-daemon --start --quiet --exec "$1" --pidfile "$2"
68
    check_exitcode $?
69
}
70

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

    
79

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

    
110
exit 0