17b94a
From 267135e74d94d8a1e56a263b37ca4689020b9e53 Mon Sep 17 00:00:00 2001
17b94a
From: Jiffin Tony Thottan <jthottan@redhat.com>
17b94a
Date: Mon, 16 Oct 2017 16:58:28 +0530
17b94a
Subject: [PATCH 055/124] Revert "storhaug HA: first step, remove resource
17b94a
 agents and setup script"
17b94a
17b94a
This reverts commit c822e354e16646adf18bbc5123798663faa543b2.
17b94a
17b94a
Label: DOWNSTREAM ONLY
17b94a
17b94a
Change-Id: Idd50fe1a5be5a3258d560518d810f9ec4c57621a
17b94a
Signed-off-by: Jiffin Tony Thottan <jthottan@redhat.com>
17b94a
Reviewed-on: https://code.engineering.redhat.com/gerrit/167104
17b94a
Reviewed-by: Soumya Koduri <skoduri@redhat.com>
17b94a
Tested-by: RHGS Build Bot <nigelb@redhat.com>
17b94a
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
17b94a
---
17b94a
 configure.ac                         |    1 +
17b94a
 extras/ganesha/Makefile.am           |    2 +-
17b94a
 extras/ganesha/ocf/Makefile.am       |   11 +
17b94a
 extras/ganesha/ocf/ganesha_grace     |  221 +++++++
17b94a
 extras/ganesha/ocf/ganesha_mon       |  234 +++++++
17b94a
 extras/ganesha/ocf/ganesha_nfsd      |  167 +++++
17b94a
 extras/ganesha/scripts/Makefile.am   |    6 +-
17b94a
 extras/ganesha/scripts/ganesha-ha.sh | 1125 ++++++++++++++++++++++++++++++++++
17b94a
 glusterfs.spec.in                    |    8 +-
17b94a
 9 files changed, 1771 insertions(+), 4 deletions(-)
17b94a
 create mode 100644 extras/ganesha/ocf/Makefile.am
17b94a
 create mode 100644 extras/ganesha/ocf/ganesha_grace
17b94a
 create mode 100644 extras/ganesha/ocf/ganesha_mon
17b94a
 create mode 100644 extras/ganesha/ocf/ganesha_nfsd
17b94a
 create mode 100644 extras/ganesha/scripts/ganesha-ha.sh
