Statistics
| Branch: | Tag: | Revision:

root / doc / examples / ganeti.initd.in @ 45e22998

History | View | Annotate | Download (2.2 kB)

1
#!/bin/sh
2
# ganeti daemons init 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
DAEMON_UTIL=@PKGLIBDIR@/daemon-util
18

    
19
SCRIPTNAME="@SYSCONFDIR@/init.d/ganeti"
20

    
21
test -f "$DAEMON_UTIL" || exit 0
22

    
23
. /lib/lsb/init-functions
24

    
25
check_exitcode() {
26
    RC=$1
27

    
28
    if errmsg=$($DAEMON_UTIL check-exitcode $RC)
29
    then
30
        log_action_end_msg 0 "$errmsg"
31
    else
32
        log_action_end_msg 1 "$errmsg"
33
    fi
34
}
35

    
36
start_action() {
37
    # called as start_action daemon-name
38
    local daemon="$1"
39
    log_action_begin_msg "$daemon"
40
    $DAEMON_UTIL start "$@"
41
    check_exitcode $?
42
}
43

    
44
stop_action() {
45
    # called as stop_action daemon-name
46
    local daemon="$1"
47
    log_action_begin_msg "$daemon"
48
    $DAEMON_UTIL stop "$@"
49
    check_exitcode $?
50
}
51

    
52
maybe_do() {
53
    requested="$1"; shift
54
    action="$1"; shift
55
    target="$1"
56
    if [ -z "$requested" -o "$requested" = "$target" ]; then
57
        $action "$@"
58
    fi
59
}
60

    
61
start_all() {
62
    if ! $DAEMON_UTIL check-config; then
63
        log_warning_msg "Incomplete configuration, will not run."
64
        exit 0
65
    fi
66

    
67
    for i in $($DAEMON_UTIL list-start-daemons); do
68
        maybe_do "$1" start_action $i
69
    done
70
}
71

    
72
stop_all() {
73
    for i in $($DAEMON_UTIL list-stop-daemons); do
74
        maybe_do "$1" stop_action $i
75
    done
76
}
77

    
78
if [ -n "$2" ] && ! errmsg=$($DAEMON_UTIL is-daemon-name "$2" 2>&1); then
79
    log_failure_msg "$errmsg"
80
    exit 1
81
fi
82

    
83
case "$1" in
84
    start)
85
        log_daemon_msg "Starting $DESC" "$2"
86
        start_all "$2"
87
        ;;
88
    stop)
89
        log_daemon_msg "Stopping $DESC" "$2"
90
        stop_all "$2"
91
        ;;
92
    restart|force-reload)
93
        log_daemon_msg "Restarting $DESC" "$2"
94
        stop_all "$2"
95
        start_all "$2"
96
        ;;
97
    *)
98
        log_success_msg "Usage: $SCRIPTNAME {start|stop|force-reload|restart}"
99
        exit 1
100
        ;;
101
esac
102

    
103
exit 0