File 0014-VirtualDomain-Properly-migrate-VMs-on-node-shutdown-.patch of Package resource-agents.10310
From 97509c033bec72a61590c3028fa304934cf972c1 Mon Sep 17 00:00:00 2001
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
Date: Wed, 28 Feb 2018 13:56:32 +0100
Subject: [PATCH 14/22] VirtualDomain: Properly migrate VMs on node shutdown
(bsc#1074014)
---
heartbeat/LVM | 6 ++++++
heartbeat/VirtualDomain | 16 ++++++++++++++++
heartbeat/clvm | 6 ++++++
heartbeat/ocf-shellfuncs.in | 25 +++++++++++++++++++++++++
heartbeat/tomcat | 2 +-
5 files changed, 54 insertions(+), 1 deletion(-)
diff --git a/heartbeat/LVM b/heartbeat/LVM
index 5b265f58..9e735e68 100755
--- a/heartbeat/LVM
+++ b/heartbeat/LVM
@@ -426,6 +426,12 @@ LVM_start() {
local vg=$1
local clvmd=0
+ # systemd drop-in to stop process before storage services during
+ # shutdown/reboot
+ if systemd_is_running ; then
+ systemd_drop_in "99-LVM" "After" "blk-availability.service"
+ fi
+
# TODO: This MUST run vgimport as well
ocf_log info "Activating volume group $vg"
if [ "$LVM_MAJOR" -eq "1" ]; then
diff --git a/heartbeat/VirtualDomain b/heartbeat/VirtualDomain
index 0b614f5f..c05fdc8f 100755
--- a/heartbeat/VirtualDomain
+++ b/heartbeat/VirtualDomain
@@ -463,6 +463,14 @@ VirtualDomain_start() {
return $OCF_SUCCESS
fi
+ # systemd drop-in to stop domain before libvirtd terminates services
+ # during shutdown/reboot
+ if systemd_is_running ; then
+ systemd_drop_in "99-VirtualDomain-libvirt" "After" "libvirtd.service"
+ systemd_drop_in "99-VirtualDomain-machines" "Wants" "virt-guest-shutdown.target"
+ systemctl start virt-guest-shutdown.target
+ fi
+
snapshotimage="$OCF_RESKEY_snapshot/${DOMAIN_NAME}.state"
if [ -n "$OCF_RESKEY_snapshot" -a -f "$snapshotimage" ]; then
virsh restore $snapshotimage
@@ -736,6 +744,14 @@ VirtualDomain_migrate_to() {
}
VirtualDomain_migrate_from() {
+ # systemd drop-in to stop domain before libvirtd terminates services
+ # during shutdown/reboot
+ if systemd_is_running ; then
+ systemd_drop_in "99-VirtualDomain-libvirt" "After" "libvirtd.service"
+ systemd_drop_in "99-VirtualDomain-machines" "Wants" "virt-guest-shutdown.target"
+ systemctl start virt-guest-shutdown.target
+ fi
+
while ! VirtualDomain_monitor; do
sleep 1
done
diff --git a/heartbeat/clvm b/heartbeat/clvm
index 8eae6c32..84e4c179 100755
--- a/heartbeat/clvm
+++ b/heartbeat/clvm
@@ -361,6 +361,12 @@ clvmd_start()
return $?
fi
+ # systemd drop-in to stop process before storage services during
+ # shutdown/reboot
+ if systemd_is_running ; then
+ systemd_drop_in "99-clvmd" "After" "blk-availability.service"
+ fi
+
clvmd_status
if [ $? -eq $OCF_SUCCESS ]; then
ocf_log debug "$DAEMON already started"
diff --git a/heartbeat/ocf-shellfuncs.in b/heartbeat/ocf-shellfuncs.in
index adb19576..b622d2c7 100644
--- a/heartbeat/ocf-shellfuncs.in
+++ b/heartbeat/ocf-shellfuncs.in
@@ -606,6 +606,31 @@ dirname()
return 0
}
+# usage: systemd_is_running
+# returns:
+# 0 PID 1 is systemd
+# 1 otherwise
+systemd_is_running()
+{
+ [ "$(cat /proc/1/comm 2>/dev/null)" = "systemd" ]
+}
+
+# usage: systemd_drop_in <name> <After|Before> <dependency.service>
+systemd_drop_in()
+{
+ if [ $# -ne 3 ]; then
+ ocf_log err "Incorrect number of arguments [$#] for systemd_drop_in."
+ fi
+
+ systemdrundir="/run/systemd/system/resource-agents-deps.target.d"
+ mkdir "$systemdrundir"
+ cat > "$systemdrundir/$1.conf" <<EOF
+[Unit]
+$2=$3
+EOF
+ systemctl daemon-reload
+}
+
#
# pseudo_resource status tracking function...
#
diff --git a/heartbeat/tomcat b/heartbeat/tomcat
index 857da78c..d97f8706 100755
--- a/heartbeat/tomcat
+++ b/heartbeat/tomcat
@@ -645,7 +645,7 @@ LOGGING_MANAGER="${OCF_RESKEY_logging_manager}"
if [ -z "${TOMCAT_START_SCRIPT}" ]; then
if ocf_is_true $OCF_RESKEY_force_systemd && \
- ps -p 1 | grep -q systemd; then
+ systemd_is_running; then
SYSTEMD=1
elif [ -e "$CATALINA_HOME/bin/catalina.sh" ]; then
TOMCAT_START_SCRIPT="$CATALINA_HOME/bin/catalina.sh"
--
2.15.1