/usr/lib/ocf/resource.d/heartbeat/sfex is in resource-agents 1:4.0.0~rc1-4.
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 | #!/bin/sh
#
# Shared Disk File EXclusiveness (SF-EX) OCF RA.
# prevent a destruction of data on shared disk file system
# due to Split-Brain.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
# Copyright (c) 2007 NIPPON TELEGRAPH AND TELEPHONE CORPORATION
#
# NOTE:
# As a prerequisite for running SF-EX, one device should be
# initialized as below.
#
# sfex_init [-n <numlocks>] <device>
#
# Example:
#
# /usr/sbin/sfex_init -n 10 /dev/sdb1
#
# if further information is necessary, See README.
#
#######################################################################
# Initialization:
# switching ocf-shellfuncs path
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
#######################################################################
SFEX_DAEMON=${HA_BIN}/sfex_daemon
usage() {
cat <<END
usage: $0 {start|stop|monitor|meta-data}
END
}
meta_data() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="sfex">
<version>1.3</version>
<longdesc lang="en">
Resource script for SF-EX. It manages a shared storage medium exclusively .
</longdesc>
<shortdesc lang="en">Manages exclusive access to shared storage using Shared Disk File EXclusiveness (SF-EX)</shortdesc>
<parameters>
<parameter name="device" unique="0" required="1">
<longdesc lang="en">
Block device path that stores exclusive control data.
</longdesc>
<shortdesc lang="en">block device</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="index" unique="0" required="0">
<longdesc lang="en">
Location in block device where exclusive control data is stored. 1 or more is specified. Default is 1.
</longdesc>
<shortdesc lang="en">index</shortdesc>
<content type="integer" default="1" />
</parameter>
<parameter name="collision_timeout" unique="0" required="0">
<longdesc lang="en">
Waiting time when a collision of lock acquisition is detected. Default is 1 second.
</longdesc>
<shortdesc lang="en">waiting time for lock acquisition</shortdesc>
<content type="integer" default="1" />
</parameter>
<parameter name="monitor_interval" unique="0" required="0">
<longdesc lang="en">
Monitor interval(sec). Default is 10 seconds
</longdesc>
<shortdesc lang="en">monitor interval</shortdesc>
<content type="integer" default="10" />
</parameter>
<parameter name="lock_timeout" unique="0" required="0">
<longdesc lang="en">
Valid term of lock(sec). Default is 100 seconds.
The lock_timeout is calculated by the following formula.
lock_timeout = monitor_interval + "The expiration time of the lock"
We suggest 90 seconds as a default value of the "The expiration time of the lock", but you should change it in consideration of access delay to the shared disk and the switch time of the multipath driver.
The lock timeout have an impact on start action timeout because start action timeout value is calculated by the following formula.
start timeout = collision_timeout + lock_timeout + "safety margin"
The "safety margin" is decided within the range of about 10-20 seconds(It depends on your system requirement).
</longdesc>
<shortdesc lang="en">Valid term of lock</shortdesc>
<content type="integer" default="100" />
</parameter>
</parameters>
<actions>
<action name="start" timeout="120s" />
<action name="stop" timeout="20s" />
<action name="monitor" depth="0" timeout="10s" interval="10s" />
<action name="meta-data" timeout="5s" />
<action name="validate-all" timeout="5s" />
</actions>
</resource-agent>
END
}
#
# START: Exclusive control starts.
#
# It loops permanently until the lock can be acquired when locked with
# the other node. In this case, the reception of the stop signal by the
# timeout time passage set to CIB becomes the only stop opportunity.
#
sfex_start() {
ocf_log info "sfex_daemon: starting..."
sfex_monitor
if [ $? -eq $OCF_SUCCESS ]; then
ocf_log info "sfex_daemon already started."
return $OCF_SUCCESS
fi
$SFEX_DAEMON -i $INDEX -c $COLLISION_TIMEOUT -t $LOCK_TIMEOUT -m $MONITOR_INTERVAL -r ${OCF_RESOURCE_INSTANCE} $DEVICE
rc=$?
if [ $rc -ne 0 ]; then
ocf_log err "sfex_daemon failed to start."
return $OCF_ERR_GENERIC
fi
while :
do
sfex_monitor
if [ $? -eq $OCF_SUCCESS ]; then
ocf_log info "sfex_daemon: started."
return $OCF_SUCCESS
fi
ocf_log debug "Waiting for the start-up of the sfex_daemon..."
sleep 1
done
ocf_log err "Can't find a sfex_daemon process. Starting a sfex_daemon failed."
return $OCF_ERR_GENERIC
}
#
# STOP: stop exclusive control
#
sfex_stop() {
ocf_log info "sfex_daemon: stopping..."
# Check the sfex daemon has already stopped.
sfex_monitor
if [ $? -eq $OCF_NOT_RUNNING ]; then
ocf_log info "sfex_daemon already stopped."
return $OCF_SUCCESS
fi
# Stop sfex daemon by sending SIGTERM signal.
pid=`/usr/bin/pgrep -f "$SFEX_DAEMON .* ${OCF_RESOURCE_INSTANCE} "`
/bin/kill $pid
rc=$?
if [ $rc -ne 0 ]; then
ocf_log err "sfex_daemon failed to stop"
return $rc
fi
#sfex could be in state D if the device is gone, and then not terminate.
#Wait and check again if the daemon is already properly shutdown.
shutdown_timeout=$((($OCF_RESKEY_CRM_meta_timeout/1000)-5))
count=0
while [ $count -lt $shutdown_timeout ]
do
sfex_monitor
if [ $? -eq $OCF_NOT_RUNNING ]; then
ocf_log info "sfex_daemon: stopped."
return $OCF_SUCCESS
fi
count=`expr $count + 1`
ocf_log debug "waiting for sfex_daemon to exit ($count/$shutdown_timeout)"
sleep 1
done
sfex_monitor
if [ $? -ne $OCF_NOT_RUNNING ]; then
ocf_log warn "regular shutdown of sfex_daemon timed out, using SIGKILL"
/bin/kill -s KILL $pid
fi
while :
do
sfex_monitor
if [ $? -eq $OCF_NOT_RUNNING ]; then
break;
fi
ocf_log debug "waiting for sfex_daemon to exit after SIGKILL"
sleep 1
done
ocf_log info "sfex_daemon: stopped."
return $OCF_SUCCESS
}
sfex_monitor() {
ocf_log debug "sfex_monitor: started..."
# Find a sfex_daemon process using daemon name and resource name.
if /usr/bin/pgrep -f "$SFEX_DAEMON .* ${OCF_RESOURCE_INSTANCE} " > /dev/null 2>&1; then
ocf_log debug "sfex_monitor: complete. sfex_daemon is running."
return $OCF_SUCCESS
fi
ocf_log debug "sfex_monitor: complete. sfex_daemon is not running."
return $OCF_NOT_RUNNING
}
#
# main process
#
# check arguments
if [ $# -ne 1 ]; then
usage
exit $OCF_ERR_ARGS
fi
OP=$1
# These operations do not require instance parameters
case $OP in
meta-data)
meta_data
exit $OCF_SUCCESS
;;
usage)
usage
exit $OCF_SUCCESS
;;
esac
# check parameters
DEVICE=$OCF_RESKEY_device
INDEX=${OCF_RESKEY_index:-1}
COLLISION_TIMEOUT=${OCF_RESKEY_collision_timeout:-1}
LOCK_TIMEOUT=${OCF_RESKEY_lock_timeout:-100}
MONITOR_INTERVAL=${OCF_RESKEY_monitor_interval:-10}
sfex_validate () {
if [ -z "$DEVICE" ]; then
ocf_log err "Please set OCF_RESKEY_device to device for sfex meta-data"
exit $OCF_ERR_ARGS
fi
if [ ! -w "$DEVICE" ]; then
ocf_log warn "Couldn't find device [$DEVICE]. Expected /dev/??? to exist"
exit $OCF_ERR_ARGS
fi
}
if [ -n "$OCF_RESKEY_CRM_meta_clone" ]; then
ocf_log err "THIS RA DO NOT SUPPORT CLONE MODE!"
exit $OCF_ERR_CONFIGURED
fi
case $OP in
start)
sfex_start
;;
stop)
sfex_stop
;;
monitor)
sfex_monitor
;;
validate-all)
sfex_validate
;;
*)
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
exit $?
|