Revision 5d9e167a

b/Makefile.am
94 94
	devel/upload \
95 95
	doc/examples/bash_completion \
96 96
	doc/examples/ganeti.initd \
97
	doc/examples/ganeti-kvm-poweroff.initd \
97 98
	doc/examples/ganeti.cron \
98 99
	doc/examples/gnt-config-backup \
99 100
	doc/examples/hooks/ipsec \
......
279 280
	doc/examples/bash_completion \
280 281
	doc/examples/ganeti.cron \
281 282
	doc/examples/ganeti.initd \
283
	doc/examples/ganeti-kvm-poweroff.initd \
282 284
	doc/examples/gnt-config-backup \
283 285
	doc/examples/hooks/ipsec \
284 286
	$(manhtml)
......
356 358
	doc/conf.py \
357 359
	doc/html \
358 360
	doc/examples/ganeti.initd.in \
361
	doc/examples/ganeti-kvm-poweroff.initd.in \
359 362
	doc/examples/ganeti.cron.in \
360 363
	doc/examples/gnt-config-backup.in \
361 364
	doc/examples/dumb-allocator \
b/doc/examples/ganeti-kvm-poweroff.initd.in
1
#!/bin/bash
2
# ganeti kvm instance poweroff
3
# based on skeleton from Debian GNU/Linux
4
### BEGIN INIT INFO
5
# Provides:          ganeti-kvm-poweroff
6
# Required-Start:
7
# Required-Stop:     drbd qemu-kvm $local_fs
8
# Default-Start:
9
# Default-Stop: 0 1 6
10
# Short-Description: Poweroff Ganeti KVM instances
11
# Description: Sends system_powerdown command to Ganeti instances, otherwise
12
# they will be killed.
13
### END INIT INFO
14

  
15
shopt -s nullglob
16

  
17
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
18
DESC="Ganeti KVM instance poweroff "
19

  
20
. /lib/lsb/init-functions
21

  
22
CONTROL_PATH="@LOCALSTATEDIR@/run/ganeti/kvm-hypervisor/ctrl"
23
SCRIPTNAME="@SYSCONFDIR@/init.d/ganeti-kvm-poweroff"
24
TIMEOUT=60
25

  
26
do_kvm_poweroff () {
27
    # shutdown VMs and remove sockets of those not running
28
    for vm_monitor in $CONTROL_PATH/*.monitor; do
29
        if ! echo system_powerdown | \
30
            socat -U UNIX:$vm_monitor STDIO > /dev/null 2>&1; then
31
            # remove disconnected socket
32
            rm -f $vm_monitor
33
        fi
34
    done
35

  
36
    log_action_begin_msg "Waiting VMs to poweroff"
37
    waiting=true
38
    remaning=$TIMEOUT
39
    while $waiting && [ $remaning -ne 0 ]; do
40
        if [[ -z "$(find $CONTROL_PATH -name '*.monitor')" ]]; then
41
            break
42
        fi
43

  
44
        echo -n "."
45
        for vm_monitor in $CONTROL_PATH/*.monitor; do
46
            if ! echo | socat -U UNIX:$vm_monitor STDIO > /dev/null 2>&1; then
47
                rm -rf $vm_monitor
48
            fi
49
        done
50

  
51
        sleep 5
52
        let remaining-=5 1
53
    done
54

  
55
    if [[ -z "$(find $CONTROL_PATH -name '*.monitor')" ]]; then
56
        log_action_end_msg 0
57
    else
58
        log_action_end_msg 1 "some VMs did not shutdown"
59
    fi
60
}
61

  
62
case "$1" in
63
  start)
64
    # No-op
65
    ;;
66
  restart|reload|force-reload)
67
    echo "Error: argument '$1' not supported" >&2
68
    exit 3
69
    ;;
70
  stop)
71
    do_kvm_poweroff
72
    ;;
73
  *)
74
    echo "Usage: $0 start|stop" >&2
75
    exit 3
76
    ;;
77
esac

Also available in: Unified diff