17b94a
17b94a
diff --git a/configure.ac b/configure.ac
17b94a
index 125ae29..baa811a 100644
17b94a
--- a/configure.ac
17b94a
+++ b/configure.ac
17b94a
@@ -199,6 +199,7 @@ AC_CONFIG_FILES([Makefile
17b94a
                 extras/ganesha/Makefile
17b94a
                 extras/ganesha/config/Makefile
17b94a
                 extras/ganesha/scripts/Makefile
17b94a
+                extras/ganesha/ocf/Makefile
17b94a
                 extras/systemd/Makefile
17b94a
                 extras/systemd/glusterd.service
17b94a
                 extras/systemd/glustereventsd.service
17b94a
diff --git a/extras/ganesha/Makefile.am b/extras/ganesha/Makefile.am
17b94a
index 542de68..9eaa401 100644
17b94a
--- a/extras/ganesha/Makefile.am
17b94a
+++ b/extras/ganesha/Makefile.am
17b94a
@@ -1,2 +1,2 @@
17b94a
-SUBDIRS = scripts config
17b94a
+SUBDIRS = scripts config ocf
17b94a
 CLEANFILES =
17b94a
diff --git a/extras/ganesha/ocf/Makefile.am b/extras/ganesha/ocf/Makefile.am
17b94a
new file mode 100644
17b94a
index 0000000..990a609
17b94a
--- /dev/null
17b94a
+++ b/extras/ganesha/ocf/Makefile.am
17b94a
@@ -0,0 +1,11 @@
17b94a
+EXTRA_DIST= ganesha_grace ganesha_mon ganesha_nfsd
17b94a
+
17b94a
+# The root of the OCF resource agent hierarchy
17b94a
+# Per the OCF standard, it's always "lib",
17b94a
+# not "lib64" (even on 64-bit platforms).
17b94a
+ocfdir = $(prefix)/lib/ocf
17b94a
+
17b94a
+# The provider directory
17b94a
+radir = $(ocfdir)/resource.d/heartbeat
17b94a
+
17b94a
+ra_SCRIPTS = ganesha_grace ganesha_mon ganesha_nfsd
17b94a
diff --git a/extras/ganesha/ocf/ganesha_grace b/extras/ganesha/ocf/ganesha_grace
17b94a
new file mode 100644
17b94a
index 0000000..825f716
17b94a
--- /dev/null
17b94a
+++ b/extras/ganesha/ocf/ganesha_grace
17b94a
@@ -0,0 +1,221 @@
17b94a
+#!/bin/bash
17b94a
+#
17b94a
+# Copyright (c) 2014 Anand Subramanian anands@redhat.com
17b94a
+# Copyright (c) 2015 Red Hat Inc.
17b94a
+#                    All Rights Reserved.
17b94a
+#
17b94a
+# This program is free software; you can redistribute it and/or modify
17b94a
+# it under the terms of version 2 of the GNU General Public License as
17b94a
+# published by the Free Software Foundation.
17b94a
+#
17b94a
+# This program is distributed in the hope that it would be useful, but
17b94a
+# WITHOUT ANY WARRANTY; without even the implied warranty of
17b94a
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17b94a
+#
17b94a
+# Further, this software is distributed without any warranty that it is
17b94a
+# free of the rightful claim of any third person regarding infringement
17b94a
+# or the like.  Any license provided herein, whether implied or
17b94a
+# otherwise, applies only to this software file.  Patent licenses, if
17b94a
+# any, provided herein do not apply to combinations of this program with
17b94a
+# other software, or any other product whatsoever.
17b94a
+#
17b94a
+# You should have received a copy of the GNU General Public License
17b94a
+# along with this program; if not, write the Free Software Foundation,
17b94a
+# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
17b94a
+#
17b94a
+#
17b94a
+
17b94a
+# Initialization:
17b94a
+: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
17b94a
+. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
17b94a
+
17b94a
+if [ -n "$OCF_DEBUG_LIBRARY" ]; then
17b94a
+	. $OCF_DEBUG_LIBRARY
17b94a
+else
17b94a
+	: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
17b94a
+	. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
17b94a
+fi
17b94a
+
17b94a
+OCF_RESKEY_grace_active_default="grace-active"
17b94a
+: ${OCF_RESKEY_grace_active=${OCF_RESKEY_grace_active_default}}
17b94a
+
17b94a
+ganesha_meta_data() {
17b94a
+	cat <
17b94a
+
17b94a
+
17b94a
+<resource-agent name="ganesha_grace">
17b94a
+<version>1.0</version>
17b94a
+
17b94a
+<longdesc lang="en">
17b94a
+This Linux-specific resource agent acts as a dummy
17b94a
+resource agent for nfs-ganesha.
17b94a
+</longdesc>
17b94a
+
17b94a
+<shortdesc lang="en">Manages the user-space nfs-ganesha NFS server</shortdesc>
17b94a
+
17b94a
+<parameters>
17b94a
+<parameter name="grace_active">
17b94a
+<longdesc lang="en">NFS-Ganesha grace active attribute</longdesc>
17b94a
+<shortdesc lang="en">NFS-Ganesha grace active attribute</shortdesc>
17b94a
+<content type="string" default="grace-active" />
17b94a
+</parameter>
17b94a
+</parameters>
17b94a
+
17b94a
+<actions>
17b94a
+<action name="start"   timeout="40s" />
17b94a
+<action name="stop"    timeout="40s" />
17b94a
+<action name="status"  timeout="20s" interval="60s" />
17b94a
+<action name="monitor" depth="0" timeout="10s" interval="5s" />
17b94a
+<action name="notify"  timeout="10s" />
17b94a
+<action name="meta-data"  timeout="20s" />
17b94a
+</actions>
17b94a
+</resource-agent>
17b94a
+END
17b94a
+
17b94a
+return ${OCF_SUCCESS}
17b94a
+}
17b94a
+
17b94a
+ganesha_grace_usage() {
17b94a
+	echo "ganesha.nfsd USAGE"
17b94a
+}
17b94a
+
17b94a
+# Make sure meta-data and usage always succeed
17b94a
+case $__OCF_ACTION in
17b94a
+	meta-data)	ganesha_meta_data
17b94a
+			exit ${OCF_SUCCESS}
17b94a
+			;;
17b94a
+	usage|help)	ganesha_usage
17b94a
+			exit ${OCF_SUCCESS}
17b94a
+			;;
17b94a
+	*)
17b94a
+			;;
17b94a
+esac
17b94a
+
17b94a
+ganesha_grace_start()
17b94a
+{
17b94a
+	local rc=${OCF_ERR_GENERIC}
17b94a
+	local host=$(hostname -s)
17b94a
+
17b94a
+	ocf_log debug "ganesha_grace_start()"
17b94a
+	# give ganesha_mon RA a chance to set the crm_attr first
17b94a
+	# I mislike the sleep, but it's not clear that looping
17b94a
+	# with a small sleep is necessarily better
17b94a
+	# start has a 40sec timeout, so a 5sec sleep here is okay
17b94a
+        sleep 5
17b94a
+	attr=$(crm_attribute --query --node=${host} --name=${OCF_RESKEY_grace_active} 2> /dev/null)
17b94a
+        if [ $? -ne 0 ]; then
17b94a
+		host=$(hostname)
17b94a
+		attr=$(crm_attribute --query --node=${host} --name=${OCF_RESKEY_grace_active} 2> /dev/null )
17b94a
+                if [ $? -ne 0 ]; then
17b94a
+	                ocf_log info "grace start: crm_attribute --query --node=${host} --name=${OCF_RESKEY_grace_active} failed"
17b94a
+                fi
17b94a
+        fi
17b94a
+
17b94a
+	# Three possibilities:
17b94a
+	# 1. There is no attribute at all and attr_updater returns
17b94a
+	#    a zero length string. This happens when
17b94a
+	#    ganesha_mon::monitor hasn't run at least once to set
17b94a
+	#    the attribute. The assumption here is that the system
17b94a
+	#    is coming up. We pretend, for now, that the node is
17b94a
+	#    healthy, to allow the system to continue coming up.
17b94a
+	#    It will cure itself in a few seconds
17b94a
+	# 2. There is an attribute, and it has the value "1"; this
17b94a
+	#    node is healthy.
17b94a
+	# 3. There is an attribute, but it has no value or the value
17b94a
+	#    "0"; this node is not healthy.
17b94a
+
17b94a
+	# case 1
17b94a
+	if [[ -z "${attr}" ]]; then
17b94a
+		return ${OCF_SUCCESS}
17b94a
+	fi
17b94a
+
17b94a
+	# case 2
17b94a
+	if [[ "${attr}" = *"value=1" ]]; then
17b94a
+		return ${OCF_SUCCESS}
17b94a
+	fi
17b94a
+
17b94a
+	# case 3
17b94a
+	return ${OCF_NOT_RUNNING}
17b94a
+}
17b94a
+
17b94a
+ganesha_grace_stop()
17b94a
+{
17b94a
+
17b94a
+	ocf_log debug "ganesha_grace_stop()"
17b94a
+	return ${OCF_SUCCESS}
17b94a
+}
17b94a
+
17b94a
+ganesha_grace_notify()
17b94a
+{
17b94a
+        # since this is a clone RA we should only ever see pre-start
17b94a
+        # or post-stop
17b94a
+	mode="${OCF_RESKEY_CRM_meta_notify_type}-${OCF_RESKEY_CRM_meta_notify_operation}"
17b94a
+	case "${mode}" in
17b94a
+	pre-start | post-stop)
17b94a
+		dbus-send --print-reply --system --dest=org.ganesha.nfsd /org/ganesha/nfsd/admin org.ganesha.nfsd.admin.grace string:${OCF_RESKEY_CRM_meta_notify_stop_uname}
17b94a
+		if [ $? -ne 0 ]; then
17b94a
+			ocf_log info "dbus-send --print-reply --system --dest=org.ganesha.nfsd /org/ganesha/nfsd/admin org.ganesha.nfsd.admin.grace string:${OCF_RESKEY_CRM_meta_notify_stop_uname} failed"
17b94a
+		fi
17b94a
+		;;
17b94a
+	esac
17b94a
+
17b94a
+	return ${OCF_SUCCESS}
17b94a
+}
17b94a
+
17b94a
+ganesha_grace_monitor()
17b94a
+{
17b94a
+	local host=$(hostname -s)
17b94a
+
17b94a
+	ocf_log debug "monitor"
17b94a
+
17b94a
+	attr=$(crm_attribute --query --node=${host} --name=${OCF_RESKEY_grace_active} 2> /dev/null)
17b94a
+        if [ $? -ne 0 ]; then
17b94a
+		host=$(hostname)
17b94a
+	        attr=$(crm_attribute --query --node=${host} --name=${OCF_RESKEY_grace_active} 2> /dev/null)
17b94a
+                if [ $? -ne 0 ]; then
17b94a
+	                ocf_log info "crm_attribute --query --node=${host} --name=${OCF_RESKEY_grace_active} failed"
17b94a
+                fi
17b94a
+        fi
17b94a
+
17b94a
+	# if there is no attribute (yet), maybe it's because
17b94a
+	# this RA started before ganesha_mon (nfs-mon) has had
17b94a
+	# chance to create it. In which case we'll pretend
17b94a
+	# everything is okay this time around
17b94a
+	if [[ -z "${attr}" ]]; then
17b94a
+		return ${OCF_SUCCESS}
17b94a
+	fi
17b94a
+
17b94a
+	if [[ "${attr}" = *"value=1" ]]; then
17b94a
+		return ${OCF_SUCCESS}
17b94a
+	fi
17b94a
+
17b94a
+	return ${OCF_NOT_RUNNING}
17b94a
+}
17b94a
+
17b94a
+ganesha_grace_validate()
17b94a
+{
17b94a
+	return ${OCF_SUCCESS}
17b94a
+}
17b94a
+
17b94a
+ganesha_grace_validate
17b94a
+
17b94a
+# Translate each action into the appropriate function call
17b94a
+case $__OCF_ACTION in
17b94a
+start)          ganesha_grace_start
17b94a
+		;;
17b94a
+stop)           ganesha_grace_stop
17b94a
+		;;
17b94a
+status|monitor) ganesha_grace_monitor
17b94a
+		;;
17b94a
+notify)         ganesha_grace_notify
17b94a
+		;;
17b94a
+*)              ganesha_grace_usage
17b94a
+		exit ${OCF_ERR_UNIMPLEMENTED}
17b94a
+		;;
17b94a
+esac
17b94a
+
17b94a
+rc=$?
17b94a
+
17b94a
+# The resource agent may optionally log a debug message
17b94a
+ocf_log debug "${OCF_RESOURCE_INSTANCE} ${__OCF_ACTION} returned $rc"
17b94a
+exit $rc
17b94a
diff --git a/extras/ganesha/ocf/ganesha_mon b/extras/ganesha/ocf/ganesha_mon
17b94a
new file mode 100644
17b94a
index 0000000..2b4a9d6
17b94a
--- /dev/null
17b94a
+++ b/extras/ganesha/ocf/ganesha_mon
17b94a
@@ -0,0 +1,234 @@
17b94a
+#!/bin/bash
17b94a
+#
17b94a
+# Copyright (c) 2014 Anand Subramanian anands@redhat.com
17b94a
+# Copyright (c) 2015 Red Hat Inc.
17b94a
+#                    All Rights Reserved.
17b94a
+#
17b94a
+# This program is free software; you can redistribute it and/or modify
17b94a
+# it under the terms of version 2 of the GNU General Public License as
17b94a
+# published by the Free Software Foundation.
17b94a
+#
17b94a
+# This program is distributed in the hope that it would be useful, but
17b94a
+# WITHOUT ANY WARRANTY; without even the implied warranty of
17b94a
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17b94a
+#
17b94a
+# Further, this software is distributed without any warranty that it is
17b94a
+# free of the rightful claim of any third person regarding infringement
17b94a
+# or the like.  Any license provided herein, whether implied or
17b94a
+# otherwise, applies only to this software file.  Patent licenses, if
17b94a
+# any, provided herein do not apply to combinations of this program with
17b94a
+# other software, or any other product whatsoever.
17b94a
+#
17b94a
+# You should have received a copy of the GNU General Public License
17b94a
+# along with this program; if not, write the Free Software Foundation,
17b94a
+# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
17b94a
+#
17b94a
+#
17b94a
+
17b94a
+# Initialization:
17b94a
+: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
17b94a
+. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
17b94a
+
17b94a
+if [ -n "${OCF_DEBUG_LIBRARY}" ]; then
17b94a
+	. ${OCF_DEBUG_LIBRARY}
17b94a
+else
17b94a
+	: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
17b94a
+	. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
17b94a
+fi
17b94a
+
17b94a
+# Defaults
17b94a
+OCF_RESKEY_ganesha_active_default="ganesha-active"
17b94a
+OCF_RESKEY_grace_active_default="grace-active"
17b94a
+OCF_RESKEY_grace_delay_default="5"
17b94a
+
17b94a
+: ${OCF_RESKEY_ganesha_active=${OCF_RESKEY_ganesha_active_default}}
17b94a
+: ${OCF_RESKEY_grace_active=${OCF_RESKEY_grace_active_default}}
17b94a
+: ${OCF_RESKEY_grace_delay=${OCF_RESKEY_grace_delay_default}}
17b94a
+
17b94a
+ganesha_meta_data() {
17b94a
+	cat <
17b94a
+
17b94a
+
17b94a
+<resource-agent name="ganesha_mon">
17b94a
+<version>1.0</version>
17b94a
+
17b94a
+<longdesc lang="en">
17b94a
+This Linux-specific resource agent acts as a dummy
17b94a
+resource agent for nfs-ganesha.
17b94a
+</longdesc>
17b94a
+
17b94a
+<shortdesc lang="en">Manages the user-space nfs-ganesha NFS server</shortdesc>
17b94a
+
17b94a
+<parameters>
17b94a
+<parameter name="ganesha_active">
17b94a
+<longdesc lang="en">NFS-Ganesha daemon active attribute</longdesc>
17b94a
+<shortdesc lang="en">NFS-Ganesha daemon active attribute</shortdesc>
17b94a
+<content type="string" default="ganesha-active" />
17b94a
+</parameter>
17b94a
+<parameter name="grace_active">
17b94a
+<longdesc lang="en">NFS-Ganesha grace active attribute</longdesc>
17b94a
+<shortdesc lang="en">NFS-Ganesha grace active attribute</shortdesc>
17b94a
+<content type="string" default="grace-active" />
17b94a
+</parameter>
17b94a
+<parameter name="grace_delay">
17b94a
+<longdesc lang="en">
17b94a
+NFS-Ganesha grace delay.
17b94a
+When changing this, adjust the ganesha_grace RA's monitor interval to match.
17b94a
+</longdesc>
17b94a
+<shortdesc lang="en">NFS-Ganesha grace delay</shortdesc>
17b94a
+<content type="string" default="5" />
17b94a
+</parameter>
17b94a
+</parameters>
17b94a
+
17b94a
+<actions>
17b94a
+<action name="start"   timeout="40s" />
17b94a
+<action name="stop"    timeout="40s" />
17b94a
+<action name="status"  timeout="20s" interval="60s" />
17b94a
+<action name="monitor" depth="0"  timeout="10s" interval="10s" />
17b94a
+<action name="meta-data"  timeout="20s" />
17b94a
+</actions>
17b94a
+</resource-agent>
17b94a
+END
17b94a
+
17b94a
+return ${OCF_SUCCESS}
17b94a
+}
17b94a
+
17b94a
+ganesha_mon_usage() {
17b94a
+	echo "ganesha.nfsd USAGE"
17b94a
+}
17b94a
+
17b94a
+# Make sure meta-data and usage always succeed
17b94a
+case ${__OCF_ACTION} in
17b94a
+	meta-data)	ganesha_meta_data
17b94a
+			exit ${OCF_SUCCESS}
17b94a
+			;;
17b94a
+	usage|help)	ganesha_usage
17b94a
+			exit ${OCF_SUCCESS}
17b94a
+			;;
17b94a
+	*)
17b94a
+			;;
17b94a
+esac
17b94a
+
17b94a
+ganesha_mon_start()
17b94a
+{
17b94a
+	ocf_log debug "ganesha_mon_start"
17b94a
+	ganesha_mon_monitor
17b94a
+	return $OCF_SUCCESS
17b94a
+}
17b94a
+
17b94a
+ganesha_mon_stop()
17b94a
+{
17b94a
+	ocf_log debug "ganesha_mon_stop"
17b94a
+	return $OCF_SUCCESS
17b94a
+}
17b94a
+
17b94a
+ganesha_mon_monitor()
17b94a
+{
17b94a
+	local host=$(hostname -s)
17b94a
+	local pid_file="/var/run/ganesha.pid"
17b94a
+	local rhel6_pid_file="/var/run/ganesha.nfsd.pid"
17b94a
+	local proc_pid="/proc/"
17b94a
+
17b94a
+	# RHEL6 /etc/init.d/nfs-ganesha adds -p /var/run/ganesha.nfsd.pid
17b94a
+	# RHEL7 systemd does not. Would be nice if all distros used the
17b94a
+	# same pid file.
17b94a
+	if [ -e ${rhel6_pid_file} ]; then
17b94a
+		pid_file=${rhel6_pid_file}
17b94a
+	fi
17b94a
+	if [ -e ${pid_file} ]; then
17b94a
+		proc_pid="${proc_pid}$(cat ${pid_file})"
17b94a
+	fi
17b94a
+
17b94a
+	if [ "x${proc_pid}" != "x/proc/" -a -d ${proc_pid} ]; then
17b94a
+
17b94a
+		attrd_updater -n ${OCF_RESKEY_ganesha_active} -v 1
17b94a
+		if [ $? -ne 0 ]; then
17b94a
+			ocf_log info "warning: attrd_updater -n ${OCF_RESKEY_ganesha_active} -v 1 failed"
17b94a
+		fi
17b94a
+
17b94a
+		# ganesha_grace (nfs-grace) RA follows grace-active attr
17b94a
+		# w/ constraint location
17b94a
+		attrd_updater -n ${OCF_RESKEY_grace_active} -v 1
17b94a
+		if [ $? -ne 0 ]; then
17b94a
+			ocf_log info "warning: attrd_updater -n ${OCF_RESKEY_grace_active} -v 1 failed"
17b94a
+		fi
17b94a
+
17b94a
+		# ganesha_mon (nfs-mon) and ganesha_grace (nfs-grace)
17b94a
+		# track grace-active crm_attr (attr != crm_attr)
17b94a
+		# we can't just use the attr as there's no way to query
17b94a
+		# its value in RHEL6 pacemaker
17b94a
+
17b94a
+		crm_attribute --node=${host} --lifetime=forever --name=${OCF_RESKEY_grace_active} --update=1 2> /dev/null
17b94a
+		if [ $? -ne 0 ]; then
17b94a
+			host=$(hostname)
17b94a
+			crm_attribute --node=${host} --lifetime=forever --name=${OCF_RESKEY_grace_active} --update=1 2> /dev/null
17b94a
+			if [ $? -ne 0 ]; then
17b94a
+				ocf_log info "mon monitor warning: crm_attribute --node=${host} --lifetime=forever --name=${OCF_RESKEY_grace_active} --update=1 failed"
17b94a
+			fi
17b94a
+		fi
17b94a
+
17b94a
+		return ${OCF_SUCCESS}
17b94a
+	fi
17b94a
+
17b94a
+	# VIP fail-over is triggered by clearing the
17b94a
+	# ganesha-active node attribute on this node.
17b94a
+	#
17b94a
+	# Meanwhile the ganesha_grace notify() runs when its
17b94a
+	# nfs-grace resource is disabled on a node; which
17b94a
+	# is triggered by clearing the grace-active attribute
17b94a
+	# on this node.
17b94a
+	#
17b94a
+	# We need to allow time for it to run and put
17b94a
+	# the remaining ganesha.nfsds into grace before
17b94a
+	# initiating the VIP fail-over.
17b94a
+
17b94a
+	attrd_updater -D -n ${OCF_RESKEY_grace_active}
17b94a
+	if [ $? -ne 0 ]; then
17b94a
+		ocf_log info "warning: attrd_updater -D -n ${OCF_RESKEY_grace_active} failed"
17b94a
+	fi
17b94a
+
17b94a
+	host=$(hostname -s)
17b94a
+	crm_attribute --node=${host} --name=${OCF_RESKEY_grace_active} --update=0 2> /dev/null
17b94a
+	if [ $? -ne 0 ]; then
17b94a
+		host=$(hostname)
17b94a
+		crm_attribute --node=${host} --name=${OCF_RESKEY_grace_active} --update=0 2> /dev/null
17b94a
+		if [ $? -ne 0 ]; then
17b94a
+			ocf_log info "mon monitor warning: crm_attribute --node=${host} --name=${OCF_RESKEY_grace_active} --update=0 failed"
17b94a
+		fi
17b94a
+	fi
17b94a
+
17b94a
+	sleep ${OCF_RESKEY_grace_delay}
17b94a
+
17b94a
+	attrd_updater -D -n ${OCF_RESKEY_ganesha_active}
17b94a
+	if [ $? -ne 0 ]; then
17b94a
+		ocf_log info "warning: attrd_updater -D -n ${OCF_RESKEY_ganesha_active} failed"
17b94a
+	fi
17b94a
+
17b94a
+	return ${OCF_SUCCESS}
17b94a
+}
17b94a
+
17b94a
+ganesha_mon_validate()
17b94a
+{
17b94a
+	return ${OCF_SUCCESS}
17b94a
+}
17b94a
+
17b94a
+ganesha_mon_validate
17b94a
+
17b94a
+# Translate each action into the appropriate function call
17b94a
+case ${__OCF_ACTION} in
17b94a
+start)          ganesha_mon_start
17b94a
+		;;
17b94a
+stop)           ganesha_mon_stop
17b94a
+		;;
17b94a
+status|monitor) ganesha_mon_monitor
17b94a
+		;;
17b94a
+*)              ganesha_mon_usage
17b94a
+		exit ${OCF_ERR_UNIMPLEMENTED}
17b94a
+		;;
17b94a
+esac
17b94a
+
17b94a
+rc=$?
17b94a
+
17b94a
+# The resource agent may optionally log a debug message
17b94a
+ocf_log debug "${OCF_RESOURCE_INSTANCE} ${__OCF_ACTION} returned $rc"
17b94a
+exit $rc
17b94a
diff --git a/extras/ganesha/ocf/ganesha_nfsd b/extras/ganesha/ocf/ganesha_nfsd
17b94a
new file mode 100644
17b94a
index 0000000..93fc8be
17b94a
--- /dev/null
17b94a
+++ b/extras/ganesha/ocf/ganesha_nfsd
17b94a
@@ -0,0 +1,167 @@
17b94a
+#!/bin/bash
17b94a
+#
17b94a
+# Copyright (c) 2014 Anand Subramanian anands@redhat.com
17b94a
+# Copyright (c) 2015 Red Hat Inc.
17b94a
+#                    All Rights Reserved.
17b94a
+#
17b94a
+# This program is free software; you can redistribute it and/or modify
17b94a
+# it under the terms of version 2 of the GNU General Public License as
17b94a
+# published by the Free Software Foundation.
17b94a
+#
17b94a
+# This program is distributed in the hope that it would be useful, but
17b94a
+# WITHOUT ANY WARRANTY; without even the implied warranty of
17b94a
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17b94a
+#
17b94a
+# Further, this software is distributed without any warranty that it is
17b94a
+# free of the rightful claim of any third person regarding infringement
17b94a
+# or the like.  Any license provided herein, whether implied or
17b94a
+# otherwise, applies only to this software file.  Patent licenses, if
17b94a
+# any, provided herein do not apply to combinations of this program with
17b94a
+# other software, or any other product whatsoever.
17b94a
+#
17b94a
+# You should have received a copy of the GNU General Public License
17b94a
+# along with this program; if not, write the Free Software Foundation,
17b94a
+# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
17b94a
+#
17b94a
+#
17b94a
+
17b94a
+# Initialization:
17b94a
+: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
17b94a
+. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
17b94a
+
17b94a
+if [ -n "${OCF_DEBUG_LIBRARY}" ]; then
17b94a
+	. ${OCF_DEBUG_LIBRARY}
17b94a
+else
17b94a
+	: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
17b94a
+	. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
17b94a
+fi
17b94a
+
17b94a
+OCF_RESKEY_ha_vol_mnt_default="/var/run/gluster/shared_storage"
17b94a
+: ${OCF_RESKEY_ha_vol_mnt=${OCF_RESKEY_ha_vol_mnt_default}}
17b94a
+
17b94a
+ganesha_meta_data() {
17b94a
+	cat <
17b94a
+
17b94a
+
17b94a
+<resource-agent name="ganesha_nfsd">
17b94a
+<version>1.0</version>
17b94a
+
17b94a
+<longdesc lang="en">
17b94a
+This Linux-specific resource agent acts as a dummy
17b94a
+resource agent for nfs-ganesha.
17b94a
+</longdesc>
17b94a
+
17b94a
+<shortdesc lang="en">Manages the user-space nfs-ganesha NFS server</shortdesc>
17b94a
+
17b94a
+<parameters>
17b94a
+<parameter name="ha_vol_mnt">
17b94a
+<longdesc lang="en">HA State Volume Mount Point</longdesc>
17b94a
+<shortdesc lang="en">HA_State Volume Mount Point</shortdesc>
17b94a
+<content type="string" default="" />
17b94a
+</parameter>
17b94a
+</parameters>
17b94a
+
17b94a
+<actions>
17b94a
+<action name="start"   timeout="5s" />
17b94a
+<action name="stop"    timeout="5s" />
17b94a
+<action name="status" depth="0"  timeout="5s" interval="0" />
17b94a
+<action name="monitor" depth="0"  timeout="5s" interval="0" />
17b94a
+<action name="meta-data"  timeout="20s" />
17b94a
+</actions>
17b94a
+</resource-agent>
17b94a
+END
17b94a
+
17b94a
+return ${OCF_SUCCESS}
17b94a
+}
17b94a
+
17b94a
+ganesha_nfsd_usage() {
17b94a
+	echo "ganesha.nfsd USAGE"
17b94a
+}
17b94a
+
17b94a
+# Make sure meta-data and usage always succeed
17b94a
+case $__OCF_ACTION in
17b94a
+	meta-data)	ganesha_meta_data
17b94a
+			exit ${OCF_SUCCESS}
17b94a
+			;;
17b94a
+	usage|help)	ganesha_usage
17b94a
+			exit ${OCF_SUCCESS}
17b94a
+			;;
17b94a
+	*)
17b94a
+			;;
17b94a
+esac
17b94a
+
17b94a
+ganesha_nfsd_start()
17b94a
+{
17b94a
+	local long_host=$(hostname)
17b94a
+
17b94a
+	if [[ -d /var/lib/nfs ]]; then
17b94a
+		mv /var/lib/nfs /var/lib/nfs.backup
17b94a
+		if [ $? -ne 0 ]; then
17b94a
+			ocf_log notice "mv /var/lib/nfs /var/lib/nfs.backup failed"
17b94a
+		fi
17b94a
+		ln -s ${OCF_RESKEY_ha_vol_mnt}/nfs-ganesha/${long_host}/nfs /var/lib/nfs
17b94a
+		if [ $? -ne 0 ]; then
17b94a
+			ocf_log notice "ln -s ${OCF_RESKEY_ha_vol_mnt}/nfs-ganesha/${long_host}/nfs /var/lib/nfs failed"
17b94a
+		fi
17b94a
+	fi
17b94a
+
17b94a
+	return ${OCF_SUCCESS}
17b94a
+}
17b94a
+
17b94a
+ganesha_nfsd_stop()
17b94a
+{
17b94a
+
17b94a
+	if [ -L /var/lib/nfs -a -d /var/lib/nfs.backup ]; then
17b94a
+		rm -f /var/lib/nfs
17b94a
+		if [ $? -ne 0 ]; then
17b94a
+			ocf_log notice "rm -f /var/lib/nfs failed"
17b94a
+		fi
17b94a
+		mv /var/lib/nfs.backup /var/lib/nfs
17b94a
+		if [ $? -ne 0 ]; then
17b94a
+			ocf_log notice "mv /var/lib/nfs.backup /var/lib/nfs failed"
17b94a
+		fi
17b94a
+	fi
17b94a
+
17b94a
+	return ${OCF_SUCCESS}
17b94a
+}
17b94a
+
17b94a
+ganesha_nfsd_monitor()
17b94a
+{
17b94a
+	# pacemaker checks to see if RA is already running before starting it.
17b94a
+	# if we return success, then it's presumed it's already running and
17b94a
+	# doesn't need to be started, i.e. invoke the start action.
17b94a
+	# return something other than success to make pacemaker invoke the
17b94a
+	# start action
17b94a
+	if [[ -L /var/lib/nfs ]]; then
17b94a
+		return ${OCF_SUCCESS}
17b94a
+	fi
17b94a
+	return ${OCF_NOT_RUNNING}
17b94a
+}
17b94a
+
17b94a
+ganesha_nfsd_validate()
17b94a
+{
17b94a
+	return ${OCF_SUCCESS}
17b94a
+}
17b94a
+
17b94a
+ganesha_nfsd_validate
17b94a
+
17b94a
+# ocf_log notice "ganesha_nfsd ${OCF_RESOURCE_INSTANCE} $__OCF_ACTION"
17b94a
+
17b94a
+# Translate each action into the appropriate function call
17b94a
+case $__OCF_ACTION in
17b94a
+start)          ganesha_nfsd_start
17b94a
+		;;
17b94a
+stop)           ganesha_nfsd_stop
17b94a
+		;;
17b94a
+status|monitor) ganesha_nfsd_monitor
17b94a
+		;;
17b94a
+*)              ganesha_nfsd_usage
17b94a
+		exit ${OCF_ERR_UNIMPLEMENTED}
17b94a
+		;;
17b94a
+esac
17b94a
+
17b94a
+rc=$?
17b94a
+
17b94a
+# The resource agent may optionally log a debug message
17b94a
+ocf_log debug "${OCF_RESOURCE_INSTANCE} ${__OCF_ACTION} returned $rc"
17b94a
+exit $rc
17b94a
diff --git a/extras/ganesha/scripts/Makefile.am b/extras/ganesha/scripts/Makefile.am
17b94a
index 00a2c45..7e345fd 100644
17b94a
--- a/extras/ganesha/scripts/Makefile.am
17b94a
+++ b/extras/ganesha/scripts/Makefile.am
17b94a
@@ -1,4 +1,6 @@
17b94a
-EXTRA_DIST= create-export-ganesha.sh generate-epoch.py dbus-send.sh
17b94a
+EXTRA_DIST= create-export-ganesha.sh generate-epoch.py dbus-send.sh \
17b94a
+			ganesha-ha.sh
17b94a
 
