summaryrefslogtreecommitdiff
path: root/app-emulation/ganeti/files/ganeti-kvm-poweroff.initd
diff options
context:
space:
mode:
Diffstat (limited to 'app-emulation/ganeti/files/ganeti-kvm-poweroff.initd')
-rw-r--r--app-emulation/ganeti/files/ganeti-kvm-poweroff.initd57
1 files changed, 57 insertions, 0 deletions
diff --git a/app-emulation/ganeti/files/ganeti-kvm-poweroff.initd b/app-emulation/ganeti/files/ganeti-kvm-poweroff.initd
new file mode 100644
index 000000000000..44fc861d1601
--- /dev/null
+++ b/app-emulation/ganeti/files/ganeti-kvm-poweroff.initd
@@ -0,0 +1,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"
+}