Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (2.4 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 9bd7f742 Iustin Pop
    case $RC in
33 9bd7f742 Iustin Pop
        0)
34 9bd7f742 Iustin Pop
            log_action_end_msg 0
35 9bd7f742 Iustin Pop
            ;;
36 9bd7f742 Iustin Pop
        11)
37 9bd7f742 Iustin Pop
            log_action_end_msg 0 "not master"
38 9bd7f742 Iustin Pop
            ;;
39 9bd7f742 Iustin Pop
        *)
40 9bd7f742 Iustin Pop
            log_action_end_msg 1 "exit code $RC"
41 9bd7f742 Iustin Pop
            ;;
42 9bd7f742 Iustin Pop
    esac
43 9bd7f742 Iustin Pop
}
44 9bd7f742 Iustin Pop
45 b1b6ea87 Iustin Pop
start_action() {
46 82cd7760 Iustin Pop
    # called as start_action daemon-name
47 f154a7a3 Michael Hanselmann
    local daemon="$1"
48 e10a3aea Iustin Pop
    log_action_begin_msg "$daemon"
49 f154a7a3 Michael Hanselmann
    $DAEMON_UTIL start "$@"
50 b1b6ea87 Iustin Pop
    check_exitcode $?
51 b1b6ea87 Iustin Pop
}
52 b1b6ea87 Iustin Pop
53 b1b6ea87 Iustin Pop
stop_action() {
54 82cd7760 Iustin Pop
    # called as stop_action daemon-name
55 82cd7760 Iustin Pop
    local daemon="$1"
56 82cd7760 Iustin Pop
    log_action_begin_msg "$daemon"
57 f154a7a3 Michael Hanselmann
    $DAEMON_UTIL stop "$@"
58 b1b6ea87 Iustin Pop
    check_exitcode $?
59 b1b6ea87 Iustin Pop
}
60 b1b6ea87 Iustin Pop
61 82cd7760 Iustin Pop
maybe_do() {
62 82cd7760 Iustin Pop
    requested="$1"; shift
63 82cd7760 Iustin Pop
    action="$1"; shift
64 82cd7760 Iustin Pop
    target="$1"
65 82cd7760 Iustin Pop
    if [ -z "$requested" -o "$requested" = "$target" ]; then
66 82cd7760 Iustin Pop
        $action "$@"
67 82cd7760 Iustin Pop
    fi
68 82cd7760 Iustin Pop
}
69 82cd7760 Iustin Pop
70 f154a7a3 Michael Hanselmann
start_all() {
71 d2baa21d Michael Hanselmann
    if ! $DAEMON_UTIL check-config; then
72 d2baa21d Michael Hanselmann
        log_warning_msg "Incomplete configuration, will not run."
73 d2baa21d Michael Hanselmann
        exit 0
74 d2baa21d Michael Hanselmann
    fi
75 d2baa21d Michael Hanselmann
76 f154a7a3 Michael Hanselmann
    for i in $NODED $MASTERD $CONFD $RAPI; do \
77 bd14a6ac Iustin Pop
        maybe_do "$1" start_action $i
78 f154a7a3 Michael Hanselmann
    done
79 f154a7a3 Michael Hanselmann
}
80 f154a7a3 Michael Hanselmann
81 f154a7a3 Michael Hanselmann
stop_all() {
82 f154a7a3 Michael Hanselmann
    for i in $RAPI $CONFD $MASTERD $NODED; do \
83 f154a7a3 Michael Hanselmann
        maybe_do "$1" stop_action $i
84 f154a7a3 Michael Hanselmann
    done
85 f154a7a3 Michael Hanselmann
}
86 f154a7a3 Michael Hanselmann
87 82cd7760 Iustin Pop
if [ -n "$2" -a \
88 82cd7760 Iustin Pop
    "$2" != "$NODED" -a \
89 e58b56ad Guido Trotter
    "$2" != "$CONFD" -a \
90 82cd7760 Iustin Pop
    "$2" != "$MASTERD" -a \
91 82cd7760 Iustin Pop
    "$2" != "$RAPI" ]; then
92 82cd7760 Iustin Pop
    log_failure_msg "Unknown daemon '$2' requested"
93 82cd7760 Iustin Pop
    exit 1
94 82cd7760 Iustin Pop
fi
95 b1b6ea87 Iustin Pop
96 a8083063 Iustin Pop
case "$1" in
97 3c9a0742 Michael Hanselmann
    start)
98 82cd7760 Iustin Pop
        log_daemon_msg "Starting $DESC" "$2"
99 f154a7a3 Michael Hanselmann
        start_all "$2"
100 84d6ea9b Guido Trotter
        ;;
101 3c9a0742 Michael Hanselmann
    stop)
102 82cd7760 Iustin Pop
        log_daemon_msg "Stopping $DESC" "$2"
103 f154a7a3 Michael Hanselmann
        stop_all "$2"
104 84d6ea9b Guido Trotter
        ;;
105 3c9a0742 Michael Hanselmann
    restart|force-reload)
106 d2baa21d Michael Hanselmann
        log_daemon_msg "Restarting $DESC" "$2"
107 f154a7a3 Michael Hanselmann
        stop_all "$2"
108 f154a7a3 Michael Hanselmann
        start_all "$2"
109 84d6ea9b Guido Trotter
        ;;
110 3c9a0742 Michael Hanselmann
    *)
111 3c9a0742 Michael Hanselmann
        log_success_msg "Usage: $SCRIPTNAME {start|stop|force-reload|restart}"
112 3c9a0742 Michael Hanselmann
        exit 1
113 84d6ea9b Guido Trotter
        ;;
114 a8083063 Iustin Pop
esac
115 a8083063 Iustin Pop
116 a8083063 Iustin Pop
exit 0