Blame SOURCES/bz1126073-2-nfsserver-fix-systemd-status-detection.patch

70ff5f
diff -uNr a/heartbeat/nfsserver b/heartbeat/nfsserver
70ff5f
--- a/heartbeat/nfsserver	2016-07-21 12:40:55.417326145 +0200
70ff5f
+++ b/heartbeat/nfsserver	2016-07-21 12:04:49.000000000 +0200
70ff5f
@@ -352,45 +352,22 @@
70ff5f
 
70ff5f
 nfsserver_monitor ()
70ff5f
 {
70ff5f
-	# Skip trying to start processes once before failing
70ff5f
-	# when run from nfsserver_start ()
70ff5f
-	if [ "$1" == "fromstart" ]; then
70ff5f
-		ocf_log info "fromstart"
70ff5f
-		fromstart=1
70ff5f
-	else
70ff5f
-		tries=1
70ff5f
-	fi
70ff5f
-
70ff5f
 	# systemd
70ff5f
 	if [ "$EXEC_MODE" -eq "2" ]; then
70ff5f
 		ocf_log info "Status: rpcbind"
70ff5f
-		rpcinfo &> /dev/null
70ff5f
+		rpcinfo > /dev/null 2>&1
70ff5f
 		rc=$?
70ff5f
 		if [ "$rc" -ne "0" ]; then
70ff5f
-			if [ ! "$fromstart" ] && [ "$tries" -gt "0" ]; then
70ff5f
-				nfsserver_start frommonitor
70ff5f
-				rc=$?
70ff5f
-				let tries=$tries-1
70ff5f
-			fi
70ff5f
-			if [ "$rc" -ne "0" ]; then 
70ff5f
-				ocf_exit_reason "rpcbind is not running"
70ff5f
-				return $OCF_NOT_RUNNING
70ff5f
-			fi
70ff5f
+			ocf_exit_reason "rpcbind is not running"
70ff5f
+			return $OCF_NOT_RUNNING
70ff5f
 		fi
70ff5f
 
70ff5f
 		ocf_log info "Status: nfs-mountd"
70ff5f
-		rpcinfo -t localhost 100005 &> /dev/null
70ff5f
+		rpcinfo -t localhost 100005 > /dev/null 2>&1
70ff5f
 		rc=$?
70ff5f
 		if [ "$rc" -ne "0" ]; then
70ff5f
-			if [ ! "$fromstart" ] && [ "$tries" -gt "0" ]; then
70ff5f
-				nfsserver_start frommonitor
70ff5f
-				rc=$?
70ff5f
-				let tries=$tries-1
70ff5f
-			fi
70ff5f
-			if [ "$rc" -ne "0" ]; then 
70ff5f
-				ocf_exit_reason "nfs-mountd is not running"
70ff5f
-				return $OCF_NOT_RUNNING
70ff5f
-			fi
70ff5f
+			ocf_exit_reason "nfs-mountd is not running"
70ff5f
+			return $OCF_NOT_RUNNING
70ff5f
 		fi
70ff5f
 
70ff5f
 		ocf_log info "Status: nfs-idmapd"
70ff5f
@@ -400,31 +377,16 @@
70ff5f
 		ocf_log debug "$(cat $fn)"
70ff5f
 		rm -f $fn
70ff5f
 		if [ "$rc" -ne "0" ]; then
70ff5f
-			if [ ! "$fromstart" ] && [ "$tries" -gt "0" ]; then
70ff5f
-				nfsserver_start frommonitor
70ff5f
-				rc=$?
70ff5f
-				ocf_log info "Tried to start services: rc: $rc"
70ff5f
-				let tries=$tries-1
70ff5f
-			fi
70ff5f
-			if [ "$rc" -ne "0" ]; then 
70ff5f
-				ocf_exit_reason "nfs-idmapd is not running"
70ff5f
-				return $OCF_NOT_RUNNING
70ff5f
-			fi
70ff5f
+			ocf_exit_reason "nfs-idmapd is not running"
70ff5f
+			return $OCF_NOT_RUNNING
70ff5f
 		fi
70ff5f
 
70ff5f
 		ocf_log info "Status: rpc-statd"
70ff5f
-		rpcinfo -t localhost 100024 &> /dev/null
70ff5f
+		rpcinfo -t localhost 100024 > /dev/null 2>&1
70ff5f
 		rc=$?
70ff5f
 		if [ "$rc" -ne "0" ]; then
70ff5f
-			if [ ! "$fromstart" ] && [ "$tries" -gt "0" ]; then
70ff5f
-				nfsserver_start frommonitor
70ff5f
-				rc=$?
70ff5f
-				let tries=$tries-1
70ff5f
-			fi
70ff5f
-			if [ "$rc" -ne "0" ]; then 
70ff5f
-				ocf_exit_reason "rpc-statd is not running"
70ff5f
-				return $OCF_NOT_RUNNING
70ff5f
-			fi
70ff5f
+			ocf_exit_reason "rpc-statd is not running"
70ff5f
+			return $OCF_NOT_RUNNING
70ff5f
 		fi
70ff5f
 	fi
70ff5f
 
70ff5f
@@ -436,15 +398,8 @@
70ff5f
 
70ff5f
 	tfn="/proc/fs/nfsd/threads"
70ff5f
 	if [ ! -f "$tfn" ] || [ "$(cat $tfn)" -le "0" ]; then
70ff5f
-		if [ ! "$fromstart" ] && [ "$tries" -gt "0" ]; then
70ff5f
-			nfsserver_start frommonitor
70ff5f
-			rc=$?
70ff5f
-			let tries=$tries-1
70ff5f
-		fi
70ff5f
-		if [ "$rc" -ne "0" ]; then 
70ff5f
-			ocf_exit_reason "NFS server not running: /proc/fs/nfsd/threads"
70ff5f
-			return $OCF_NOT_RUNNING
70ff5f
-		fi
70ff5f
+		ocf_exit_reason "NFS server not running: /proc/fs/nfsd/threads"
70ff5f
+		return $OCF_NOT_RUNNING
70ff5f
 	fi
70ff5f
 
70ff5f
 	#Adapt LSB status code to OCF return code
70ff5f
@@ -454,15 +409,8 @@
70ff5f
 		v3locking_exec "status"
70ff5f
 		rc=$?
70ff5f
 		if [ $rc -ne 0 ]; then
70ff5f
-			if [ ! "$fromstart" ] && [ $tries -gt "0" ]; then
70ff5f
-				nfsserver_start frommonitor
70ff5f
-				rc=$?
70ff5f
-				let tries=$tries-1
70ff5f
-			fi
70ff5f
-			if [ "$rc" -ne "0" ]; then 
70ff5f
-				ocf_exit_reason "NFS server is up, but the locking daemons are down"
70ff5f
-				rc=$OCF_ERR_GENERIC
70ff5f
-			fi
70ff5f
+			ocf_exit_reason "NFS server is up, but the locking daemons are down"
70ff5f
+			rc=$OCF_ERR_GENERIC
70ff5f
 		fi
70ff5f
 		return $rc
70ff5f
 	elif [ $rc -eq 3 ]; then
70ff5f
@@ -561,7 +509,7 @@
70ff5f
 	[ -f "$fp/xtab" ] || touch "$fp/xtab"
70ff5f
 	[ -f "$fp/rmtab" ] || touch "$fp/rmtab"
70ff5f
 
70ff5f
-	dd if=/dev/urandom of=$fp/$STATD_DIR/state bs=1 count=4 &> /dev/null
70ff5f
+	dd if=/dev/urandom of=$fp/$STATD_DIR/state bs=1 count=4 > /dev/null 2>&1
70ff5f
 	[ -n "`id -u rpcuser`" -a "`id -g rpcuser`" ] && chown rpcuser.rpcuser "$fp/$STATD_DIR/state"
70ff5f
 	[ $SELINUX_ENABLED -eq 0 ] && chcon -R "$SELINUX_LABEL" "$fp"
70ff5f
 }