17b94a
 scriptsdir = $(libexecdir)/ganesha
17b94a
-scripts_SCRIPTS = create-export-ganesha.sh dbus-send.sh generate-epoch.py
17b94a
+scripts_SCRIPTS = create-export-ganesha.sh dbus-send.sh generate-epoch.py \
17b94a
+				  ganesha-ha.sh
17b94a
diff --git a/extras/ganesha/scripts/ganesha-ha.sh b/extras/ganesha/scripts/ganesha-ha.sh
17b94a
new file mode 100644
17b94a
index 0000000..6b011be
17b94a
--- /dev/null
17b94a
+++ b/extras/ganesha/scripts/ganesha-ha.sh
17b94a
@@ -0,0 +1,1125 @@
17b94a
+#!/bin/bash
17b94a
+
17b94a
+# Copyright 2015-2016 Red Hat Inc.  All Rights Reserved
17b94a
+#
17b94a
+# Pacemaker+Corosync High Availability for NFS-Ganesha
17b94a
+#
17b94a
+# setup, teardown, add, delete, refresh-config, and status
17b94a
+#
17b94a
+# Each participating node in the cluster is assigned a virtual IP (VIP)
17b94a
+# which fails over to another node when its associated ganesha.nfsd dies
17b94a
+# for any reason. After the VIP is moved to another node all the
17b94a
+# ganesha.nfsds are send a signal using DBUS to put them into NFS GRACE.
17b94a
+#
17b94a
+# There are six resource agent types used: ganesha_mon, ganesha_grace,
17b94a
+# ganesha_nfsd, IPaddr, and Dummy. ganesha_mon is used to monitor the
17b94a
+# ganesha.nfsd. ganesha_grace is used to send the DBUS signal to put
17b94a
+# the remaining ganesha.nfsds into grace. ganesha_nfsd is used to start
17b94a
+# and stop the ganesha.nfsd during setup and teardown. IPaddr manages
17b94a
+# the VIP. A Dummy resource named $hostname-trigger_ip-1 is used to
17b94a
+# ensure that the NFS GRACE DBUS signal is sent after the VIP moves to
17b94a
+# the new host.
17b94a
+
17b94a
+HA_NUM_SERVERS=0
17b94a
+HA_SERVERS=""
17b94a
+HA_VOL_NAME="gluster_shared_storage"
17b94a
+HA_VOL_MNT="/var/run/gluster/shared_storage"
17b94a
+HA_CONFDIR=$HA_VOL_MNT"/nfs-ganesha"
17b94a
+SERVICE_MAN="DISTRO_NOT_FOUND"
17b94a
+
17b94a
+RHEL6_PCS_CNAME_OPTION="--name"
17b94a
+SECRET_PEM="/var/lib/glusterd/nfs/secret.pem"
17b94a
+
17b94a
+# UNBLOCK RA uses shared_storage which may become unavailable
17b94a
+# during any of the nodes reboot. Hence increase timeout value.
17b94a
+PORTBLOCK_UNBLOCK_TIMEOUT="60s"
17b94a
+
17b94a
+# Try loading the config from any of the distro
17b94a
+# specific configuration locations
17b94a
+if [ -f /etc/sysconfig/ganesha ]
17b94a
+        then
17b94a
+        . /etc/sysconfig/ganesha
17b94a
+fi
17b94a
+if [ -f /etc/conf.d/ganesha ]
17b94a
+        then
17b94a
+        . /etc/conf.d/ganesha
17b94a
+fi
17b94a
+if [ -f /etc/default/ganesha ]
17b94a
+        then
17b94a
+        . /etc/default/ganesha
17b94a
+fi
17b94a
+
17b94a
+GANESHA_CONF=
17b94a
+
17b94a
+function find_rhel7_conf
17b94a
+{
17b94a
+ while [[ $# > 0 ]]
17b94a
+        do
17b94a
+                key="$1"
17b94a
+                case $key in
17b94a
+                        -f)
17b94a
+                         CONFFILE="$2"
17b94a
+                         break;
17b94a
+                         ;;
17b94a
+                         *)
17b94a
+                         ;;
17b94a
+                 esac
17b94a
+                 shift
17b94a
+         done
17b94a
+}
17b94a
+
17b94a
+if [ -z $CONFFILE ]
17b94a
+        then
17b94a
+        find_rhel7_conf $OPTIONS
17b94a
+
17b94a
+fi
17b94a
+
17b94a
+GANESHA_CONF=${CONFFILE:-/etc/ganesha/ganesha.conf}
17b94a
+
17b94a
+usage() {
17b94a
+
17b94a
+        echo "Usage      : add|delete|refresh-config|status"
17b94a
+        echo "Add-node   : ganesha-ha.sh --add <HA_CONF_DIR> \
17b94a
+<NODE-HOSTNAME>  <NODE-VIP>"
17b94a
+        echo "Delete-node: ganesha-ha.sh --delete <HA_CONF_DIR> \
17b94a
+<NODE-HOSTNAME>"
17b94a
+        echo "Refresh-config : ganesha-ha.sh --refresh-config <HA_CONFDIR> \
17b94a
+<volume>"
17b94a
+        echo "Status : ganesha-ha.sh --status <HA_CONFDIR>"
17b94a
+}
17b94a
+
17b94a
+determine_service_manager () {
17b94a
+
17b94a
+        if [ -e "/usr/bin/systemctl" ];
17b94a
+        then
17b94a
+                SERVICE_MAN="/usr/bin/systemctl"
17b94a
+        elif [ -e "/sbin/invoke-rc.d" ];
17b94a
+        then
17b94a
+                SERVICE_MAN="/sbin/invoke-rc.d"
17b94a
+        elif [ -e "/sbin/service" ];
17b94a
+        then
17b94a
+                SERVICE_MAN="/sbin/service"
17b94a
+        fi
17b94a
+        if [ "$SERVICE_MAN" == "DISTRO_NOT_FOUND" ]
17b94a
+        then
17b94a
+                echo "Service manager not recognized, exiting"
17b94a
+                exit 1
17b94a
+        fi
17b94a
+}
17b94a
+
17b94a
+manage_service ()
17b94a
+{
17b94a
+        local action=${1}
17b94a
+        local new_node=${2}
17b94a
+        local option=
17b94a
+
17b94a
+        if [ "$action" == "start" ]; then
17b94a
+                option="yes"
17b94a
+        else
17b94a
+                option="no"
17b94a
+        fi
17b94a
+        ssh -oPasswordAuthentication=no -oStrictHostKeyChecking=no -i \
17b94a
+${SECRET_PEM} root@${new_node} "/usr/libexec/ganesha/ganesha-ha.sh --setup-ganesha-conf-files $HA_CONFDIR $option"
17b94a
+
17b94a
+        if [ "$SERVICE_MAN" == "/usr/bin/systemctl" ]
17b94a
+        then
17b94a
+                ssh -oPasswordAuthentication=no -oStrictHostKeyChecking=no -i \
17b94a
+${SECRET_PEM} root@${new_node} "$SERVICE_MAN  ${action} nfs-ganesha"
17b94a
+        else
17b94a
+                ssh -oPasswordAuthentication=no -oStrictHostKeyChecking=no -i \
17b94a
+${SECRET_PEM} root@${new_node} "$SERVICE_MAN nfs-ganesha ${action}"
17b94a
+        fi
17b94a
+}
17b94a
+
17b94a
+
17b94a
+check_cluster_exists()
17b94a
+{
17b94a
+    local name=${1}
17b94a
+    local cluster_name=""
17b94a
+
17b94a
+    if [ -e /var/run/corosync.pid ]; then
17b94a
+        cluster_name=$(pcs status | grep "Cluster name:" | cut -d ' ' -f 3)
17b94a
+        if [ ${cluster_name} -a ${cluster_name} = ${name} ]; then
17b94a
+            logger "$name already exists, exiting"
17b94a
+            exit 0
17b94a
+        fi
17b94a
+    fi
17b94a
+}
17b94a
+
17b94a
+
17b94a
+determine_servers()
17b94a
+{
17b94a
+    local cmd=${1}
17b94a
+    local num_servers=0
17b94a
+    local tmp_ifs=${IFS}
17b94a
+    local ha_servers=""
17b94a
+
17b94a
+    if [ "X${cmd}X" != "XsetupX" -a "X${cmd}X" != "XstatusX" ]; then
17b94a
+        ha_servers=$(pcs status | grep "Online:" | grep -o '\[.*\]' | sed -e 's/\[//' | sed -e 's/\]//')
17b94a
+        IFS=$' '
17b94a
+        for server in ${ha_servers} ; do
17b94a
+            num_servers=$(expr ${num_servers} + 1)
17b94a
+        done
17b94a
+        IFS=${tmp_ifs}
17b94a
+        HA_NUM_SERVERS=${num_servers}
17b94a
+        HA_SERVERS="${ha_servers}"
17b94a
+    else
17b94a
+        IFS=$','
17b94a
+        for server in ${HA_CLUSTER_NODES} ; do
17b94a
+            num_servers=$(expr ${num_servers} + 1)
17b94a
+        done
17b94a
+        IFS=${tmp_ifs}
17b94a
+        HA_NUM_SERVERS=${num_servers}
17b94a
+        HA_SERVERS="${HA_CLUSTER_NODES//,/ }"
17b94a
+    fi
17b94a
+}
17b94a
+
17b94a
+
17b94a
+setup_cluster()
17b94a
+{
17b94a
+    local name=${1}
17b94a
+    local num_servers=${2}
17b94a
+    local servers=${3}
17b94a
+    local unclean=""
17b94a
+    local quorum_policy="stop"
17b94a
+
17b94a
+    logger "setting up cluster ${name} with the following ${servers}"
17b94a
+
17b94a
+    pcs cluster auth ${servers}
17b94a
+    # pcs cluster setup --name ${name} ${servers}
17b94a
+    pcs cluster setup ${RHEL6_PCS_CNAME_OPTION} ${name} --transport udpu ${servers}
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "pcs cluster setup ${RHEL6_PCS_CNAME_OPTION} ${name} ${servers} failed"
17b94a
+        exit 1;
17b94a
+    fi
17b94a
+    pcs cluster start --all
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "pcs cluster start failed"
17b94a
+        exit 1;
17b94a
+    fi
17b94a
+
17b94a
+    sleep 1
17b94a
+    # wait for the cluster to elect a DC before querying or writing
17b94a
+    # to the CIB. BZ 1334092
17b94a
+    crmadmin --dc_lookup --timeout=5000 > /dev/null 2>&1
17b94a
+    while [ $? -ne 0 ]; do
17b94a
+        crmadmin --dc_lookup --timeout=5000 > /dev/null 2>&1
17b94a
+    done
17b94a
+
17b94a
+    unclean=$(pcs status | grep -u "UNCLEAN")
17b94a
+    while [[ "${unclean}X" = "UNCLEANX" ]]; do
17b94a
+         sleep 1
17b94a
+         unclean=$(pcs status | grep -u "UNCLEAN")
17b94a
+    done
17b94a
+    sleep 1
17b94a
+
17b94a
+    if [ ${num_servers} -lt 3 ]; then
17b94a
+        quorum_policy="ignore"
17b94a
+    fi
17b94a
+    pcs property set no-quorum-policy=${quorum_policy}
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "warning: pcs property set no-quorum-policy=${quorum_policy} failed"
17b94a
+    fi
17b94a
+
17b94a
+    pcs property set stonith-enabled=false
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "warning: pcs property set stonith-enabled=false failed"
17b94a
+    fi
17b94a
+}
17b94a
+
17b94a
+
17b94a
+setup_finalize_ha()
17b94a
+{
17b94a
+    local cibfile=${1}
17b94a
+    local stopped=""
17b94a
+
17b94a
+    stopped=$(pcs status | grep -u "Stopped")
17b94a
+    while [[ "${stopped}X" = "StoppedX" ]]; do
17b94a
+         sleep 1
17b94a
+         stopped=$(pcs status | grep -u "Stopped")
17b94a
+    done
17b94a
+}
17b94a
+
17b94a
+
17b94a
+refresh_config ()
17b94a
+{
17b94a
+        local short_host=$(hostname -s)
17b94a
+        local VOL=${1}
17b94a
+        local HA_CONFDIR=${2}
17b94a
+        local short_host=$(hostname -s)
17b94a
+
17b94a
+        local export_id=$(grep ^[[:space:]]*Export_Id $HA_CONFDIR/exports/export.$VOL.conf |\
17b94a
+                          awk -F"[=,;]" '{print $2}' | tr -d '[[:space:]]')
17b94a
+
17b94a
+
17b94a
+        if [ -e ${SECRET_PEM} ]; then
17b94a
+        while [[ ${3} ]]; do
17b94a
+            current_host=`echo ${3} | cut -d "." -f 1`
17b94a
+            if [ ${short_host} != ${current_host} ]; then
17b94a
+                output=$(ssh -oPasswordAuthentication=no \
17b94a
+-oStrictHostKeyChecking=no -i ${SECRET_PEM} root@${current_host} \
17b94a
+"dbus-send --print-reply --system --dest=org.ganesha.nfsd \
17b94a
+/org/ganesha/nfsd/ExportMgr org.ganesha.nfsd.exportmgr.UpdateExport \
17b94a
+string:$HA_CONFDIR/exports/export.$VOL.conf \
17b94a
+string:\"EXPORT(Export_Id=$export_id)\" 2>&1")
17b94a
+                ret=$?
17b94a
+                logger <<< "${output}"
17b94a
+                if [ ${ret} -ne 0 ]; then
17b94a
+                        echo "Error: refresh-config failed on ${current_host}."
17b94a
+                        exit 1
17b94a
+                else
17b94a
+                        echo "Refresh-config completed on ${current_host}."
17b94a
+                fi
17b94a
+
17b94a
+          fi
17b94a
+          shift
17b94a
+        done
17b94a
+    else
17b94a
+        echo "Error: refresh-config failed. Passwordless ssh is not enabled."
17b94a
+        exit 1
17b94a
+    fi
17b94a
+
17b94a
+    # Run the same command on the localhost,
17b94a
+        output=$(dbus-send --print-reply --system --dest=org.ganesha.nfsd \
17b94a
+/org/ganesha/nfsd/ExportMgr org.ganesha.nfsd.exportmgr.UpdateExport \
17b94a
+string:$HA_CONFDIR/exports/export.$VOL.conf \
17b94a
+string:"EXPORT(Export_Id=$export_id)" 2>&1)
17b94a
+        ret=$?
17b94a
+        logger <<< "${output}"
17b94a
+        if [ ${ret} -ne 0 ] ; then
17b94a
+                echo "Error: refresh-config failed on localhost."
17b94a
+                exit 1
17b94a
+        else
17b94a
+                echo "Success: refresh-config completed."
17b94a
+        fi
17b94a
+}
17b94a
+
17b94a
+
17b94a
+teardown_cluster()
17b94a
+{
17b94a
+    local name=${1}
17b94a
+
17b94a
+    for server in ${HA_SERVERS} ; do
17b94a
+        if [[ ${HA_CLUSTER_NODES} != *${server}* ]]; then
17b94a
+            logger "info: ${server} is not in config, removing"
17b94a
+
17b94a
+            pcs cluster stop ${server} --force
17b94a
+            if [ $? -ne 0 ]; then
17b94a
+                logger "warning: pcs cluster stop ${server} failed"
17b94a
+            fi
17b94a
+
17b94a
+            pcs cluster node remove ${server}
17b94a
+            if [ $? -ne 0 ]; then
17b94a
+                logger "warning: pcs cluster node remove ${server} failed"
17b94a
+            fi
17b94a
+        fi
17b94a
+    done
17b94a
+
17b94a
+    # BZ 1193433 - pcs doesn't reload cluster.conf after modification
17b94a
+    # after teardown completes, a subsequent setup will appear to have
17b94a
+    # 'remembered' the deleted node. You can work around this by
17b94a
+    # issuing another `pcs cluster node remove $node`,
17b94a
+    # `crm_node -f -R $server`, or
17b94a
+    # `cibadmin --delete --xml-text '
17b94a
+    # uname="$server"/>'
17b94a
+
17b94a
+    pcs cluster stop --all
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "warning pcs cluster stop --all failed"
17b94a
+    fi
17b94a
+
17b94a
+    pcs cluster destroy
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "error pcs cluster destroy failed"
17b94a
+        exit 1
17b94a
+    fi
17b94a
+}
17b94a
+
17b94a
+
17b94a
+cleanup_ganesha_config ()
17b94a
+{
17b94a
+    rm -f /etc/corosync/corosync.conf
17b94a
+    rm -rf /etc/cluster/cluster.conf*
17b94a
+    rm -rf /var/lib/pacemaker/cib/*
17b94a
+}
17b94a
+
17b94a
+do_create_virt_ip_constraints()
17b94a
+{
17b94a
+    local cibfile=${1}; shift
17b94a
+    local primary=${1}; shift
17b94a
+    local weight="1000"
17b94a
+
17b94a
+    # first a constraint location rule that says the VIP must be where
17b94a
+    # there's a ganesha.nfsd running
17b94a
+    pcs -f ${cibfile} constraint location ${primary}-group rule score=-INFINITY ganesha-active ne 1
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "warning: pcs constraint location ${primary}-group rule score=-INFINITY ganesha-active ne 1 failed"
17b94a
+    fi
17b94a
+
17b94a
+    # then a set of constraint location prefers to set the prefered order
17b94a
+    # for where a VIP should move
17b94a
+    while [[ ${1} ]]; do
17b94a
+        pcs -f ${cibfile} constraint location ${primary}-group prefers ${1}=${weight}
17b94a
+        if [ $? -ne 0 ]; then
17b94a
+            logger "warning: pcs constraint location ${primary}-group prefers ${1}=${weight} failed"
17b94a
+        fi
17b94a
+        weight=$(expr ${weight} + 1000)
17b94a
+        shift
17b94a
+    done
17b94a
+    # and finally set the highest preference for the VIP to its home node
17b94a
+    # default weight when created is/was 100.
17b94a
+    # on Fedora setting appears to be additive, so to get the desired
17b94a
+    # value we adjust the weight
17b94a
+    # weight=$(expr ${weight} - 100)
17b94a
+    pcs -f ${cibfile} constraint location ${primary}-group prefers ${primary}=${weight}
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "warning: pcs constraint location ${primary}-group prefers ${primary}=${weight} failed"
17b94a
+    fi
17b94a
+}
17b94a
+
17b94a
+
17b94a
+wrap_create_virt_ip_constraints()
17b94a
+{
17b94a
+    local cibfile=${1}; shift
17b94a
+    local primary=${1}; shift
17b94a
+    local head=""
17b94a
+    local tail=""
17b94a
+
17b94a
+    # build a list of peers, e.g. for a four node cluster, for node1,
17b94a
+    # the result is "node2 node3 node4"; for node2, "node3 node4 node1"
17b94a
+    # and so on.
17b94a
+    while [[ ${1} ]]; do
17b94a
+        if [ "${1}" = "${primary}" ]; then
17b94a
+            shift
17b94a
+            while [[ ${1} ]]; do
17b94a
+                tail=${tail}" "${1}
17b94a
+                shift
17b94a
+            done
17b94a
+        else
17b94a
+            head=${head}" "${1}
17b94a
+        fi
17b94a
+        shift
17b94a
+    done
17b94a
+    do_create_virt_ip_constraints ${cibfile} ${primary} ${tail} ${head}
17b94a
+}
17b94a
+
17b94a
+
17b94a
+create_virt_ip_constraints()
17b94a
+{
17b94a
+    local cibfile=${1}; shift
17b94a
+
17b94a
+    while [[ ${1} ]]; do
17b94a
+        wrap_create_virt_ip_constraints ${cibfile} ${1} ${HA_SERVERS}
17b94a
+        shift
17b94a
+    done
17b94a
+}
17b94a
+
17b94a
+
17b94a
+setup_create_resources()
17b94a
+{
17b94a
+    local cibfile=$(mktemp -u)
17b94a
+
17b94a
+    # fixup /var/lib/nfs
17b94a
+    logger "pcs resource create nfs_setup ocf:heartbeat:ganesha_nfsd ha_vol_mnt=${HA_VOL_MNT} --clone"
17b94a
+    pcs resource create nfs_setup ocf:heartbeat:ganesha_nfsd ha_vol_mnt=${HA_VOL_MNT} --clone
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "warning: pcs resource create nfs_setup ocf:heartbeat:ganesha_nfsd ha_vol_mnt=${HA_VOL_MNT} --clone failed"
17b94a
+    fi
17b94a
+
17b94a
+    pcs resource create nfs-mon ocf:heartbeat:ganesha_mon --clone
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "warning: pcs resource create nfs-mon ocf:heartbeat:ganesha_mon --clone failed"
17b94a
+    fi
17b94a
+
17b94a
+    # see comment in (/usr/lib/ocf/resource.d/heartbeat/ganesha_grace
17b94a
+    # start method. Allow time for ganesha_mon to start and set the
17b94a
+    # ganesha-active crm_attribute
17b94a
+    sleep 5
17b94a
+
17b94a
+    pcs resource create nfs-grace ocf:heartbeat:ganesha_grace --clone meta notify=true
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "warning: pcs resource create nfs-grace ocf:heartbeat:ganesha_grace --clone failed"
17b94a
+    fi
17b94a
+
17b94a
+    pcs constraint location nfs-grace-clone rule score=-INFINITY grace-active ne 1
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "warning: pcs constraint location nfs-grace-clone rule score=-INFINITY grace-active ne 1"
17b94a
+    fi
17b94a
+
17b94a
+    pcs cluster cib ${cibfile}
17b94a
+
17b94a
+    while [[ ${1} ]]; do
17b94a
+
17b94a
+        # this is variable indirection
17b94a
+        # from a nvs like 'VIP_host1=10.7.6.5' or 'VIP_host1="10.7.6.5"'
17b94a
+        # (or VIP_host-1=..., or VIP_host-1.my.domain.name=...)
17b94a
+        # a variable 'clean_name' is created (e.g. w/ value 'VIP_host_1')
17b94a
+        # and a clean nvs (e.g. w/ value 'VIP_host_1="10_7_6_5"')
17b94a
+        # after the `eval ${clean_nvs}` there is a variable VIP_host_1
17b94a
+        # with the value '10_7_6_5', and the following \$$ magic to
17b94a
+        # reference it, i.e. `eval tmp_ipaddr=\$${clean_name}` gives us
17b94a
+        # ${tmp_ipaddr} with 10_7_6_5 and then convert the _s back to .s
17b94a
+        # to give us ipaddr="10.7.6.5". whew!
17b94a
+        name="VIP_${1}"
17b94a
+        clean_name=${name//[-.]/_}
17b94a
+        nvs=$(grep "^${name}=" ${HA_CONFDIR}/ganesha-ha.conf)
17b94a
+        clean_nvs=${nvs//[-.]/_}
17b94a
+        eval ${clean_nvs}
17b94a
+        eval tmp_ipaddr=\$${clean_name}
17b94a
+        ipaddr=${tmp_ipaddr//_/.}
17b94a
+
17b94a
+        pcs -f ${cibfile} resource create ${1}-nfs_block ocf:heartbeat:portblock protocol=tcp \
17b94a
+        portno=2049 action=block ip=${ipaddr} --group ${1}-group
17b94a
+        if [ $? -ne 0 ]; then
17b94a
+            logger "warning pcs resource create ${1}-nfs_block failed"
17b94a
+        fi
17b94a
+        pcs -f ${cibfile} resource create ${1}-cluster_ip-1 ocf:heartbeat:IPaddr ip=${ipaddr} \
17b94a
+        cidr_netmask=32 op monitor interval=15s --group ${1}-group --after ${1}-nfs_block
17b94a
+        if [ $? -ne 0 ]; then
17b94a
+            logger "warning pcs resource create ${1}-cluster_ip-1 ocf:heartbeat:IPaddr ip=${ipaddr} \
17b94a
+            cidr_netmask=32 op monitor interval=15s failed"
17b94a
+        fi
17b94a
+
17b94a
+        pcs -f ${cibfile} constraint order nfs-grace-clone then ${1}-cluster_ip-1
17b94a
+        if [ $? -ne 0 ]; then
17b94a
+            logger "warning: pcs constraint order nfs-grace-clone then ${1}-cluster_ip-1 failed"
17b94a
+        fi
17b94a
+
17b94a
+        pcs -f ${cibfile} resource create ${1}-nfs_unblock ocf:heartbeat:portblock protocol=tcp \
17b94a
+        portno=2049 action=unblock ip=${ipaddr} reset_local_on_unblock_stop=true \
17b94a
+        tickle_dir=${HA_VOL_MNT}/nfs-ganesha/tickle_dir/ --group ${1}-group --after ${1}-cluster_ip-1 \
17b94a
+        op stop timeout=${PORTBLOCK_UNBLOCK_TIMEOUT} op start timeout=${PORTBLOCK_UNBLOCK_TIMEOUT} \
17b94a
+        op monitor interval=10s timeout=${PORTBLOCK_UNBLOCK_TIMEOUT}
17b94a
+        if [ $? -ne 0 ]; then
17b94a
+            logger "warning pcs resource create ${1}-nfs_unblock failed"
17b94a
+        fi
17b94a
+
17b94a
+
17b94a
+        shift
17b94a
+    done
17b94a
+
17b94a
+    create_virt_ip_constraints ${cibfile} ${HA_SERVERS}
17b94a
+
17b94a
+    pcs cluster cib-push ${cibfile}
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "warning pcs cluster cib-push ${cibfile} failed"
17b94a
+    fi
17b94a
+    rm -f ${cibfile}
17b94a
+}
17b94a
+
17b94a
+
17b94a
+teardown_resources()
17b94a
+{
17b94a
+    # local mntpt=$(grep ha-vol-mnt ${HA_CONFIG_FILE} | cut -d = -f 2)
17b94a
+
17b94a
+    # restore /var/lib/nfs
17b94a
+    logger "notice: pcs resource delete nfs_setup-clone"
17b94a
+    pcs resource delete nfs_setup-clone
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "warning: pcs resource delete nfs_setup-clone failed"
17b94a
+    fi
17b94a
+
17b94a
+    # delete -clone resource agents
17b94a
+    # in particular delete the ganesha monitor so we don't try to
17b94a
+    # trigger anything when we shut down ganesha next.
17b94a
+    pcs resource delete nfs-mon-clone
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "warning: pcs resource delete nfs-mon-clone failed"
17b94a
+    fi
17b94a
+
17b94a
+    pcs resource delete nfs-grace-clone
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "warning: pcs resource delete nfs-grace-clone failed"
17b94a
+    fi
17b94a
+
17b94a
+    while [[ ${1} ]]; do
17b94a
+        pcs resource delete ${1}-group
17b94a
+        if [ $? -ne 0 ]; then
17b94a
+            logger "warning: pcs resource delete ${1}-group failed"
17b94a
+        fi
17b94a
+        shift
17b94a
+    done
17b94a
+
17b94a
+}
17b94a
+
17b94a
+
17b94a
+recreate_resources()
17b94a
+{
17b94a
+    local cibfile=${1}; shift
17b94a
+
17b94a
+    while [[ ${1} ]]; do
17b94a
+        # this is variable indirection
17b94a
+        # see the comment on the same a few lines up
17b94a
+        name="VIP_${1}"
17b94a
+        clean_name=${name//[-.]/_}
17b94a
+        nvs=$(grep "^${name}=" ${HA_CONFDIR}/ganesha-ha.conf)
17b94a
+        clean_nvs=${nvs//[-.]/_}
17b94a
+        eval ${clean_nvs}
17b94a
+        eval tmp_ipaddr=\$${clean_name}
17b94a
+        ipaddr=${tmp_ipaddr//_/.}
17b94a
+
17b94a
+        pcs -f ${cibfile} resource create ${1}-nfs_block ocf:heartbeat:portblock protocol=tcp \
17b94a
+        portno=2049 action=block ip=${ipaddr} --group ${1}-group
17b94a
+        if [ $? -ne 0 ]; then
17b94a
+            logger "warning pcs resource create ${1}-nfs_block failed"
17b94a
+        fi
17b94a
+        pcs -f ${cibfile} resource create ${1}-cluster_ip-1 ocf:heartbeat:IPaddr ip=${ipaddr} \
17b94a
+        cidr_netmask=32 op monitor interval=15s --group ${1}-group --after ${1}-nfs_block
17b94a
+        if [ $? -ne 0 ]; then
17b94a
+            logger "warning pcs resource create ${1}-cluster_ip-1 ocf:heartbeat:IPaddr ip=${ipaddr} \
17b94a
+            cidr_netmask=32 op monitor interval=15s failed"
17b94a
+        fi
17b94a
+
17b94a
+        pcs -f ${cibfile} constraint order nfs-grace-clone then ${1}-cluster_ip-1
17b94a
+        if [ $? -ne 0 ]; then
17b94a
+            logger "warning: pcs constraint order nfs-grace-clone then ${1}-cluster_ip-1 failed"
17b94a
+        fi
17b94a
+
17b94a
+        pcs -f ${cibfile} resource create ${1}-nfs_unblock ocf:heartbeat:portblock protocol=tcp \
17b94a
+        portno=2049 action=unblock ip=${ipaddr} reset_local_on_unblock_stop=true \
17b94a
+        tickle_dir=${HA_VOL_MNT}/nfs-ganesha/tickle_dir/ --group ${1}-group --after ${1}-cluster_ip-1 \
17b94a
+        op stop timeout=${PORTBLOCK_UNBLOCK_TIMEOUT} op start timeout=${PORTBLOCK_UNBLOCK_TIMEOUT} \
17b94a
+        op monitor interval=10s timeout=${PORTBLOCK_UNBLOCK_TIMEOUT}
17b94a
+        if [ $? -ne 0 ]; then
17b94a
+            logger "warning pcs resource create ${1}-nfs_unblock failed"
17b94a
+        fi
17b94a
+
17b94a
+        shift
17b94a
+    done
17b94a
+}
17b94a
+
17b94a
+
17b94a
+addnode_recreate_resources()
17b94a
+{
17b94a
+    local cibfile=${1}; shift
17b94a
+    local add_node=${1}; shift
17b94a
+    local add_vip=${1}; shift
17b94a
+
17b94a
+    recreate_resources ${cibfile} ${HA_SERVERS}
17b94a
+
17b94a
+    pcs -f ${cibfile} resource create ${add_node}-nfs_block ocf:heartbeat:portblock \
17b94a
+    protocol=tcp portno=2049 action=block ip=${add_vip} --group ${add_node}-group
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "warning pcs resource create ${add_node}-nfs_block failed"
17b94a
+    fi
17b94a
+    pcs -f ${cibfile} resource create ${add_node}-cluster_ip-1 ocf:heartbeat:IPaddr \
17b94a
+    ip=${add_vip} cidr_netmask=32 op monitor interval=15s --group ${add_node}-group \
17b94a
+    --after ${add_node}-nfs_block
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "warning pcs resource create ${add_node}-cluster_ip-1 ocf:heartbeat:IPaddr \
17b94a
+	ip=${add_vip} cidr_netmask=32 op monitor interval=15s failed"
17b94a
+    fi
17b94a
+
17b94a
+    pcs -f ${cibfile} constraint order nfs-grace-clone then ${add_node}-cluster_ip-1
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "warning: pcs constraint order nfs-grace-clone then ${add_node}-cluster_ip-1 failed"
17b94a
+    fi
17b94a
+    pcs -f ${cibfile} resource create ${add_node}-nfs_unblock ocf:heartbeat:portblock \
17b94a
+    protocol=tcp portno=2049 action=unblock ip=${add_vip} reset_local_on_unblock_stop=true \
17b94a
+    tickle_dir=${HA_VOL_MNT}/nfs-ganesha/tickle_dir/ --group ${add_node}-group --after \
17b94a
+    ${add_node}-cluster_ip-1 op stop timeout=${PORTBLOCK_UNBLOCK_TIMEOUT} op start \
17b94a
+    timeout=${PORTBLOCK_UNBLOCK_TIMEOUT} op monitor interval=10s \
17b94a
+    timeout=${PORTBLOCK_UNBLOCK_TIMEOUT}
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "warning pcs resource create ${add_node}-nfs_unblock failed"
17b94a
+    fi
17b94a
+}
17b94a
+
17b94a
+
17b94a
+clear_resources()
17b94a
+{
17b94a
+    local cibfile=${1}; shift
17b94a
+
17b94a
+    while [[ ${1} ]]; do
17b94a
+        pcs -f ${cibfile} resource delete ${1}-group
17b94a
+        if [ $? -ne 0 ]; then
17b94a
+            logger "warning: pcs -f ${cibfile} resource delete ${1}-group"
17b94a
+        fi
17b94a
+
17b94a
+        shift
17b94a
+    done
17b94a
+}
17b94a
+
17b94a
+
17b94a
+addnode_create_resources()
17b94a
+{
17b94a
+    local add_node=${1}; shift
17b94a
+    local add_vip=${1}; shift
17b94a
+    local cibfile=$(mktemp -u)
17b94a
+
17b94a
+    # start HA on the new node
17b94a
+    pcs cluster start ${add_node}
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+       logger "warning: pcs cluster start ${add_node} failed"
17b94a
+    fi
17b94a
+
17b94a
+    pcs cluster cib ${cibfile}
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "warning: pcs cluster cib ${cibfile} failed"
17b94a
+    fi
17b94a
+
17b94a
+    # delete all the -cluster_ip-1 resources, clearing
17b94a
+    # their constraints, then create them again so we can
17b94a
+    # recompute their constraints
17b94a
+    clear_resources ${cibfile} ${HA_SERVERS}
17b94a
+    addnode_recreate_resources ${cibfile} ${add_node} ${add_vip}
17b94a
+
17b94a
+    HA_SERVERS="${HA_SERVERS} ${add_node}"
17b94a
+    create_virt_ip_constraints ${cibfile} ${HA_SERVERS}
17b94a
+
17b94a
+    pcs cluster cib-push ${cibfile}
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "warning: pcs cluster cib-push ${cibfile} failed"
17b94a
+    fi
17b94a
+    rm -f ${cibfile}
17b94a
+}
17b94a
+
17b94a
+
17b94a
+deletenode_delete_resources()
17b94a
+{
17b94a
+    local node=${1}; shift
17b94a
+    local ha_servers=$(echo "${HA_SERVERS}" | sed s/${node}//)
17b94a
+    local cibfile=$(mktemp -u)
17b94a
+
17b94a
+    pcs cluster cib ${cibfile}
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "warning: pcs cluster cib ${cibfile} failed"
17b94a
+    fi
17b94a
+
17b94a
+    # delete all the -cluster_ip-1 and -trigger_ip-1 resources,
17b94a
+    # clearing their constraints, then create them again so we can
17b94a
+    # recompute their constraints
17b94a
+    clear_resources ${cibfile} ${HA_SERVERS}
17b94a
+    recreate_resources ${cibfile} ${ha_servers}
17b94a
+    HA_SERVERS=$(echo "${ha_servers}" | sed -e "s/  / /")
17b94a
+
17b94a
+    create_virt_ip_constraints ${cibfile} ${HA_SERVERS}
17b94a
+
17b94a
+    pcs cluster cib-push ${cibfile}
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "warning: pcs cluster cib-push ${cibfile} failed"
17b94a
+    fi
17b94a
+    rm -f ${cibfile}
17b94a
+
17b94a
+}
17b94a
+
17b94a
+
17b94a
+deletenode_update_haconfig()
17b94a
+{
17b94a
+    local name="VIP_${1}"
17b94a
+    local clean_name=${name//[-.]/_}
17b94a
+
17b94a
+    ha_servers=$(echo ${HA_SERVERS} | sed -e "s/ /,/")
17b94a
+    sed -i -e "s/^HA_CLUSTER_NODES=.*$/HA_CLUSTER_NODES=\"${ha_servers// /,}\"/" -e "s/^${name}=.*$//" -e "/^$/d" ${HA_CONFDIR}/ganesha-ha.conf
17b94a
+}
17b94a
+
17b94a
+
17b94a
+setup_state_volume()
17b94a
+{
17b94a
+    local mnt=${HA_VOL_MNT}
17b94a
+    local longname=""
17b94a
+    local shortname=""
17b94a
+    local dname=""
17b94a
+    local dirname=""
17b94a
+
17b94a
+    longname=$(hostname)
17b94a
+    dname=${longname#$(hostname -s)}
17b94a
+
17b94a
+    while [[ ${1} ]]; do
17b94a
+
17b94a
+        if [[ ${1} == *${dname} ]]; then
17b94a
+            dirname=${1}
17b94a
+        else
17b94a
+            dirname=${1}${dname}
17b94a
+        fi
17b94a
+
17b94a
+        if [ ! -d ${mnt}/nfs-ganesha/tickle_dir ]; then
17b94a
+            mkdir ${mnt}/nfs-ganesha/tickle_dir
17b94a
+        fi
17b94a
+        if [ ! -d ${mnt}/nfs-ganesha/${dirname} ]; then
17b94a
+            mkdir ${mnt}/nfs-ganesha/${dirname}
17b94a
+        fi
17b94a
+        if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs ]; then
17b94a
+            mkdir ${mnt}/nfs-ganesha/${dirname}/nfs
17b94a
+        fi
17b94a
+        if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha ]; then
17b94a
+            mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha
17b94a
+        fi
17b94a
+        if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/statd ]; then
17b94a
+            mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/statd
17b94a
+        fi
17b94a
+        if [ ! -e ${mnt}/nfs-ganesha/${dirname}/nfs/state ]; then
17b94a
+            touch ${mnt}/nfs-ganesha/${dirname}/nfs/state
17b94a
+        fi
17b94a
+        if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/v4recov ]; then
17b94a
+            mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/v4recov
17b94a
+        fi
17b94a
+        if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/v4old ]; then
17b94a
+            mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/v4old
17b94a
+        fi
17b94a
+        if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/statd/sm ]; then
17b94a
+            mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/statd/sm
17b94a
+        fi
17b94a
+        if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/statd/sm.bak ]; then
17b94a
+            mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/statd/sm.bak
17b94a
+        fi
17b94a
+        if [ ! -e ${mnt}/nfs-ganesha/${dirname}/nfs/statd/state ]; then
17b94a
+            touch ${mnt}/nfs-ganesha/${dirname}/nfs/statd/state
17b94a
+        fi
17b94a
+        for server in ${HA_SERVERS} ; do
17b94a
+            if [ ${server} != ${dirname} ]; then
17b94a
+                ln -s ${mnt}/nfs-ganesha/${server}/nfs/ganesha ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/${server}
17b94a
+                ln -s ${mnt}/nfs-ganesha/${server}/nfs/statd ${mnt}/nfs-ganesha/${dirname}/nfs/statd/${server}
17b94a
+            fi
17b94a
+        done
17b94a
+        shift
17b94a
+    done
17b94a
+
17b94a
+}
17b94a
+
17b94a
+
17b94a
+addnode_state_volume()
17b94a
+{
17b94a
+    local newnode=${1}; shift
17b94a
+    local mnt=${HA_VOL_MNT}
17b94a
+    local longname=""
17b94a
+    local dname=""
17b94a
+    local dirname=""
17b94a
+
17b94a
+    longname=$(hostname)
17b94a
+    dname=${longname#$(hostname -s)}
17b94a
+
17b94a
+    if [[ ${newnode} == *${dname} ]]; then
17b94a
+        dirname=${newnode}
17b94a
+    else
17b94a
+        dirname=${newnode}${dname}
17b94a
+    fi
17b94a
+
17b94a
+    if [ ! -d ${mnt}/nfs-ganesha/${dirname} ]; then
17b94a
+        mkdir ${mnt}/nfs-ganesha/${dirname}
17b94a
+    fi
17b94a
+    if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs ]; then
17b94a
+        mkdir ${mnt}/nfs-ganesha/${dirname}/nfs
17b94a
+    fi
17b94a
+    if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha ]; then
17b94a
+        mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha
17b94a
+    fi
17b94a
+    if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/statd ]; then
17b94a
+        mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/statd
17b94a
+    fi
17b94a
+    if [ ! -e ${mnt}/nfs-ganesha/${dirname}/nfs/state ]; then
17b94a
+        touch ${mnt}/nfs-ganesha/${dirname}/nfs/state
17b94a
+    fi
17b94a
+    if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/v4recov ]; then
17b94a
+        mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/v4recov
17b94a
+    fi
17b94a
+    if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/v4old ]; then
17b94a
+        mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/v4old
17b94a
+    fi
17b94a
+    if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/statd/sm ]; then
17b94a
+        mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/statd/sm
17b94a
+    fi
17b94a
+    if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/statd/sm.bak ]; then
17b94a
+        mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/statd/sm.bak
17b94a
+    fi
17b94a
+    if [ ! -e ${mnt}/nfs-ganesha/${dirname}/nfs/statd/state ]; then
17b94a
+        touch ${mnt}/nfs-ganesha/${dirname}/nfs/statd/state
17b94a
+    fi
17b94a
+
17b94a
+    for server in ${HA_SERVERS} ; do
17b94a
+
17b94a
+        if [[ ${server} != ${dirname} ]]; then
17b94a
+            ln -s ${mnt}/nfs-ganesha/${server}/nfs/ganesha ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/${server}
17b94a
+            ln -s ${mnt}/nfs-ganesha/${server}/nfs/statd ${mnt}/nfs-ganesha/${dirname}/nfs/statd/${server}
17b94a
+
17b94a
+            ln -s ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha ${mnt}/nfs-ganesha/${server}/nfs/ganesha/${dirname}
17b94a
+            ln -s ${mnt}/nfs-ganesha/${dirname}/nfs/statd ${mnt}/nfs-ganesha/${server}/nfs/statd/${dirname}
17b94a
+        fi
17b94a
+    done
17b94a
+
17b94a
+}
17b94a
+
17b94a
+
17b94a
+delnode_state_volume()
17b94a
+{
17b94a
+    local delnode=${1}; shift
17b94a
+    local mnt=${HA_VOL_MNT}
17b94a
+    local longname=""
17b94a
+    local dname=""
17b94a
+    local dirname=""
17b94a
+
17b94a
+    longname=$(hostname)
17b94a
+    dname=${longname#$(hostname -s)}
17b94a
+
17b94a
+    if [[ ${delnode} == *${dname} ]]; then
17b94a
+        dirname=${delnode}
17b94a
+    else
17b94a
+        dirname=${delnode}${dname}
17b94a
+    fi
17b94a
+
17b94a
+    rm -rf ${mnt}/nfs-ganesha/${dirname}
17b94a
+
17b94a
+    for server in ${HA_SERVERS} ; do
17b94a
+        if [[ "${server}" != "${dirname}" ]]; then
17b94a
+            rm -f ${mnt}/nfs-ganesha/${server}/nfs/ganesha/${dirname}
17b94a
+            rm -f ${mnt}/nfs-ganesha/${server}/nfs/statd/${dirname}
17b94a
+        fi
17b94a
+    done
17b94a
+}
17b94a
+
17b94a
+
17b94a
+status()
17b94a
+{
17b94a
+    local scratch=$(mktemp)
17b94a
+    local regex_str="^${1}-cluster_ip-1"
17b94a
+    local healthy=0
17b94a
+    local index=1
17b94a
+    local nodes
17b94a
+
17b94a
+    # change tabs to spaces, strip leading spaces
17b94a
+    pcs status | sed -e "s/\t/ /g" -e "s/^[ ]*//" > ${scratch}
17b94a
+
17b94a
+    nodes[0]=${1}; shift
17b94a
+
17b94a
+    # make a regex of the configured nodes
17b94a
+    # and initalize the nodes array for later
17b94a
+    while [[ ${1} ]]; do
17b94a
+
17b94a
+        regex_str="${regex_str}|^${1}-cluster_ip-1"
17b94a
+        nodes[${index}]=${1}
17b94a
+        ((index++))
17b94a
+        shift
17b94a
+    done
17b94a
+
17b94a
+    # print the nodes that are expected to be online
17b94a
+    grep -E "^Online:" ${scratch}
17b94a
+
17b94a
+    echo
17b94a
+
17b94a
+    # print the VIPs and which node they are on
17b94a
+    grep -E "${regex_str}" < ${scratch} | cut -d ' ' -f 1,4
17b94a
+
17b94a
+    echo
17b94a
+
17b94a
+    # check if the VIP and port block/unblock RAs are on the expected nodes
17b94a
+    for n in ${nodes[*]}; do
17b94a
+
17b94a
+        grep -E -x "${n}-nfs_block \(ocf::heartbeat:portblock\): Started ${n}" > /dev/null 2>&1 ${scratch}
17b94a
+        result=$?
17b94a
+        ((healthy+=${result}))
17b94a
+        grep -E -x "${n}-cluster_ip-1 \(ocf::heartbeat:IPaddr\): Started ${n}" > /dev/null 2>&1 ${scratch}
17b94a
+        result=$?
17b94a
+        ((healthy+=${result}))
17b94a
+        grep -E -x "${n}-nfs_unblock \(ocf::heartbeat:portblock\): Started ${n}" > /dev/null 2>&1 ${scratch}
17b94a
+        result=$?
17b94a
+        ((healthy+=${result}))
17b94a
+    done
17b94a
+
17b94a
+    grep -E "\):\ Stopped|FAILED" > /dev/null 2>&1 ${scratch}
17b94a
+    result=$?
17b94a
+
17b94a
+    if [ ${result} -eq 0 ]; then
17b94a
+        echo "Cluster HA Status: BAD"
17b94a
+    elif [ ${healthy} -eq 0 ]; then
17b94a
+        echo "Cluster HA Status: HEALTHY"
17b94a
+    else
17b94a
+        echo "Cluster HA Status: FAILOVER"
17b94a
+    fi
17b94a
+
17b94a
+    rm -f ${scratch}
17b94a
+}
17b94a
+
17b94a
+create_ganesha_conf_file()
17b94a
+{
17b94a
+        if [ $1 == "yes" ];
17b94a
+        then
17b94a
+                if [  -e $GANESHA_CONF ];
17b94a
+                then
17b94a
+                        rm -rf $GANESHA_CONF
17b94a
+                fi
17b94a
+        # The symlink /etc/ganesha/ganesha.conf need to be
17b94a
+        # created using ganesha conf file mentioned in the
17b94a
+        # shared storage. Every node will only have this
17b94a
+        # link and actual file will stored in shared storage,
17b94a
+        # so that ganesha conf editing of ganesha conf will
17b94a
+        # be easy as well as it become more consistent.
17b94a
+
17b94a
+                ln -s $HA_CONFDIR/ganesha.conf $GANESHA_CONF
17b94a
+        else
17b94a
+        # Restoring previous file
17b94a
+                rm -rf $GANESHA_CONF
17b94a
+                cp $HA_CONFDIR/ganesha.conf $GANESHA_CONF
17b94a
+                sed -r -i -e '/^%include[[:space:]]+".+\.conf"$/d' $GANESHA_CONF
17b94a
+        fi
17b94a
+}
17b94a
+
17b94a
+set_quorum_policy()
17b94a
+{
17b94a
+    local quorum_policy="stop"
17b94a
+    local num_servers=${1}
17b94a
+
17b94a
+    if [ ${num_servers} -lt 3 ]; then
17b94a
+        quorum_policy="ignore"
17b94a
+    fi
17b94a
+    pcs property set no-quorum-policy=${quorum_policy}
17b94a
+    if [ $? -ne 0 ]; then
17b94a
+        logger "warning: pcs property set no-quorum-policy=${quorum_policy} failed"
17b94a
+    fi
17b94a
+}
17b94a
+
17b94a
+main()
17b94a
+{
17b94a
+
17b94a
+    local cmd=${1}; shift
17b94a
+    if [[ ${cmd} == *help ]]; then
17b94a
+        usage
17b94a
+        exit 0
17b94a
+    fi
17b94a
+    HA_CONFDIR=${1%/}; shift
17b94a
+    local ha_conf=${HA_CONFDIR}/ganesha-ha.conf
17b94a
+    local node=""
17b94a
+    local vip=""
17b94a
+
17b94a
+    # ignore any comment lines
17b94a
+    cfgline=$(grep  ^HA_NAME= ${ha_conf})
17b94a
+    eval $(echo ${cfgline} | grep -F HA_NAME=)
17b94a
+    cfgline=$(grep  ^HA_CLUSTER_NODES= ${ha_conf})
17b94a
+    eval $(echo ${cfgline} | grep -F HA_CLUSTER_NODES=)
17b94a
+
17b94a
+    case "${cmd}" in
17b94a
+
17b94a
+    setup | --setup)
17b94a
+        logger "setting up ${HA_NAME}"
17b94a
+
17b94a
+        check_cluster_exists ${HA_NAME}
17b94a
+
17b94a
+        determine_servers "setup"
17b94a
+
17b94a
+        if [ "X${HA_NUM_SERVERS}X" != "X1X" ]; then
17b94a
+
17b94a
+            setup_cluster ${HA_NAME} ${HA_NUM_SERVERS} "${HA_SERVERS}"
17b94a
+
17b94a
+            setup_create_resources ${HA_SERVERS}
17b94a
+
17b94a
+            setup_finalize_ha
17b94a
+
17b94a
+            setup_state_volume ${HA_SERVERS}
17b94a
+
17b94a
+        else
17b94a
+
17b94a
+            logger "insufficient servers for HA, aborting"
17b94a
+        fi
17b94a
+        ;;
17b94a
+
17b94a
+    teardown | --teardown)
17b94a
+        logger "tearing down ${HA_NAME}"
17b94a
+
17b94a
+        determine_servers "teardown"
17b94a
+
17b94a
+        teardown_resources ${HA_SERVERS}
17b94a
+
17b94a
+        teardown_cluster ${HA_NAME}
17b94a
+
17b94a
+        cleanup_ganesha_config ${HA_CONFDIR}
17b94a
+        ;;
17b94a
+
17b94a
+    cleanup | --cleanup)
17b94a
+        cleanup_ganesha_config ${HA_CONFDIR}
17b94a
+        ;;
17b94a
+
17b94a
+    add | --add)
17b94a
+        node=${1}; shift
17b94a
+        vip=${1}; shift
17b94a
+
17b94a
+        logger "adding ${node} with ${vip} to ${HA_NAME}"
17b94a
+
17b94a
+        determine_service_manager
17b94a
+
17b94a
+        manage_service "start" ${node}
17b94a
+
17b94a
+        determine_servers "add"
17b94a
+
17b94a
+        pcs cluster node add ${node}
17b94a
+        if [ $? -ne 0 ]; then
17b94a
+            logger "warning: pcs cluster node add ${node} failed"
17b94a
+        fi
17b94a
+
17b94a
+        addnode_create_resources ${node} ${vip}
17b94a
+        # Subsequent add-node recreates resources for all the nodes
17b94a
+        # that already exist in the cluster. The nodes are picked up
17b94a
+        # from the entries in the ganesha-ha.conf file. Adding the
17b94a
+        # newly added node to the file so that the resources specfic
17b94a
+        # to this node is correctly recreated in the future.
17b94a
+        clean_node=${node//[-.]/_}
17b94a
+        echo "VIP_${node}=\"${vip}\"" >> ${HA_CONFDIR}/ganesha-ha.conf
17b94a
+
17b94a
+        NEW_NODES="$HA_CLUSTER_NODES,${node}"
17b94a
+
17b94a
+        sed -i s/HA_CLUSTER_NODES.*/"HA_CLUSTER_NODES=\"$NEW_NODES\""/ \
17b94a
+$HA_CONFDIR/ganesha-ha.conf
17b94a
+
17b94a
+        addnode_state_volume ${node}
17b94a
+
17b94a
+        # addnode_create_resources() already appended ${node} to
17b94a
+        # HA_SERVERS, so only need to increment HA_NUM_SERVERS
17b94a
+        # and set quorum policy
17b94a
+        HA_NUM_SERVERS=$(expr ${HA_NUM_SERVERS} + 1)
17b94a
+        set_quorum_policy ${HA_NUM_SERVERS}
17b94a
+        ;;
17b94a
+
17b94a
+    delete | --delete)
17b94a
+        node=${1}; shift
17b94a
+
17b94a
+        logger "deleting ${node} from ${HA_NAME}"
17b94a
+
17b94a
+        determine_servers "delete"
17b94a
+
17b94a
+        deletenode_delete_resources ${node}
17b94a
+
17b94a
+        pcs cluster node remove ${node}
17b94a
+        if [ $? -ne 0 ]; then
17b94a
+            logger "warning: pcs cluster node remove ${node} failed"
17b94a
+        fi
17b94a
+
17b94a
+        deletenode_update_haconfig ${node}
17b94a
+
17b94a
+        delnode_state_volume ${node}
17b94a
+
17b94a
+        determine_service_manager
17b94a
+
17b94a
+        manage_service "stop" ${node}
17b94a
+
17b94a
+        HA_NUM_SERVERS=$(expr ${HA_NUM_SERVERS} - 1)
17b94a
+        set_quorum_policy ${HA_NUM_SERVERS}
17b94a
+        ;;
17b94a
+
17b94a
+    status | --status)
17b94a
+        determine_servers "status"
17b94a
+
17b94a
+        status ${HA_SERVERS}
17b94a
+        ;;
17b94a
+
17b94a
+    refresh-config | --refresh-config)
17b94a
+        VOL=${1}
17b94a
+
17b94a
+        determine_servers "refresh-config"
17b94a
+
17b94a
+        refresh_config ${VOL} ${HA_CONFDIR} ${HA_SERVERS}
17b94a
+        ;;
17b94a
+
17b94a
+    setup-ganesha-conf-files | --setup-ganesha-conf-files)
17b94a
+
17b94a
+        create_ganesha_conf_file ${1}
17b94a
+        ;;
17b94a
+
17b94a
+    *)
17b94a
+        # setup and teardown are not intended to be used by a
17b94a
+        # casual user
17b94a
+        usage
17b94a
+        logger "Usage: ganesha-ha.sh add|delete|status"
17b94a
+        ;;
17b94a
+
17b94a
+    esac
17b94a
+}
17b94a
+
17b94a
+main $*
17b94a
diff --git a/glusterfs.spec.in b/glusterfs.spec.in
17b94a
index dd7438c..d748ebc 100644
17b94a
--- a/glusterfs.spec.in
17b94a
+++ b/glusterfs.spec.in
17b94a
@@ -460,7 +460,8 @@ Summary:          NFS-Ganesha configuration
17b94a
 Group:            Applications/File
