Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (2.3 kB)

1 c1671c0e Michael Hanselmann
#!/bin/sh
2 a8083063 Iustin Pop
# ganeti node daemon starter 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 82cd7760 Iustin Pop
NODED="ganeti-noded"
18 82cd7760 Iustin Pop
MASTERD="ganeti-masterd"
19 5c566e17 Michael Hanselmann
CONFD="ganeti-confd"
20 82cd7760 Iustin Pop
RAPI="ganeti-rapi"
21 f154a7a3 Michael Hanselmann
22 f154a7a3 Michael Hanselmann
DAEMON_UTIL=@PKGLIBDIR@/daemon-util
23 b1b6ea87 Iustin Pop
24 b1b6ea87 Iustin Pop
SCRIPTNAME="@SYSCONFDIR@/init.d/ganeti"
25 a8083063 Iustin Pop
26 82cd7760 Iustin Pop
test -f "@PREFIX@/sbin/$NODED" || exit 0
27 a8083063 Iustin Pop
28 a8083063 Iustin Pop
. /lib/lsb/init-functions
29 a8083063 Iustin Pop
30 b1b6ea87 Iustin Pop
check_exitcode() {
31 b1b6ea87 Iustin Pop
    RC=$1
32 10c5c1c3 Michael Hanselmann
33 10c5c1c3 Michael Hanselmann
    if errmsg=$($DAEMON_UTIL check-exitcode $RC)
34 10c5c1c3 Michael Hanselmann
    then
35 10c5c1c3 Michael Hanselmann
        log_action_end_msg 0 "$errmsg"
36 10c5c1c3 Michael Hanselmann
    else
37 10c5c1c3 Michael Hanselmann
        log_action_end_msg 1 "$errmsg"
38 10c5c1c3 Michael Hanselmann
    fi
39 9bd7f742 Iustin Pop
}
40 9bd7f742 Iustin Pop
41 b1b6ea87 Iustin Pop
start_action() {
42 82cd7760 Iustin Pop
    # called as start_action daemon-name
43 f154a7a3 Michael Hanselmann
    local daemon="$1"
44 e10a3aea Iustin Pop
    log_action_begin_msg "$daemon"
45 f154a7a3 Michael Hanselmann
    $DAEMON_UTIL start "$@"
46 b1b6ea87 Iustin Pop
    check_exitcode $?
47 b1b6ea87 Iustin Pop
}
48 b1b6ea87 Iustin Pop
49 b1b6ea87 Iustin Pop
stop_action() {
50 82cd7760 Iustin Pop
    # called as stop_action daemon-name
51 82cd7760 Iustin Pop
    local daemon="$1"
52 82cd7760 Iustin Pop
    log_action_begin_msg "$daemon"
53 f154a7a3 Michael Hanselmann
    $DAEMON_UTIL stop "$@"
54 b1b6ea87 Iustin Pop
    check_exitcode $?
55 b1b6ea87 Iustin Pop
}
56 b1b6ea87 Iustin Pop
57 82cd7760 Iustin Pop
maybe_do() {
58 82cd7760 Iustin Pop
    requested="$1"; shift
59 82cd7760 Iustin Pop
    action="$1"; shift
60 82cd7760 Iustin Pop
    target="$1"
61 82cd7760 Iustin Pop
    if [ -z "$requested" -o "$requested" = "$target" ]; then
62 82cd7760 Iustin Pop
        $action "$@"
63 82cd7760 Iustin Pop
    fi
64 82cd7760 Iustin Pop
}
65 82cd7760 Iustin Pop
66 f154a7a3 Michael Hanselmann
start_all() {
67 d2baa21d Michael Hanselmann
    if ! $DAEMON_UTIL check-config; then
68 d2baa21d Michael Hanselmann
        log_warning_msg "Incomplete configuration, will not run."
69 d2baa21d Michael Hanselmann
        exit 0
70 d2baa21d Michael Hanselmann
    fi
71 d2baa21d Michael Hanselmann
72 f154a7a3 Michael Hanselmann
    for i in $NODED $MASTERD $CONFD $RAPI; do \
73 bd14a6ac Iustin Pop
        maybe_do "$1" start_action $i
74 f154a7a3 Michael Hanselmann
    done
75 f154a7a3 Michael Hanselmann
}
76 f154a7a3 Michael Hanselmann
77 f154a7a3 Michael Hanselmann
stop_all() {
78 f154a7a3 Michael Hanselmann
    for i in $RAPI $CONFD $MASTERD $NODED; do \
79 f154a7a3 Michael Hanselmann
        maybe_do "$1" stop_action $i
80 f154a7a3 Michael Hanselmann
    done
81 f154a7a3 Michael Hanselmann
}
82 f154a7a3 Michael Hanselmann
83 82cd7760 Iustin Pop
if [ -n "$2" -a \
84 82cd7760 Iustin Pop
    "$2" != "$NODED" -a \
85 e58b56ad Guido Trotter
    "$2" != "$CONFD" -a \
86 82cd7760 Iustin Pop
    "$2" != "$MASTERD" -a \
87 82cd7760 Iustin Pop
    "$2" != "$RAPI" ]; then
88 82cd7760 Iustin Pop
    log_failure_msg "Unknown daemon '$2' requested"
89 82cd7760 Iustin Pop
    exit 1
90 82cd7760 Iustin Pop
fi
91 b1b6ea87 Iustin Pop
92 a8083063 Iustin Pop
case "$1" in
93 3c9a0742 Michael Hanselmann
    start)
94 82cd7760 Iustin Pop
        log_daemon_msg "Starting $DESC" "$2"
95 f154a7a3 Michael Hanselmann
        start_all "$2"
96 84d6ea9b Guido Trotter
        ;;
97 3c9a0742 Michael Hanselmann
    stop)
98 82cd7760 Iustin Pop
        log_daemon_msg "Stopping $DESC" "$2"
99 f154a7a3 Michael Hanselmann
        stop_all "$2"
100 84d6ea9b Guido Trotter
        ;;
101 3c9a0742 Michael Hanselmann
    restart|force-reload)
102 d2baa21d Michael Hanselmann
        log_daemon_msg "Restarting $DESC" "$2"
103 f154a7a3 Michael Hanselmann
        stop_all "$2"
104 f154a7a3 Michael Hanselmann
        start_all "$2"
105 84d6ea9b Guido Trotter
        ;;
106 3c9a0742 Michael Hanselmann
    *)
107 3c9a0742 Michael Hanselmann
        log_success_msg "Usage: $SCRIPTNAME {start|stop|force-reload|restart}"
108 3c9a0742 Michael Hanselmann
        exit 1
109 84d6ea9b Guido Trotter
        ;;
110 a8083063 Iustin Pop
esac
111 a8083063 Iustin Pop
112 a8083063 Iustin Pop
exit 0