summaryrefslogtreecommitdiff
blob: 44fc861d16018c03d5c2892060cebd55144971f7 (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
#!/sbin/openrc-run
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

depend() {
    after ganeti
    after bootmisc
}

CONTROL_PATH="/var/run/ganeti/kvm-hypervisor/ctrl"
GANETI_KVM_TIMEOUT=${GANETI_KVM_TIMEOUT:-60}

start() {
    return 0
}

# Taken from doc/examples/ganeti-kvm-poweroff.initd.in in ganeti package
stop() {
    ebegin "Stopping Ganeti KVM VMs"
    # shutdown VMs and remove sockets of those not running
    for vm_monitor in $(find $CONTROL_PATH -type s -name '*.monitor') ; do
        if ! echo system_powerdown | \
            socat -U UNIX:$vm_monitor STDIO > /dev/null 2>&1; then
            # remove disconnected socket
            rm -f $vm_monitor
        fi
    done

    einfo " Waiting for VMs to poweroff"
    waiting=true
    remaining=$GANETI_KVM_TIMEOUT
    while $waiting && [ $remaining -ne 0 ]; do
        if [ -z "$(find $CONTROL_PATH -type s -name '*.monitor')" ] ; then
            break
        fi

        printf "."
        for vm_monitor in $(find $CONTROL_PATH -type s -name '*.monitor') ; do
            if ! echo | socat -U UNIX:$vm_monitor STDIO > /dev/null 2>&1; then
                rm -rf $vm_monitor
            fi
        done

        sleep 5
        remaining=$((remaining - 5))
    done

    if [ -n "$(find $CONTROL_PATH -type s -name '*.monitor')" ] ; then
        eerror " Some ganeti VMs did not shutdown"
    fi
    echo
    eend $? 
}

restart() {
    eerror "restart not supported"
}