70ff5f
@@ -656,15 +604,15 @@
70ff5f
 
70ff5f
 terminate()
70ff5f
 {
70ff5f
-	declare pids
70ff5f
-	declare i=0
70ff5f
+	local pids
70ff5f
+	local i=0
70ff5f
 
70ff5f
 	while : ; do
70ff5f
 		pids=$(binary_status $1)
70ff5f
 		[ -z "$pids" ] && return 0
70ff5f
 	 	kill $pids
70ff5f
 		sleep 1
70ff5f
-		((i++))
70ff5f
+		i=$((i + 1))
70ff5f
 		[ $i -gt 3 ] && return 1
70ff5f
 	done
70ff5f
 }
70ff5f
@@ -672,22 +620,22 @@
70ff5f
 
70ff5f
 killkill()
70ff5f
 {
70ff5f
-	declare pids
70ff5f
-	declare i=0
70ff5f
+	local pids
70ff5f
+	local i=0
70ff5f
 
70ff5f
 	while : ; do
70ff5f
 		pids=$(binary_status $1)
70ff5f
 		[ -z "$pids" ] && return 0
70ff5f
 	 	kill -9 $pids
70ff5f
 		sleep 1
70ff5f
-		((i++))
70ff5f
+		i=$((i + 1))
70ff5f
 		[ $i -gt 3 ] && return 1
70ff5f
 	done
70ff5f
 }
