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