/usr/lib/ocf/resource.d/heartbeat/nfsnotify is in resource-agents 1:3.9.7-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | #!/bin/bash
#
# Copyright (c) 2014 David Vossel <davidvossel@gmail.com>
#                    All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Further, this software is distributed without any warranty that it is
# free of the rightful claim of any third person regarding infringement
# or the like.  Any license provided herein, whether implied or
# otherwise, applies only to this software file.  Patent licenses, if
# any, provided herein do not apply to combinations of this program with
# other software, or any other product whatsoever.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
#
#######################################################################
# Initialization:
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
. ${OCF_FUNCTIONS_DIR}/ocf-directories
#######################################################################
sbindir=$HA_SBIN_DIR
if [ -z "$sbindir" ]; then
	sbindir=/usr/sbin
fi
SELINUX_ENABLED=-1
NFSNOTIFY_TMP_DIR="${HA_RSCTMP}/nfsnotify_${OCF_RESOURCE_INSTANCE}/"
HA_STATD_PIDFILE="$NFSNOTIFY_TMP_DIR/rpc.statd_${OCF_RESOURCE_INSTANCE}.pid"
HA_STATD_PIDFILE_PREV="$NFSNOTIFY_TMP_DIR/rpc.statd_${OCF_RESOURCE_INSTANCE}.pid.prev"
STATD_PATH="/var/lib/nfs/statd"
SM_NOTIFY_BINARY="${sbindir}/sm-notify"
IS_RENOTIFY=0
meta_data() {
	cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="nfsnotify" version="0.9">
<version>1.0</version>
<longdesc lang="en">
This agent sends NFSv3 reboot notifications to clients which informs clients to reclaim locks.
</longdesc>
<shortdesc lang="en">sm-notify reboot notifications</shortdesc>
<parameters>
<parameter name="source_host" unique="0" required="0">
<longdesc lang="en">
Comma separated list of floating IP addresses or host names that clients use
to access the nfs service.  This will be used to set the source address and
mon_name of the SN_NOTIFY reboot notifications.
</longdesc>
<shortdesc lang="en">source IP addresses</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="notify_args" unique="0" required="0">
<longdesc lang="en">
Additional arguments to send to the sm-notify command. By default
this agent will always set sm-notify's '-f' option.  When the
source_host option is set, the '-v' option will be used automatically
to set the proper source address. Any additional sm-notify arguments
set with this option will be used in addition to the previous default
arguments.
</longdesc>
<shortdesc lang="en">sm-notify arguments</shortdesc>
<content type="string" default="false" />
</parameter>
</parameters>
<actions>
<action name="start"        timeout="90" />
<action name="stop"         timeout="90" />
<action name="monitor"      timeout="90" interval="30" depth="0" />
<action name="reload"       timeout="90" />
<action name="meta-data"    timeout="10" />
<action name="validate-all"   timeout="20" />
</actions>
</resource-agent>
END
}
v3notify_usage()
{
	cat <<END
usage: $0 {start|stop|monitor|validate-all|meta-data}
Expects to have a fully populated OCF RA-compliant environment set.
END
}
v3notify_validate()
{
	# check_binary will exit with OCF_ERR_INSTALLED when binary is missing
	check_binary "$SM_NOTIFY_BINARY"
	check_binary "pgrep"
	check_binary "killall"
	return $OCF_SUCCESS
}
killall_smnotify()
{
	# killall sm-notify 
	killall -TERM $SM_NOTIFY_BINARY > /dev/null 2>&1
	if [ $? -eq 0 ]; then
		# it is useful to know if sm-notify processes were actually left around
		# or not during the stop/start operation. Whether this condition is true
		# or false does not indicate a failure. It does indicate that 
		# there are probably some unresponsive nfs clients out there that are keeping
		# the sm-notify processes retrying.
		ocf_log info "previous sm-notify processes terminated before $__OCF_ACTION action."
	fi
}
v3notify_stop()
{
	killall_smnotify
	rm -f $HA_STATD_PIDFILE_PREV > /dev/null 2>&1
	mv $HA_STATD_PIDFILE $HA_STATD_PIDFILE_PREV > /dev/null 2>&1
	return $OCF_SUCCESS
}
check_statd_pidfile()
{
	local binary="rpc.statd"
	local pidfile="$HA_STATD_PIDFILE"
	ocf_log debug "Checking status for ${binary}."
	if [ -e "$pidfile" ]; then
		cat /proc/$(cat $pidfile)/cmdline 2>/dev/null | grep -a "${binary}" > /dev/null 2>&1
		if [ $? -eq 0 ]; then
			return $OCF_SUCCESS
		fi
		ocf_exit_reason "$(cat $pidfile) for $binary is no longer running, sm-notify needs to re-notify clients"
		return $OCF_ERR_GENERIC
	fi
	# if we don't have a pid file for rpc.statd, we have not yet sent the notifications
	return $OCF_NOT_RUNNING
}
write_statd_pid()
{
	local binary="rpc.statd"
	local pidfile="$HA_STATD_PIDFILE"
	local pid
	pid=$(pgrep ${binary})
	case $? in
		0)
			ocf_log info "PID file (pid:${pid} at $pidfile) created for ${binary}."
			mkdir -p $(dirname $pidfile)
			echo "$pid" > $pidfile
			return $OCF_SUCCESS;;
		1)
			rm -f "$pidfile" > /dev/null 2>&1 
			ocf_log info "$binary is not running"
			return $OCF_NOT_RUNNING;;
		*)
			rm -f "$pidfile" > /dev/null 2>&1 
		  	ocf_exit_reason "Error encountered detecting pid status of $binary"
			return $OCF_ERR_GENERIC;;
	esac
}
copy_statd()
{
	local src=$1
	local dest=$2
	if ! [ -d "$dest" ]; then
		mkdir -p "$dest"
	fi
	cp -rpfn $src/sm $src/sm.bak $src/state $dest > /dev/null 2>&1
	# make sure folder ownership and selinux lables stay consistent
	[ -n "`id -u rpcuser`" -a "`id -g rpcuser`" ] && chown rpcuser.rpcuser "$dest"
	[ $SELINUX_ENABLED -eq 0 ] && chcon -R "$SELINUX_LABEL" "$dest"
}
v3notify_start()
{
	local rc=$OCF_SUCCESS
	local cur_statd
	local statd_backup
	local is_renotify=0
	# monitor, see if we need to notify or not
	v3notify_monitor
	if [ $? -eq 0 ]; then
		return $OCF_SUCCESS
	fi
	# kill off any other sm-notify processes that might already be running.
	killall_smnotify
	# record the pid of rpc.statd. if this pid ever changes, we have to re-notify
	write_statd_pid
	rc=$?
	if [ $rc -ne 0 ]; then
		return $rc
	fi
	# if the last time we ran nfs-notify, it was with the same statd process,
	# consider this a re-notification. During re-notifications we do not let the
	# sm-notify binary have access to the real statd directory.
	if [ "$(cat $HA_STATD_PIDFILE)" = "$(cat $HA_STATD_PIDFILE_PREV 2>/dev/null)" ]; then
		ocf_log info "Renotifying clients"
		is_renotify=1
	fi
	statd_backup="$STATD_PATH/nfsnotify.bu"
	copy_statd "$STATD_PATH" "$statd_backup"
	if [ -z "$OCF_RESKEY_source_host" ]; then
		if [ "$is_renotify" -eq 0 ]; then
			cur_statd="$STATD_PATH"
		else 
			cur_statd="$statd_backup"
		fi
		ocf_log info "sending notifications on default source address."
		$SM_NOTIFY_BINARY -f $OCF_RESKEY_notify_args -P $cur_statd
		if [ $? -ne 0 ]; then
			ocf_exit_reason "sm-notify execution failed, view syslog for more information"
			return $OCF_ERR_GENERIC
		fi
		
		return $OCF_SUCCESS
	fi
	# do sm-notify for each ip
	for ip in `echo ${OCF_RESKEY_source_host} | sed 's/,/ /g'`; do
		# have the first sm-notify use the actual statd directory so the
		# notify list can be managed properly.
		if [ "$is_renotify" -eq 0 ]; then
			cur_statd="$STATD_PATH"
			# everything after the first notify we are considering a renotification
			# which means we don't use the real statd directory. 
			is_renotify=1
		else 
			# use our copied statd directory for the remaining ip addresses
			cur_statd="$STATD_PATH/nfsnotify_${OCF_RESOURCE_INSTANCE}_${ip}"
			copy_statd "$statd_backup" "$cur_statd"
		fi
		ocf_log info "sending notifications with source address $ip"
		$SM_NOTIFY_BINARY -f $OCF_RESKEY_notify_args -v $ip -P "$cur_statd"
		if [ $? -ne 0 ]; then
			ocf_exit_reason "sm-notify with source host set to [ $ip ] failed. view syslog for more information"
			return $OCF_ERR_GENERIC
		fi
	done
	return $OCF_SUCCESS
}
v3notify_monitor()
{
	# verify rpc.statd is up, and that the rpc.statd pid is the same one we
	# found during the start. otherwise rpc.statd recovered and we need to notify
	# again.
	check_statd_pidfile
}
case $__OCF_ACTION in
	meta-data)   meta_data
		exit $OCF_SUCCESS;;
	usage|help)    v3notify_usage
		exit $OCF_SUCCESS;;
	*)
		;;
esac
which restorecon > /dev/null 2>&1 && selinuxenabled
SELINUX_ENABLED=$?
if [ $SELINUX_ENABLED -eq 0 ]; then
	export SELINUX_LABEL="$(ls -ldZ $STATD_PATH | cut -f4 -d' ')"
fi
case $__OCF_ACTION in
	start)         v3notify_start;;
	stop)          v3notify_stop;;
	monitor)       v3notify_monitor;;
	validate-all)  v3notify_validate;;
	*)             v3notify_usage
	               exit $OCF_ERR_UNIMPLEMENTED;;
esac
rc=$?
ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
exit $rc
 |