File 0034-systemd-add-resource-agents-deps-target.patch of Package resource-agents.8843

From f868af55364b71a8a73a8e3dd2a7d499b967003f Mon Sep 17 00:00:00 2001
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
Date: Fri, 28 Apr 2017 12:49:55 +0200
Subject: [PATCH 30/33] systemd: add resource-agents-deps target

---
 Makefile.am                         |  2 +-
 configure.ac                        |  1 +
 heartbeat/LVM                       |  6 ++++++
 heartbeat/clvm                      |  6 ++++++
 heartbeat/ocf-shellfuncs.in         | 16 ++++++++++++++++
 resource-agents.spec.in             |  4 ++++
 systemd/Makefile.am                 | 23 +++++++++++++++++++++++
 systemd/resource-agents-deps.target |  2 ++
 8 files changed, 59 insertions(+), 1 deletion(-)
 create mode 100644 systemd/Makefile.am
 create mode 100644 systemd/resource-agents-deps.target

diff --git a/Makefile.am b/Makefile.am
index 1769c6e3..fccaca49 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -37,7 +37,7 @@ RGMANAGER = with
 endif
 
 if BUILD_LINUX_HA
-SUBDIRS	+= include heartbeat tools ldirectord doc
+SUBDIRS	+= include heartbeat tools ldirectord doc systemd
 LINUX_HA = without
 else
 LINUX_HA = with
diff --git a/configure.ac b/configure.ac
index aae41573..3fb65c93 100644
--- a/configure.ac
+++ b/configure.ac
@@ -864,6 +864,7 @@ heartbeat/Makefile						\
    heartbeat/ocf-directories					\
    heartbeat/ocf-shellfuncs					\
    heartbeat/shellfuncs						\
+systemd/Makefile						\
 tools/Makefile							\
    tools/ocf-tester						\
    tools/ocft/Makefile						\
diff --git a/heartbeat/LVM b/heartbeat/LVM
index 49ebce85..3db61d9f 100755
--- a/heartbeat/LVM
+++ b/heartbeat/LVM
@@ -416,6 +416,12 @@ LVM_start() {
 	local vg=$1
 	local clvmd=0
 
+	# systemd drop-in to stop process before storage services during
+	# shutdown/reboot
+	if ps -p 1 | grep -q systemd ; 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/clvm b/heartbeat/clvm
index 9d639035..1197baf9 100755
--- a/heartbeat/clvm
+++ b/heartbeat/clvm
@@ -362,6 +362,12 @@ clvmd_start()
 		return $?
 	fi
 
+	# systemd drop-in to stop process before storage services during
+	# shutdown/reboot
+	if ps -p 1 | grep -q systemd ; 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 6d9669d1..695c62e6 100644
--- a/heartbeat/ocf-shellfuncs.in
+++ b/heartbeat/ocf-shellfuncs.in
@@ -606,6 +606,22 @@ dirname()
 	return 0
 }
 
+# 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/resource-agents.spec.in b/resource-agents.spec.in
index fbdb7ef0..7dec78c7 100644
--- a/resource-agents.spec.in
+++ b/resource-agents.spec.in
@@ -248,6 +248,10 @@ rm -rf %{buildroot}
 /usr/lib/ocf/resource.d/redhat
 %endif
 
+%if %{defined _unitdir}
+%{_unitdir}/resource-agents-deps.target
+%endif
+
 %dir %{_datadir}/%{name}
 %dir %{_datadir}/%{name}/ocft
 %{_datadir}/%{name}/ocft/configs
diff --git a/systemd/Makefile.am b/systemd/Makefile.am
new file mode 100644
index 00000000..fe13de28
--- /dev/null
+++ b/systemd/Makefile.am
@@ -0,0 +1,23 @@
+#
+# Copyright (C) 2017 Oyvind Albrigtsen
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+
+MAINTAINERCLEANFILES    = Makefile.in
+
+if HAVE_SYSTEMD
+dist_systemdsystemunit_DATA = resource-agents-deps.target
+endif
diff --git a/systemd/resource-agents-deps.target b/systemd/resource-agents-deps.target
new file mode 100644
index 00000000..1c4fdffe
--- /dev/null
+++ b/systemd/resource-agents-deps.target
@@ -0,0 +1,2 @@
+[Unit]
+Description=resource-agents dependencies
-- 
2.16.4

openSUSE Build Service is sponsored by