summaryrefslogtreecommitdiff
blob: a270ac831e93a06b7ebcc31be956ec74f80f7f8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/sbin/runscript
# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

depend() {
    need localmount logger
    after bootmisc
	use net
}

DAEMON_UTIL="/usr/lib/ganeti/daemon-util"

check_config() {
    if ! $DAEMON_UTIL check-config ; then
        eend 0 "Incomplete configuration, will not run."
    fi
}

check_exitcode() {
    RC=${1}
    if errmsg=$(${DAEMON_UTIL} check-exitcode ${RC}) ; then
        eend 0 "${errmsg}"
    else
        eend 1 "${errmsg}"
    fi
}

start_action() {
    # called as start_action daemon-name
    local daemon="${1}"
    ebegin "Starting ${daemon}"
    ${DAEMON_UTIL} start "${@}"
    check_exitcode ${?}
}

stop_action() {
    # called as stop_action daemon-name
    local daemon="${1}"
    ebegin "Stopping ${daemon}"
    ${DAEMON_UTIL} stop "${@}"
    check_exitcode ${?}
}

maybe_do() {
    requested="${1}"; shift
    action="${1}"; shift
    target="${1}"
    if [ -z "${requested}" -o "${requested}" = "${target}" ] ; then
        ${action} "${@}"
    fi
}

get_master_node() {
    MASTER_NODE="$(gnt-cluster getmaster)"
    NODE_HOSTNAME="$(hostname -f)"
    if [ "$MASTER_NODE" == "$NODE_HOSTNAME" ] ; then
        MASTER=1
    else
        MASTER=0
    fi
}

start_all() {
    check_config
    get_master_node
    for i in $($DAEMON_UTIL list-start-daemons); do \
        GANETI_START_OPTS="${GANETI_OPTS}"
        case "${i}" in
            ganeti-masterd)
                GANETI_OPTS="${GANETI_START_OPTS} ${GANETI_MASTERD_OPTS}"
                ;;
            ganeti-rapid)
                GANETI_OPTS="${GANETI_START_OPTS} ${GANETI_RAPI_OPTS}"
                ;;
            ganeti-noded)
                GANETI_OPTS="${GANETI_START_OPTS} ${GANETI_NODED_OPTS}"
                ;;
            ganeti-confd)
                GANETI_OPTS="${GANETI_START_OPTS} ${GANETI_CONFD_OPTS}"
                ;;
        esac
        # Don't start if not master
        if [ $MASTER = 0 -a $i = "ganeti-masterd" ] ; then
            continue
        elif [ $MASTER = 0 -a $i = "ganeti-rapi" ] ; then
            continue
        else
            maybe_do "${1}" start_action ${i} ${GANETI_OPTS}
        fi
    done
}

stop_all() {
    get_master_node
    for i in $($DAEMON_UTIL list-stop-daemons) ; do \
        if [ $MASTER = 0 -a $i = "ganeti-masterd" ] ; then
            continue
        elif [ $MASTER = 0 -a $i = "ganeti-rapi" ] ; then
            continue
        else
            maybe_do "${1}" stop_action ${i} ${GANETI_OPTS}
        fi
    done
}

start() {
    start_all
}

stop() {
    stop_all
}