Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (2.2 kB)

1 c1671c0e Michael Hanselmann
#!/bin/sh
2 45e22998 Guido Trotter
# ganeti daemons init script
3 a8083063 Iustin Pop
# based on skeleton from Debian GNU/Linux
4 24d48647 Guido Trotter
### BEGIN INIT INFO
5 24d48647 Guido Trotter
# Provides:          ganeti
6 a02b4427 Iustin Pop
# Required-Start:    $syslog $remote_fs
7 a02b4427 Iustin Pop
# Required-Stop:     $syslog $remote_fs
8 24d48647 Guido Trotter
# Default-Start:     2 3 4 5
9 e71d6323 Iustin Pop
# Default-Stop:      0 1 6
10 a02b4427 Iustin Pop
# Short-Description: Ganeti Cluster Manager
11 a02b4427 Iustin Pop
# Description:       Ganeti Cluster Manager
12 24d48647 Guido Trotter
### END INIT INFO
13 a8083063 Iustin Pop
14 880478f8 Iustin Pop
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
15 9bd7f742 Iustin Pop
DESC="Ganeti cluster"
16 b1b6ea87 Iustin Pop
17 f154a7a3 Michael Hanselmann
DAEMON_UTIL=@PKGLIBDIR@/daemon-util
18 b1b6ea87 Iustin Pop
19 b1b6ea87 Iustin Pop
SCRIPTNAME="@SYSCONFDIR@/init.d/ganeti"
20 a8083063 Iustin Pop
21 5d8acbdd Michael Hanselmann
test -f "$DAEMON_UTIL" || exit 0
22 a8083063 Iustin Pop
23 a8083063 Iustin Pop
. /lib/lsb/init-functions
24 a8083063 Iustin Pop
25 b1b6ea87 Iustin Pop
check_exitcode() {
26 b1b6ea87 Iustin Pop
    RC=$1
27 10c5c1c3 Michael Hanselmann
28 10c5c1c3 Michael Hanselmann
    if errmsg=$($DAEMON_UTIL check-exitcode $RC)
29 10c5c1c3 Michael Hanselmann
    then
30 10c5c1c3 Michael Hanselmann
        log_action_end_msg 0 "$errmsg"
31 10c5c1c3 Michael Hanselmann
    else
32 10c5c1c3 Michael Hanselmann
        log_action_end_msg 1 "$errmsg"
33 10c5c1c3 Michael Hanselmann
    fi
34 9bd7f742 Iustin Pop
}
35 9bd7f742 Iustin Pop
36 b1b6ea87 Iustin Pop
start_action() {
37 82cd7760 Iustin Pop
    # called as start_action daemon-name
38 f154a7a3 Michael Hanselmann
    local daemon="$1"
39 e10a3aea Iustin Pop
    log_action_begin_msg "$daemon"
40 f154a7a3 Michael Hanselmann
    $DAEMON_UTIL start "$@"
41 b1b6ea87 Iustin Pop
    check_exitcode $?
42 b1b6ea87 Iustin Pop
}
43 b1b6ea87 Iustin Pop
44 b1b6ea87 Iustin Pop
stop_action() {
45 82cd7760 Iustin Pop
    # called as stop_action daemon-name
46 82cd7760 Iustin Pop
    local daemon="$1"
47 82cd7760 Iustin Pop
    log_action_begin_msg "$daemon"
48 f154a7a3 Michael Hanselmann
    $DAEMON_UTIL stop "$@"
49 b1b6ea87 Iustin Pop
    check_exitcode $?
50 b1b6ea87 Iustin Pop
}
51 b1b6ea87 Iustin Pop
52 82cd7760 Iustin Pop
maybe_do() {
53 82cd7760 Iustin Pop
    requested="$1"; shift
54 82cd7760 Iustin Pop
    action="$1"; shift
55 82cd7760 Iustin Pop
    target="$1"
56 82cd7760 Iustin Pop
    if [ -z "$requested" -o "$requested" = "$target" ]; then
57 82cd7760 Iustin Pop
        $action "$@"
58 82cd7760 Iustin Pop
    fi
59 82cd7760 Iustin Pop
}
60 82cd7760 Iustin Pop
61 f154a7a3 Michael Hanselmann
start_all() {
62 d2baa21d Michael Hanselmann
    if ! $DAEMON_UTIL check-config; then
63 d2baa21d Michael Hanselmann
        log_warning_msg "Incomplete configuration, will not run."
64 d2baa21d Michael Hanselmann
        exit 0
65 d2baa21d Michael Hanselmann
    fi
66 d2baa21d Michael Hanselmann
67 5d8acbdd Michael Hanselmann
    for i in $($DAEMON_UTIL list-start-daemons); do
68 bd14a6ac Iustin Pop
        maybe_do "$1" start_action $i
69 f154a7a3 Michael Hanselmann
    done
70 f154a7a3 Michael Hanselmann
}
71 f154a7a3 Michael Hanselmann
72 f154a7a3 Michael Hanselmann
stop_all() {
73 5d8acbdd Michael Hanselmann
    for i in $($DAEMON_UTIL list-stop-daemons); do
74 f154a7a3 Michael Hanselmann
        maybe_do "$1" stop_action $i
75 f154a7a3 Michael Hanselmann
    done
76 f154a7a3 Michael Hanselmann
}
77 f154a7a3 Michael Hanselmann
78 5d8acbdd Michael Hanselmann
if [ -n "$2" ] && ! errmsg=$($DAEMON_UTIL is-daemon-name "$2" 2>&1); then
79 5d8acbdd Michael Hanselmann
    log_failure_msg "$errmsg"
80 82cd7760 Iustin Pop
    exit 1
81 82cd7760 Iustin Pop
fi
82 b1b6ea87 Iustin Pop
83 a8083063 Iustin Pop
case "$1" in
84 3c9a0742 Michael Hanselmann
    start)
85 82cd7760 Iustin Pop
        log_daemon_msg "Starting $DESC" "$2"
86 f154a7a3 Michael Hanselmann
        start_all "$2"
87 84d6ea9b Guido Trotter
        ;;
88 3c9a0742 Michael Hanselmann
    stop)
89 82cd7760 Iustin Pop
        log_daemon_msg "Stopping $DESC" "$2"
90 f154a7a3 Michael Hanselmann
        stop_all "$2"
91 84d6ea9b Guido Trotter
        ;;
92 3c9a0742 Michael Hanselmann
    restart|force-reload)
93 d2baa21d Michael Hanselmann
        log_daemon_msg "Restarting $DESC" "$2"
94 f154a7a3 Michael Hanselmann
        stop_all "$2"
95 f154a7a3 Michael Hanselmann
        start_all "$2"
96 84d6ea9b Guido Trotter
        ;;
97 3c9a0742 Michael Hanselmann
    *)
98 3c9a0742 Michael Hanselmann
        log_success_msg "Usage: $SCRIPTNAME {start|stop|force-reload|restart}"
99 3c9a0742 Michael Hanselmann
        exit 1
100 84d6ea9b Guido Trotter
        ;;
101 a8083063 Iustin Pop
esac
102 a8083063 Iustin Pop
103 a8083063 Iustin Pop
exit 0