70ff5f
 
70ff5f
 stop_process()
70ff5f
 {
70ff5f
-	declare process=$1
70ff5f
+	local process=$1
70ff5f
 
70ff5f
 	ocf_log info "Stopping $process"
70ff5f
 	if terminate $process; then
70ff5f
@@ -758,14 +706,9 @@
70ff5f
 
70ff5f
 nfsserver_start ()
70ff5f
 {
70ff5f
-	# Skip monitor check when run from nfsserver_monitor ()
70ff5f
-	if [ "$1" == "frommonitor" ]; then
70ff5f
-		frommonitor=1
70ff5f
-	fi
70ff5f
-
70ff5f
 	local rc;
70ff5f
 
70ff5f
-	if [ ! "$frommonitor" ] && nfsserver_monitor fromstart; then
70ff5f
+	if nfsserver_monitor; then
70ff5f
 		ocf_log debug "NFS server is already started"
70ff5f
 		return $OCF_SUCCESS
70ff5f
 	fi
70ff5f
@@ -796,21 +739,17 @@
70ff5f
 	# systemd
70ff5f
 	if [ "$EXEC_MODE" -eq "2" ]; then
70ff5f
 		nfs_exec start rpcbind
70ff5f
-		local i=10
70ff5f
-		while [ "$i" -gt 0 ]; do
70ff5f
+		local i=1
70ff5f
+		while : ; do
70ff5f
 			ocf_log info "Start: rpcbind i: $i"
70ff5f
-			rpcinfo &> /dev/null
70ff5f
+			rpcinfo > /dev/null 2>&1
70ff5f
 			rc=$?
70ff5f
 			if [ "$rc" -eq "0" ]; then
70ff5f
 				break;
70ff5f
 			fi
70ff5f
 			sleep 1
70ff5f
-			let i=$i-1
70ff5f
+			i=$((i + 1))
70ff5f
 		done
70ff5f
-		if [ "$i" -eq 0 ]; then
70ff5f
-			ocf_exit_reason "Failed to start rpcbind"
70ff5f
-			return $OCF_ERR_GENERIC
70ff5f
-		fi
70ff5f
 	fi
70ff5f
 
70ff5f
 	# check to see if we need to start rpc.statd
70ff5f
@@ -830,25 +769,21 @@
70ff5f
 	# systemd
70ff5f
 	if [ "$EXEC_MODE" -eq "2" ]; then
70ff5f
 		nfs_exec start nfs-mountd
70ff5f
-		local i=10
70ff5f
-		while [ "$i" -gt 0 ]; do
70ff5f
+		local i=1
70ff5f
+		while : ; do
70ff5f
 			ocf_log info "Start: nfs-mountd i: $i"
70ff5f
-			rpcinfo -t localhost 100005 &> /dev/null
70ff5f
+			rpcinfo -t localhost 100005 > /dev/null 2>&1
70ff5f
 			rc=$?
70ff5f
 			if [ "$rc" -eq "0" ]; then
70ff5f
 				break;
70ff5f
 			fi
70ff5f
 			sleep 1
70ff5f
-			let i=$i-1
70ff5f
+			i=$((i + 1))
70ff5f
 		done
70ff5f
-		if [ "$i" -eq 0 ]; then
70ff5f
-			ocf_exit_reason "Failed to start nfs-mountd"
70ff5f
-			return $OCF_ERR_GENERIC
70ff5f
-		fi
70ff5f
 
70ff5f
 		nfs_exec start nfs-idmapd
70ff5f
-		local i=10
70ff5f
-		while [ "$i" -gt 0 ]; do
70ff5f
+		local i=1
70ff5f
+		while : ; do
70ff5f
 			ocf_log info "Start: nfs-idmapd i: $i"
70ff5f
 			fn=`mktemp`
70ff5f
 			nfs_exec status nfs-idmapd > $fn 2>&1
70ff5f
@@ -859,29 +794,21 @@
70ff5f
 				break;
70ff5f
 			fi
70ff5f
 			sleep 1
70ff5f
-			let i=$i-1
70ff5f
+			i=$((i + 1))
70ff5f
 		done
70ff5f
-		if [ "$i" -eq 0 ]; then
70ff5f
-			ocf_exit_reason "Failed to start nfs-idmapd"
70ff5f
-			return $OCF_ERR_GENERIC
70ff5f
-		fi
70ff5f
 
70ff5f
 		nfs_exec start rpc-statd
70ff5f
-		local i=10
70ff5f
-		while [ "$i" -gt 0 ]; do
70ff5f
+		local i=1
70ff5f
+		while : ; do
70ff5f
 			ocf_log info "Start: rpc-statd i: $i"
70ff5f
-			rpcinfo -t localhost 100024 &> /dev/null
70ff5f
+			rpcinfo -t localhost 100024 > /dev/null 2>&1
70ff5f
 			rc=$?
70ff5f
 			if [ "$rc" -eq "0" ]; then
70ff5f
 				break;
70ff5f
 			fi
70ff5f
 			sleep 1
70ff5f
-			let i=$i-1
70ff5f
+			i=$((i + 1))
70ff5f
 		done
70ff5f
-		if [ "$i" -eq 0 ]; then
70ff5f
-			ocf_exit_reason "Failed to start rpc-statd"
70ff5f
-			return $OCF_ERR_GENERIC
70ff5f
-		fi
70ff5f
 	fi
70ff5f
 
70ff5f
 	fn=`mktemp`
70ff5f
@@ -936,16 +863,16 @@
70ff5f
 			return $OCF_ERR_GENERIC
70ff5f
 		fi
70ff5f
 
70ff5f
-		nfs_exec stop rpc-statd &> /dev/null
70ff5f
+		nfs_exec stop rpc-statd > /dev/null 2>&1
70ff5f
 		ocf_log info "Stop: rpc-statd"
70ff5f
-		rpcinfo -t localhost 100024 &> /dev/null
70ff5f
+		rpcinfo -t localhost 100024 > /dev/null 2>&1
70ff5f
 		rc=$?
70ff5f
 		if [ "$rc" -eq "0" ]; then
70ff5f
 			ocf_exit_reason "Failed to stop rpc-statd"
70ff5f
 			return $OCF_ERR_GENERIC
70ff5f
 		fi
70ff5f
 
70ff5f
-		nfs_exec stop nfs-idmapd &> /dev/null
70ff5f
+		nfs_exec stop nfs-idmapd > /dev/null 2>&1
70ff5f
 		ocf_log info "Stop: nfs-idmapd"
70ff5f
 		fn=`mktemp`
70ff5f
 		nfs_exec status nfs-idmapd > $fn 2>&1
70ff5f
@@ -957,9 +884,9 @@
70ff5f
 			return $OCF_ERR_GENERIC
70ff5f
 		fi
70ff5f
 
70ff5f
-		nfs_exec stop nfs-mountd &> /dev/null
70ff5f
+		nfs_exec stop nfs-mountd > /dev/null 2>&1
70ff5f
 		ocf_log info "Stop: nfs-mountd"
70ff5f
-		rpcinfo -t localhost 100005 &> /dev/null
70ff5f
+		rpcinfo -t localhost 100005 > /dev/null 2>&1
70ff5f
 		rc=$?
70ff5f
 		if [ "$rc" -eq "0" ]; then
70ff5f
 			ocf_exit_reason "Failed to stop nfs-mountd"
70ff5f
@@ -975,8 +902,11 @@
70ff5f
 
70ff5f
 	# systemd
70ff5f
 	if [ "$EXEC_MODE" -eq "2" ]; then
70ff5f
-		nfs_exec stop rpcbind &> /dev/null
70ff5f
+		nfs_exec stop rpcbind > /dev/null 2>&1
70ff5f
 		ocf_log info "Stop: rpcbind"
70ff5f
+
70ff5f
+		nfs_exec stop rpc-gssd > /dev/null 2>&1
70ff5f
+		ocf_log info "Stop: rpc-gssd"
70ff5f
 	fi
70ff5f
 
70ff5f
 	unbind_tree