17b94a
 
17b94a
 Requires:         %{name}-server%{?_isa} = %{version}-%{release}
17b94a
-Requires:         nfs-ganesha-gluster, pcs, dbus
17b94a
+Requires:         nfs-ganesha-gluster >= 2.4.1
17b94a
+Requires:         pcs, dbus
17b94a
 %if ( 0%{?rhel} && 0%{?rhel} == 6 )
17b94a
 Requires:         cman, pacemaker, corosync
17b94a
 %endif
17b94a
@@ -1138,6 +1139,7 @@ exit 0
17b94a
 #exclude ganesha related files
17b94a
 %exclude %{_sysconfdir}/ganesha/*
17b94a
 %exclude %{_libexecdir}/ganesha/*
17b94a
+%exclude %{_prefix}/lib/ocf/resource.d/heartbeat/*
17b94a
 %endif
17b94a
 
17b94a
 %files api
17b94a
@@ -1306,6 +1308,7 @@ exit 0
17b94a
 %files ganesha
17b94a
 %{_sysconfdir}/ganesha/*
17b94a
 %{_libexecdir}/ganesha/*
17b94a
+%{_prefix}/lib/ocf/resource.d/heartbeat/*
17b94a
 %endif
17b94a
 
17b94a
 %if ( 0%{!?_without_ocf:1} )
17b94a
@@ -1904,6 +1907,9 @@ fi
17b94a
 %endif
17b94a
 
17b94a
 %changelog
17b94a
+* Sat Apr 6 2019 Jiffin Tony Thottan <jthottan@redhat.com>
17b94a
+- Adding ganesha ha resources back in gluster repository
17b94a
+
17b94a
 * Fri Apr 5 2019 Jiffin Tony Thottan <jthottan@redhat.com>
17b94a
 - Adding ganesha bits back in gluster repository
17b94a
 
17b94a
-- 
17b94a
1.8.3.1
17b94a