2 # ganeti kvm instance poweroff
3 # based on skeleton from Debian GNU/Linux
5 # Provides: ganeti-kvm-poweroff
7 # Required-Stop: drbd qemu-kvm $local_fs
10 # Short-Description: Poweroff Ganeti KVM instances
11 # Description: Sends system_powerdown command to Ganeti instances, otherwise
12 # they will be killed.
17 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
18 DESC="Ganeti KVM instance poweroff "
20 . /lib/lsb/init-functions
22 CONTROL_PATH="@LOCALSTATEDIR@/run/ganeti/kvm-hypervisor/ctrl"
23 SCRIPTNAME="@SYSCONFDIR@/init.d/ganeti-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
36 log_action_begin_msg "Waiting VMs to poweroff"
39 while $waiting && [ $remaning -ne 0 ]; do
40 if [[ -z "$(find $CONTROL_PATH -name '*.monitor')" ]]; then
45 for vm_monitor in $CONTROL_PATH/*.monitor; do
46 if ! echo | socat -U UNIX:$vm_monitor STDIO > /dev/null 2>&1; then
55 if [[ -z "$(find $CONTROL_PATH -name '*.monitor')" ]]; then
58 log_action_end_msg 1 "some VMs did not shutdown"
66 restart|reload|force-reload)
67 echo "Error: argument '$1' not supported" >&2
74 echo "Usage: $0 start|stop" >&2