| 1 | #!/bin/sh |
| 2 | # |
| 3 | # SAPInstance |
| 4 | # |
| 5 | # Description: Manages a single SAP Instance as a High-Availability |
| 6 | # resource. One SAP Instance is defined by one |
| 7 | # SAP Instance-Profile. start/stop handels all services |
| 8 | # of the START-Profile, status and monitor care only |
| 9 | # about essential services. |
| 10 | # |
| 11 | # Author: Alexander Krauth, June 2006 |
| 12 | # Support: [email protected] |
| 13 | # License: GNU General Public License (GPL) |
| 14 | # Copyright: (c) 2006, 2007 Alexander Krauth |
| 15 | # |
| 16 | # An example usage: |
| 17 | # See usage() function below for more details... |
| 18 | # |
| 19 | # OCF instance parameters: |
| 20 | # OCF_RESKEY_InstanceName |
| 21 | # OCF_RESKEY_DIR_EXECUTABLE (optional, well known directories will be searched by default) |
| 22 | # OCF_RESKEY_DIR_PROFILE (optional, well known directories will be searched by default) |
| 23 | # OCF_RESKEY_START_PROFILE (optional, well known directories will be searched by default) |
| 24 | # OCF_RESKEY_START_WAITTIME (optional, to solve timing problems during J2EE-Addin start) |
| 25 | # OCF_RESKEY_AUTOMATIC_RECOVER (optional, automatic startup recovery using cleanipc, default is false) |
| 26 | # OCF_RESKEY_PRE_START_USEREXIT (optional, lists a script which can be executed before the resource is started) |
| 27 | # OCF_RESKEY_POST_START_USEREXIT (optional, lists a script which can be executed after the resource is started) |
| 28 | # OCF_RESKEY_PRE_STOP_USEREXIT (optional, lists a script which can be executed before the resource is stopped) |
| 29 | # OCF_RESKEY_POST_STOP_USEREXIT (optional, lists a script which can be executed after the resource is stopped) |
| 30 | # |
| 31 | ####################################################################### |
| 32 | # Initialization: |
| 33 | |
| 34 | if [ -f $(dirname $0)/.ocf-shellfuncs ]; then |
| 35 | . $(dirname $0)/.ocf-shellfuncs |
| 36 | elif [ -f $(dirname $0)/ocf-shellfuncs ]; then |
| 37 | LC_ALL=C |
| 38 | LANG=C |
| 39 | PATH=/bin:/sbin:/usr/bin:/usr/sbin |
| 40 | export LC_ALL LANG PATH |
| 41 | . $(dirname $0)/ocf-shellfuncs |
| 42 | else |
| 43 | echo Could not find ocf-shellfuncs! |
| 44 | exit 1 |
| 45 | fi |
| 46 | |
| 47 | |
| 48 | ####################################################################### |
| 49 | |
| 50 | SH=/bin/sh |
| 51 | |
| 52 | usage() { |
| 53 | methods=`sapinstance_methods` |
| 54 | methods=`echo $methods | tr ' ' '|'` |
| 55 | cat <<-! |
| 56 | usage: $0 ($methods) |
| 57 | |
| 58 | $0 manages a SAP Instance as an HA resource. |
| 59 | |
| 60 | The 'start' operation starts the instance. |
| 61 | The 'stop' operation stops the instance. |
| 62 | The 'status' operation reports whether the instance is running |
| 63 | The 'monitor' operation reports whether the instance seems to be working |
| 64 | The 'validate-all' operation reports whether the parameters are valid |
| 65 | The 'methods' operation reports on the methods $0 supports |
| 66 | |
| 67 | ! |
| 68 | } |
| 69 | |
| 70 | meta_data() { |
| 71 | cat <<END |
| 72 | <?xml version="1.0"?> |
| 73 | <!DOCTYPE resource-agent SYSTEM "ra-api-1-modified.dtd"> |
| 74 | <resource-agent name="SAPInstance"> |
| 75 | <version>1.92.1</version> |
| 76 | |
| 77 | <longdesc lang="en"> |
| 78 | Resource script for SAP. It manages a SAP Instance as an HA resource. |
| 79 | </longdesc> |
| 80 | <shortdesc lang="en">SAP instance resource agent</shortdesc> |
| 81 | |
| 82 | <parameters> |
| 83 | <parameter name="InstanceName" unique="1" required="1" primary="1"> |
| 84 | <longdesc lang="en">The full qualified SAP instance name. e.g. P01_DVEBMGS00_sapp01ci</longdesc> |
| 85 | <shortdesc lang="en">instance name: SID_INSTANCE_VIR-HOSTNAME</shortdesc> |
| 86 | <content type="string" default="" /> |
| 87 | </parameter> |
| 88 | <parameter name="DIR_EXECUTABLE" unique="0" required="0"> |
| 89 | <longdesc lang="en">The full qualified path where to find sapstartsrv and sapcontrol.</longdesc> |
| 90 | <shortdesc lang="en">path of sapstartsrv and sapcontrol</shortdesc> |
| 91 | <content type="string" default="" /> |
| 92 | </parameter> |
| 93 | <parameter name="DIR_PROFILE" unique="0" required="0"> |
| 94 | <longdesc lang="en">The full qualified path where to find the SAP START profile.</longdesc> |
| 95 | <shortdesc lang="en">path of start profile</shortdesc> |
| 96 | <content type="string" default="" /> |
| 97 | </parameter> |
| 98 | <parameter name="START_PROFILE" unique="0" required="0"> |
| 99 | <longdesc lang="en">The name of the SAP START profile.</longdesc> |
| 100 | <shortdesc lang="en">start profile name</shortdesc> |
| 101 | <content type="string" default="" /> |
| 102 | </parameter> |
| 103 | <parameter name="START_WAITTIME" unique="0" required="0"> |
| 104 | <longdesc lang="en">After that time in seconds a monitor operation is executed by the resource agent. Does the monitor return SUCCESS, the start is handled as SUCCESS. This is useful to resolve timing problems with e.g. the J2EE-Addin instance.</longdesc> |
| 105 | <shortdesc lang="en">Check the successful start after that time (do not wait for J2EE-Addin)</shortdesc> |
| 106 | <content type="string" default="3600" /> |
| 107 | </parameter> |
| 108 | <parameter name="AUTOMATIC_RECOVER" unique="0" required="0"> |
| 109 | <longdesc lang="en">The SAPInstance resource agent tries to recover a failed start attempt automatically one time. This is done by killing running instance processes and executing cleanipc.</longdesc> |
| 110 | <shortdesc lang="en">Enable or disable automatic startup recovery</shortdesc> |
| 111 | <content type="boolean" default="false"/> |
| 112 | </parameter> |
| 113 | <parameter name="PRE_START_USEREXIT" unique="0" required="0"> |
| 114 | <longdesc lang="en">The full qualified path where to find a script or program which should be executed before this resource gets started.</longdesc> |
| 115 | <shortdesc lang="en">path to a pre-start script</shortdesc> |
| 116 | <content type="string" default="" /> |
| 117 | </parameter> |
| 118 | <parameter name="POST_START_USEREXIT" unique="0" required="0"> |
| 119 | <longdesc lang="en">The full qualified path where to find a script or program which should be executed after this resource got started.</longdesc> |
| 120 | <shortdesc lang="en">path to a post-start script</shortdesc> |
| 121 | <content type="string" default="" /> |
| 122 | </parameter> |
| 123 | <parameter name="PRE_STOP_USEREXIT" unique="0" required="0"> |
| 124 | <longdesc lang="en">The full qualified path where to find a script or program which should be executed before this resource gets stopped.</longdesc> |
| 125 | <shortdesc lang="en">path to a pre-start script</shortdesc> |
| 126 | <content type="string" default="" /> |
| 127 | </parameter> |
| 128 | <parameter name="POST_STOP_USEREXIT" unique="0" required="0"> |
| 129 | <longdesc lang="en">The full qualified path where to find a script or program which should be executed after this resource got stopped.</longdesc> |
| 130 | <shortdesc lang="en">path to a post-start script</shortdesc> |
| 131 | <content type="string" default="" /> |
| 132 | </parameter> |
| 133 | </parameters> |
| 134 | |
| 135 | <actions> |
| 136 | <action name="start" timeout="180" /> |
| 137 | <action name="stop" timeout="240" /> |
| 138 | <action name="status" timeout="60" depth="0" interval="120" start-delay="240" /> |
| 139 | <action name="monitor" depth="0" timeout="60" interval="120" start-delay="240" /> |
| 140 | <action name="validate-all" timeout="5" /> |
| 141 | <action name="meta-data" timeout="5" /> |
| 142 | <action name="methods" timeout="5" /> |
| 143 | </actions> |
| 144 | </resource-agent> |
| 145 | END |
| 146 | } |
| 147 | |
| 148 | |
| 149 | # |
| 150 | # methods: What methods/operations do we support? |
| 151 | # |
| 152 | sapinstance_methods() { |
| 153 | cat <<-! |
| 154 | start |
| 155 | stop |
| 156 | status |
| 157 | monitor |
| 158 | validate-all |
| 159 | methods |
| 160 | meta-data |
| 161 | usage |
| 162 | ! |
| 163 | } |
| 164 | |
| 165 | # |
| 166 | # setup_limits: If sapstartsrv needs to be started by this resource agent we need to ensure that any resource |
| 167 | # limits configured in /usr/sap/sapservices are applied. |
| 168 | # Since sapstartsrv is started as root and then it downgrades its privileges by calling setuid() and |
| 169 | # setgid() any PAM limits at /etc/security/limits.conf are not applied. |
| 170 | # Should sapstartsrv need to be started, we look for values configured at /usr/sap/sapservices (as |
| 171 | # per SAP note 1437105) and, if found, we apply them before starting sapstartsrv. |
| 172 | # Instance processes are started by sapstartsrv and will inherit resource limits from it. |
| 173 | # |
| 174 | setup_limits() { |
| 175 | if [ -r $SAPSERVICES ] |
| 176 | then |
| 177 | descriptors=`grep "^limit.descriptors" $SAPSERVICES | sed -e "s/limit.descriptors=//" ` |
| 178 | if [ -n $descriptors ] |
| 179 | then |
| 180 | ocf_log info "found valid open file descriptors limit at ${SAPSERVICES}: ${descriptors}, applying..." |
| 181 | eval ulimit -n $descriptors |
| 182 | fi |
| 183 | |
| 184 | stacksize=`grep "^limit.stacksize" $SAPSERVICES | sed -e "s/limit.stacksize=//" ` |
| 185 | if [ -n $stacksize ] |
| 186 | then |
| 187 | ocf_log info "found valid stack size limit at ${SAPSERVICES}: ${stacksize}, applying..." |
| 188 | eval ulimit -s $stacksize |
| 189 | fi |
| 190 | |
| 191 | datasize=`grep "^limit.datasize" $SAPSERVICES | sed -e "s/limit.datasize=//" ` |
| 192 | if [ -n $datasize ] |
| 193 | then |
| 194 | ocf_log info "found valid process data segment size limit at ${SAPSERVICES}: ${datasize}, applying..." |
| 195 | eval ulimit -d $datasize |
| 196 | fi |
| 197 | fi |
| 198 | } |
| 199 | |
| 200 | # |
| 201 | # check_sapstartsrv : Before using sapcontrol we make sure that the sapstartsrv is running for the correct instance. |
| 202 | # We cannot use sapinit and the /usr/sap/sapservices file in case of an enquerep instance, |
| 203 | # because then we have two instances with the same instance number. |
| 204 | # |
| 205 | check_sapstartsrv() { |
| 206 | restart=0 |
| 207 | runninginst="" |
| 208 | chkrc=$OCF_SUCCESS |
| 209 | |
| 210 | output=`$SAPCONTROL -nr $InstanceNr -function ParameterValue INSTANCE_NAME -format script` |
| 211 | if [ $? -eq 0 ] |
| 212 | then |
| 213 | runninginst=`echo "$output" | grep '^0 : ' | cut -d' ' -f3` |
| 214 | if [ "$runninginst" != "$InstanceName" ] |
| 215 | then |
| 216 | ocf_log warn "sapstartsrv is running for instance $runninginst, that service will be killed" |
| 217 | restart=1 |
| 218 | fi |
| 219 | else |
| 220 | ocf_log warn "sapstartsrv is not running for instance $SID-$InstanceName, it will be started now" |
| 221 | restart=1 |
| 222 | fi |
| 223 | |
| 224 | if [ -z "$runninginst" ]; then runninginst=$InstanceName; fi |
| 225 | |
| 226 | if [ $restart -eq 1 ] |
| 227 | then |
| 228 | pkill -9 -f "sapstartsrv.*$runninginst" |
| 229 | |
| 230 | setup_limits |
| 231 | $SAPSTARTSRV pf=$SAPSTARTPROFILE -D -u $sidadm |
| 232 | |
| 233 | # now make sure the daemon has been started and is able to respond |
| 234 | srvrc=1 |
| 235 | while [ $srvrc -eq 1 -a `pgrep -f "sapstartsrv.*$runninginst" | wc -l` -gt 0 ] |
| 236 | do |
| 237 | sleep 1 |
| 238 | $SAPCONTROL -nr $InstanceNr -function GetProcessList > /dev/null 2>&1 |
| 239 | srvrc=$? |
| 240 | done |
| 241 | |
| 242 | if [ $srvrc -ne 1 ] |
| 243 | then |
| 244 | ocf_log info "sapstartsrv for instance $SID-$InstanceName was restarted !" |
| 245 | chkrc=$OCF_SUCCESS |
| 246 | else |
| 247 | ocf_log error "sapstartsrv for instance $SID-$InstanceName could not be started!" |
| 248 | chkrc=$OCF_NOT_RUNNING |
| 249 | fi |
| 250 | fi |
| 251 | |
| 252 | return $chkrc |
| 253 | } |
| 254 | |
| 255 | |
| 256 | # |
| 257 | # sapuserexit : Many SAP customers need some additional processes/tools to run their SAP systems. |
| 258 | # This specialties do not allow a totally generic SAP cluster resource agent. |
| 259 | # Someone should write a resource agent for each additional process you need, if it |
| 260 | # is required to monitor that process within the cluster manager. To enable |
| 261 | # you to extent this resource agent without developing a new one, this user exit |
| 262 | # was introduced. |
| 263 | # |
| 264 | sapuserexit() { |
| 265 | NAME="$1" |
| 266 | VALUE="$2" |
| 267 | |
| 268 | if [ -n "$VALUE" ] |
| 269 | then |
| 270 | if [ -x "$VALUE" ] |
| 271 | then |
| 272 | ocf_log info "Calling userexit ${NAME} with customer script file ${VALUE}" |
| 273 | eval "$VALUE" > /dev/null 2>&1 |
| 274 | ocf_log info "Exiting userexit ${NAME} with customer script file ${VALUE}, returncode: $?" |
| 275 | else |
| 276 | ocf_log warn "Attribute ${NAME} is set to ${VALUE}, but this file is not executable" |
| 277 | fi |
| 278 | fi |
| 279 | return 0 |
| 280 | } |
| 281 | |
| 282 | |
| 283 | # |
| 284 | # cleanup_instance : remove resources (processes and shared memory) from a crashed instance) |
| 285 | # |
| 286 | cleanup_instance() { |
| 287 | pkill -9 -f -U $sidadm $InstanceName |
| 288 | $DIR_EXECUTABLE/cleanipc $InstanceNr remove |
| 289 | return 0 |
| 290 | } |
| 291 | |
| 292 | # |
| 293 | # sapinstance_start : Start the SAP instance |
| 294 | # |
| 295 | sapinstance_start() { |
| 296 | |
| 297 | sapuserexit PRE_START_USEREXIT "$OCF_RESKEY_PRE_START_USEREXIT" |
| 298 | |
| 299 | rc=$OCF_NOT_RUNNING |
| 300 | loopcount=0 |
| 301 | while [ $loopcount -lt 2 ] |
| 302 | do |
| 303 | loopcount=$(($loopcount + 1)) |
| 304 | |
| 305 | check_sapstartsrv |
| 306 | output=`$SAPCONTROL -nr $InstanceNr -function Start` |
| 307 | rc=$? |
| 308 | ocf_log info "Starting SAP Instance $SID-$InstanceName: $output" |
| 309 | |
| 310 | if [ $rc -ne 0 ] |
| 311 | then |
| 312 | ocf_log err "SAP Instance $SID-$InstanceName start failed." |
| 313 | return $OCF_ERR_GENERIC |
| 314 | fi |
| 315 | |
| 316 | startrc=1 |
| 317 | while [ $startrc -gt 0 ] |
| 318 | do |
| 319 | waittime_start=`date +%s` |
| 320 | output=`$SAPCONTROL -nr $InstanceNr -function WaitforStarted $OCF_RESKEY_START_WAITTIME 10` |
| 321 | startrc=$? |
| 322 | waittime_stop=`date +%s` |
| 323 | |
| 324 | if [ $startrc -ne 0 ] |
| 325 | then |
| 326 | if [ $(($waittime_stop - $waittime_start)) -ge $OCF_RESKEY_START_WAITTIME ] |
| 327 | then |
| 328 | sapinstance_monitor NOLOG |
| 329 | if [ $? -eq $OCF_SUCCESS ] |
| 330 | then |
| 331 | output="START_WAITTIME ($OCF_RESKEY_START_WAITTIME) has elapsed, but instance monitor returned SUCCESS. Instance considered running." |
| 332 | startrc=0; loopcount=2 |
| 333 | fi |
| 334 | else |
| 335 | if [ $loopcount -eq 1 -a $OCF_RESKEY_AUTOMATIC_RECOVER -eq 1 ] |
| 336 | then |
| 337 | ocf_log warn "SAP Instance $SID-$InstanceName start failed: $output" |
| 338 | ocf_log warn "Try to recover $SID-$InstanceName" |
| 339 | cleanup_instance |
| 340 | else |
| 341 | loopcount=2 |
| 342 | fi |
| 343 | startrc=-1 |
| 344 | fi |
| 345 | else |
| 346 | loopcount=2 |
| 347 | fi |
| 348 | done |
| 349 | done |
| 350 | |
| 351 | if [ $startrc -eq 0 ] |
| 352 | then |
| 353 | ocf_log info "SAP Instance $SID-$InstanceName started: $output" |
| 354 | rc=$OCF_SUCCESS |
| 355 | sapuserexit POST_START_USEREXIT "$OCF_RESKEY_POST_START_USEREXIT" |
| 356 | else |
| 357 | ocf_log err "SAP Instance $SID-$InstanceName start failed: $output" |
| 358 | rc=$OCF_NOT_RUNNING |
| 359 | fi |
| 360 | |
| 361 | return $rc |
| 362 | } |
| 363 | |
| 364 | |
| 365 | # |
| 366 | # sapinstance_recover: Try startup of failed instance by cleaning up resources |
| 367 | # |
| 368 | sapinstance_recover() { |
| 369 | cleanup_instance |
| 370 | sapinstance_start |
| 371 | return $? |
| 372 | } |
| 373 | |
| 374 | |
| 375 | # |
| 376 | # sapinstance_stop: Stop the SAP instance |
| 377 | # |
| 378 | sapinstance_stop() { |
| 379 | sapuserexit PRE_STOP_USEREXIT "$OCF_RESKEY_PRE_STOP_USEREXIT" |
| 380 | |
| 381 | check_sapstartsrv |
| 382 | |
| 383 | output=`$SAPCONTROL -nr $InstanceNr -function Stop` |
| 384 | if [ $? -eq 0 ] |
| 385 | then |
| 386 | output=`$SAPCONTROL -nr $InstanceNr -function WaitforStopped 3600 1` |
| 387 | if [ $? -eq 0 ] |
| 388 | then |
| 389 | ocf_log info "SAP Instance $SID-$InstanceName stopped: $output" |
| 390 | rc=$OCF_SUCCESS |
| 391 | else |
| 392 | ocf_log err "SAP Instance $SID-$InstanceName stop failed: $output" |
| 393 | rc=$OCF_ERR_GENERIC |
| 394 | fi |
| 395 | else |
| 396 | ocf_log err "SAP Instance $SID-$InstanceName stop failed: $output" |
| 397 | rc=$OCF_ERR_GENERIC |
| 398 | fi |
| 399 | |
| 400 | sapuserexit POST_STOP_USEREXIT "$OCF_RESKEY_POST_STOP_USEREXIT" |
| 401 | |
| 402 | return $rc |
| 403 | } |
| 404 | |
| 405 | |
| 406 | # |
| 407 | # sapinstance_monitor: Can the given SAP instance do anything useful? |
| 408 | # |
| 409 | sapinstance_monitor() { |
| 410 | MONLOG=$1 |
| 411 | check_sapstartsrv |
| 412 | rc=$? |
| 413 | |
| 414 | if [ $rc -eq $OCF_SUCCESS ] |
| 415 | then |
| 416 | count=0 |
| 417 | LOCALHOST=`hostname` |
| 418 | output=`$SAPCONTROL -nr $InstanceNr -host $LOCALHOST -function GetProcessList -format script` |
| 419 | |
| 420 | # we have to parse the output, because the returncode doesn't tell anything about the instance status |
| 421 | for SERVNO in `echo "$output" | grep '^[0-9] ' | cut -d' ' -f1 | sort -u` |
| 422 | do |
| 423 | COLOR=`echo "$output" | grep "^$SERVNO dispstatus: " | cut -d' ' -f3` |
| 424 | SERVICE=`echo "$output" | grep "^$SERVNO name: " | cut -d' ' -f3` |
| 425 | STATE=0 |
| 426 | |
| 427 | case $COLOR in |
| 428 | GREEN|YELLOW) STATE=$OCF_SUCCESS;; |
| 429 | *) STATE=$OCF_NOT_RUNNING;; |
| 430 | esac |
| 431 | |
| 432 | case $SERVICE in |
| 433 | disp+work|msg_server|enserver|enrepserver|jcontrol|jstart) |
| 434 | if [ $STATE -eq $OCF_NOT_RUNNING ] |
| 435 | then |
| 436 | if [ "$MONLOG" != "NOLOG" ] |
| 437 | then |
| 438 | ocf_log err "SAP instance service $SERVICE is not running with status $COLOR !" |
| 439 | fi |
| 440 | rc=$STATE |
| 441 | fi |
| 442 | count=1;; |
| 443 | *);; |
| 444 | esac |
| 445 | done |
| 446 | |
| 447 | if [ $count -eq 0 -a $rc -eq $OCF_SUCCESS ] |
| 448 | then |
| 449 | if [ "$MONLOG" != "NOLOG" ] |
| 450 | then |
| 451 | ocf_log err "The SAP instance does not run any services which this RA could monitor!" |
| 452 | fi |
| 453 | rc=$OCF_ERR_ARGS |
| 454 | fi |
| 455 | fi |
| 456 | |
| 457 | return $rc |
| 458 | } |
| 459 | |
| 460 | # |
| 461 | # sapinstance_validate: Check the symantic of the input parameters |
| 462 | # |
| 463 | sapinstance_validate() { |
| 464 | rc=$OCF_SUCCESS |
| 465 | if [ `echo "$SID" | grep -c '^[A-Z][A-Z0-9][A-Z0-9]$'` -ne 1 ] |
| 466 | then |
| 467 | ocf_log err "Parsing instance profile name: '$SID' is not a valid system ID!" |
| 468 | rc=$OCF_ERR_ARGS |
| 469 | fi |
| 470 | |
| 471 | if [ `echo "$InstanceName" | grep -c '^[A-Z].*[0-9][0-9]$'` -ne 1 ] |
| 472 | then |
| 473 | ocf_log err "Parsing instance profile name: '$InstanceName' is not a valid instance name!" |
| 474 | rc=$OCF_ERR_ARGS |
| 475 | fi |
| 476 | |
| 477 | if [ `echo "$InstanceNr" | grep -c '^[0-9][0-9]$'` -ne 1 ] |
| 478 | then |
| 479 | ocf_log err "Parsing instance profile name: '$InstanceNr' is not a valid instance number!" |
| 480 | rc=$OCF_ERR_ARGS |
| 481 | fi |
| 482 | |
| 483 | if [ `echo "$SAPVIRHOST" | grep -c '^[A-Za-z][A-Za-z0-9_-]*$'` -ne 1 ] |
| 484 | then |
| 485 | ocf_log err "Parsing instance profile name: '$SAPVIRHOST' is not a valid hostname!" |
| 486 | rc=$OCF_ERR_ARGS |
| 487 | fi |
| 488 | |
| 489 | return $rc |
| 490 | } |
| 491 | |
| 492 | |
| 493 | # |
| 494 | # 'main' starts here... |
| 495 | # |
| 496 | |
| 497 | if |
| 498 | ( [ $# -ne 1 ] ) |
| 499 | then |
| 500 | usage |
| 501 | exit $OCF_ERR_ARGS |
| 502 | fi |
| 503 | |
| 504 | # These operations don't require OCF instance parameters to be set |
| 505 | case "$1" in |
| 506 | meta-data) meta_data |
| 507 | exit $OCF_SUCCESS;; |
| 508 | |
| 509 | usage) usage |
| 510 | exit $OCF_SUCCESS;; |
| 511 | |
| 512 | methods) sapinstance_methods |
| 513 | exit $?;; |
| 514 | |
| 515 | *);; |
| 516 | esac |
| 517 | |
| 518 | US=`id -u -n` |
| 519 | US=`echo $US` |
| 520 | if |
| 521 | [ $US != root ] |
| 522 | then |
| 523 | ocf_log err "$0 must be run as root" |
| 524 | exit $OCF_ERR_PERM |
| 525 | fi |
| 526 | |
| 527 | # parameter check |
| 528 | if [ -z "$OCF_RESKEY_InstanceName" ] |
| 529 | then |
| 530 | ocf_log err "Please set OCF_RESKEY_InstanceName to the name to the SAP instance profile!" |
| 531 | exit $OCF_ERR_ARGS |
| 532 | fi |
| 533 | |
| 534 | SID=`echo "$OCF_RESKEY_InstanceName" | cut -d_ -f1` |
| 535 | InstanceName=`echo "$OCF_RESKEY_InstanceName" | cut -d_ -f2` |
| 536 | InstanceNr=`echo "$InstanceName" | sed 's/.*\([0-9][0-9]\)$/\1/'` |
| 537 | SAPVIRHOST=`echo "$OCF_RESKEY_InstanceName" | cut -d_ -f3` |
| 538 | |
| 539 | # optional OCF parameters, we try to guess which directories are correct |
| 540 | if [ -z "$OCF_RESKEY_DIR_EXECUTABLE" ] |
| 541 | then |
| 542 | if [ -x /usr/sap/$SID/$InstanceName/exe/sapstartsrv -a -x /usr/sap/$SID/$InstanceName/exe/sapcontrol ] |
| 543 | then |
| 544 | DIR_EXECUTABLE="/usr/sap/$SID/$InstanceName/exe" |
| 545 | SAPSTARTSRV="/usr/sap/$SID/$InstanceName/exe/sapstartsrv" |
| 546 | SAPCONTROL="/usr/sap/$SID/$InstanceName/exe/sapcontrol" |
| 547 | elif [ -x /usr/sap/$SID/SYS/exe/run/sapstartsrv -a -x /usr/sap/$SID/SYS/exe/run/sapcontrol ] |
| 548 | then |
| 549 | DIR_EXECUTABLE="/usr/sap/$SID/SYS/exe/run" |
| 550 | SAPSTARTSRV="/usr/sap/$SID/SYS/exe/run/sapstartsrv" |
| 551 | SAPCONTROL="/usr/sap/$SID/SYS/exe/run/sapcontrol" |
| 552 | else |
| 553 | ocf_log warn "Cannot find sapstartsrv and sapcontrol executable, please set DIR_EXECUTABLE parameter!" |
| 554 | exit $OCF_NOT_RUNNING |
| 555 | fi |
| 556 | else |
| 557 | DIR_EXECUTABLE="$OCF_RESKEY_DIR_EXECUTABLE" |
| 558 | SAPSTARTSRV="$OCF_RESKEY_DIR_EXECUTABLE/sapstartsrv" |
| 559 | SAPCONTROL="$OCF_RESKEY_DIR_EXECUTABLE/sapcontrol" |
| 560 | fi |
| 561 | |
| 562 | if [ -z "$OCF_RESKEY_DIR_PROFILE" ] |
| 563 | then |
| 564 | if [ -d /usr/sap/$SID/SYS/profile/ ] |
| 565 | then |
| 566 | DIR_PROFILE="/usr/sap/$SID/SYS/profile" |
| 567 | else |
| 568 | ocf_log warn "Expected /usr/sap/$SID/SYS/profile/ to be a directory, please set DIR_PROFILE parameter!" |
| 569 | exit $OCF_NOT_RUNNING |
| 570 | fi |
| 571 | else |
| 572 | DIR_PROFILE="$OCF_RESKEY_DIR_PROFILE" |
| 573 | fi |
| 574 | |
| 575 | if [ -z "$OCF_RESKEY_START_PROFILE" ] |
| 576 | then |
| 577 | SAPSTARTPROFILE="$DIR_PROFILE/START_${InstanceName}_${SAPVIRHOST}" |
| 578 | if [ ! -r $SAPSTARTPROFILE ] |
| 579 | then |
| 580 | ocf_log warn "Expected $SAPSTARTPROFILE to be the instance START profile, please set START_PROFILE parameter!" |
| 581 | exit $OCF_NOT_RUNNING |
| 582 | fi |
| 583 | else |
| 584 | SAPSTARTPROFILE="$OCF_RESKEY_START_PROFILE" |
| 585 | fi |
| 586 | |
| 587 | if [ -z "$OCF_RESKEY_START_WAITTIME" ] |
| 588 | then |
| 589 | OCF_RESKEY_START_WAITTIME=3600 |
| 590 | fi |
| 591 | |
| 592 | |
| 593 | if [ -z "$OCF_RESKEY_AUTOMATIC_RECOVER" ] |
| 594 | then |
| 595 | OCF_RESKEY_AUTOMATIC_RECOVER=0 |
| 596 | else |
| 597 | case "$OCF_RESKEY_AUTOMATIC_RECOVER" in |
| 598 | 1|true|TRUE|yes|YES) OCF_RESKEY_AUTOMATIC_RECOVER=1;; |
| 599 | 0|false|FALSE|no|NO) OCF_RESKEY_AUTOMATIC_RECOVER=0;; |
| 600 | esac |
| 601 | fi |
| 602 | |
| 603 | # as root user we need the library path to the SAP kernel to be able to call sapcontrol |
| 604 | if [ `echo $LD_LIBRARY_PATH | grep -c "^$DIR_EXECUTABLE\>"` -eq 0 ]; then |
| 605 | LD_LIBRARY_PATH=$DIR_EXECUTABLE${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH |
| 606 | export LD_LIBRARY_PATH |
| 607 | fi |
| 608 | sidadm="`echo $SID | tr '[:upper:]' '[:lower:]'`adm" |
| 609 | |
| 610 | SAPSERVICES=/usr/sap/sapservices |
| 611 | |
| 612 | # What kind of method was invoked? |
| 613 | case "$1" in |
| 614 | |
| 615 | start) sapinstance_start |
| 616 | exit $?;; |
| 617 | |
| 618 | stop) sapinstance_stop |
| 619 | exit $?;; |
| 620 | |
| 621 | status|monitor) |
| 622 | sapinstance_monitor |
| 623 | exit $?;; |
| 624 | |
| 625 | validate-all) sapinstance_validate |
| 626 | exit $?;; |
| 627 | |
| 628 | *) sapinstance_methods |
| 629 | exit $OCF_ERR_UNIMPLEMENTED;; |
| 630 | esac |