Debian Codegraph @

rgmanager/src/resources/SAPDatabase

raw symbols SCIP
1 #!/bin/sh
2 #
3 # SAPDatabase
4 #
5 # Description: Manages any type of SAP supported database instance
6 # as a High-Availability OCF compliant resource.
7 #
8 # Author: Alexander Krauth, October 2006
9 # Support: [email protected]
10 # License: GNU General Public License (GPL)
11 # Copyright: (c) 2006, 2007 Alexander Krauth
12 #
13 # An example usage:
14 # See usage() function below for more details...
15 #
16 # OCF instance parameters:
17 # OCF_RESKEY_SID
18 # OCF_RESKEY_DIR_EXECUTABLE (optional, well known directories will be searched by default)
19 # OCF_RESKEY_DBTYPE
20 # OCF_RESKEY_NETSERVICENAME (optional, non standard name of Oracle Listener)
21 # OCF_RESKEY_DBJ2EE_ONLY (optional, default is false)
22 # OCF_RESKEY_JAVA_HOME (optional, only needed if DBJ2EE_ONLY is true and JAVA_HOME enviroment variable is not set)
23 # OCF_RESKEY_STRICT_MONITORING (optional, activate application level monitoring - with Oracle a failover will occur in case of an archiver stuck)
24 # OCF_RESKEY_AUTOMATIC_RECOVER (optional, automatic startup recovery, default is false)
25 # OCF_RESKEY_DIR_BOOTSTRAP (optional, if non standard J2EE server directory)
26 # OCF_RESKEY_DIR_SECSTORE (optional, if non standard J2EE secure store directory)
27 # OCF_RESKEY_DB_JARS (optional, if maintained in bootstrap.properties, mandatory for WebAS Java 7.10)
28 # OCF_RESKEY_PRE_START_USEREXIT (optional, lists a script which can be executed before the resource is started)
29 # OCF_RESKEY_POST_START_USEREXIT (optional, lists a script which can be executed after the resource is started)
30 # OCF_RESKEY_PRE_STOP_USEREXIT (optional, lists a script which can be executed before the resource is stopped)
31 # OCF_RESKEY_POST_STOP_USEREXIT (optional, lists a script which can be executed after the resource is stopped)
32 #
33 # ToDo:
34 # Remove all the database dependend stuff from the agent and use
35 # saphostcontrol daemon as soon as SAP will release it.
36 #
37 #######################################################################
38 # Initialization:
39
40 if [ -f $(dirname $0)/.ocf-shellfuncs ]; then
41 . $(dirname $0)/.ocf-shellfuncs
42 elif [ -f $(dirname $0)/ocf-shellfuncs ]; then
43 LC_ALL=C
44 LANG=C
45 PATH=/bin:/sbin:/usr/bin:/usr/sbin
46 export LC_ALL LANG PATH
47 . $(dirname $0)/ocf-shellfuncs
48 else
49 echo Could not find ocf-shellfuncs!
50 exit 1
51 fi
52
53 #######################################################################
54
55 SH=/bin/sh
56
57 usage() {
58 methods=`sapdatabase_methods`
59 methods=`echo $methods | tr ' ' '|'`
60 cat <<-!
61 usage: $0 ($methods)
62
63 $0 manages a SAP database of any type as an HA resource.
64 Currently Oracle, MaxDB and DB/2 UDB are supported.
65 ABAP databases as well as JAVA only databases are supported.
66
67 The 'start' operation starts the instance.
68 The 'stop' operation stops the instance.
69 The 'status' operation reports whether the instance is running
70 The 'monitor' operation reports whether the instance seems to be working
71 The 'recover' operation tries to recover the instance after a crash (instance will be stopped first!)
72 The 'validate-all' operation reports whether the parameters are valid
73 The 'methods' operation reports on the methods $0 supports
74
75 !
76 }
77
78 meta_data() {
79 cat <<END
80 <?xml version="1.0"?>
81 <!DOCTYPE resource-agent SYSTEM "ra-api-1-modified.dtd">
82 <resource-agent name="SAPDatabase">
83 <version>1.92.1</version>
84
85 <longdesc lang="en">
86 Resource script for SAP databases. It manages a SAP database of any type as an HA resource.
87 </longdesc>
88 <shortdesc lang="en">SAP database resource agent</shortdesc>
89
90 <parameters>
91 <parameter name="SID" unique="1" required="1" primary="1">
92 <longdesc lang="en">The unique SAP system identifier. e.g. P01</longdesc>
93 <shortdesc lang="en">SAP system ID</shortdesc>
94 <content type="string" default="" />
95 </parameter>
96 <parameter name="DIR_EXECUTABLE" unique="0" required="0">
97 <longdesc lang="en">The full qualified path where to find sapstartsrv and sapcontrol.</longdesc>
98 <shortdesc lang="en">path of sapstartsrv and sapcontrol</shortdesc>
99 <content type="string" default="" />
100 </parameter>
101 <parameter name="DBTYPE" unique="0" required="1">
102 <longdesc lang="en">The name of the database vendor you use. Set either: ORA,DB6,ADA</longdesc>
103 <shortdesc lang="en">database vendor</shortdesc>
104 <content type="string" default="" />
105 </parameter>
106 <parameter name="NETSERVICENAME" unique="0" required="0">
107 <longdesc lang="en">The Oracle TNS listener name.</longdesc>
108 <shortdesc lang="en">listener name</shortdesc>
109 <content type="string" default="" />
110 </parameter>
111 <parameter name="DBJ2EE_ONLY" unique="0" required="0">
112 <longdesc lang="en">If you do not have a ABAP stack installed in the SAP database, set this to TRUE</longdesc>
113 <shortdesc lang="en">only JAVA stack installed</shortdesc>
114 <content type="boolean" default="false"/>
115 </parameter>
116 <parameter name="JAVA_HOME" unique="0" required="0">
117 <longdesc lang="en">This is only needed if the DBJ2EE_ONLY parameter is set to true. Enter the path to the Java SDK which is used by the SAP WebAS Java</longdesc>
118 <shortdesc lang="en">Path to Java SDK</shortdesc>
119 <content type="string" default=""/>
120 </parameter>
121 <parameter name="STRICT_MONITORING" unique="0" required="0">
122 <longdesc lang="en">This controls how the resource agent monitors the database. If set to true, it will use SAP tools to test the connect to the database. Do not use with Oracle, because it will result in unwanted failovers in case of an archiver stuck</longdesc>
123 <shortdesc lang="en">Activates application level monitoring</shortdesc>
124 <content type="boolean" default="false"/>
125 </parameter>
126 <parameter name="AUTOMATIC_RECOVER" unique="0" required="0">
127 <longdesc lang="en">The SAPDatabase resource agent tries to recover a failed start attempt automatically one time. This is done by running a forced abort of the RDBMS and/or executing recovery commands.</longdesc>
128 <shortdesc lang="en">Enable or disable automatic startup recovery</shortdesc>
129 <content type="boolean" default="false"/>
130 </parameter>
131 <parameter name="DIR_BOOTSTRAP" unique="0" required="0">
132 <longdesc lang="en">The full qualified path where to find the J2EE instance bootstrap directory. e.g. /usr/sap/P01/J00/j2ee/cluster/bootstrap</longdesc>
133 <shortdesc lang="en">path to j2ee bootstrap directory</shortdesc>
134 <content type="string" default="" />
135 </parameter>
136 <parameter name="DIR_SECSTORE" unique="0" required="0">
137 <longdesc lang="en">The full qualified path where to find the J2EE security store directory. e.g. /usr/sap/P01/SYS/global/security/lib/tools</longdesc>
138 <shortdesc lang="en">path to j2ee secure store directory</shortdesc>
139 <content type="string" default="" />
140 </parameter>
141 <parameter name="DB_JARS" unique="0" required="0">
142 <longdesc lang="en">The full qualified filename of the jdbc driver for the database connection test. It will be automaticaly read from the bootstrap.properties file in Java engine 6.40 and 7.00. For Java engine 7.10 the parameter is mandatory.</longdesc>
143 <shortdesc lang="en">file name of the jdbc driver</shortdesc>
144 <content type="string" default="" />
145 </parameter>
146 <parameter name="PRE_START_USEREXIT" unique="0" required="0">
147 <longdesc lang="en">The full qualified path where to find a script or program which should be executed before this resource gets started.</longdesc>
148 <shortdesc lang="en">path to a pre-start script</shortdesc>
149 <content type="string" default="" />
150 </parameter>
151 <parameter name="POST_START_USEREXIT" unique="0" required="0">
152 <longdesc lang="en">The full qualified path where to find a script or program which should be executed after this resource got started.</longdesc>
153 <shortdesc lang="en">path to a post-start script</shortdesc>
154 <content type="string" default="" />
155 </parameter>
156 <parameter name="PRE_STOP_USEREXIT" unique="0" required="0">
157 <longdesc lang="en">The full qualified path where to find a script or program which should be executed before this resource gets stopped.</longdesc>
158 <shortdesc lang="en">path to a pre-start script</shortdesc>
159 <content type="string" default="" />
160 </parameter>
161 <parameter name="POST_STOP_USEREXIT" unique="0" required="0">
162 <longdesc lang="en">The full qualified path where to find a script or program which should be executed after this resource got stopped.</longdesc>
163 <shortdesc lang="en">path to a post-start script</shortdesc>
164 <content type="string" default="" />
165 </parameter>
166 </parameters>
167
168 <actions>
169 <action name="start" timeout="1800" />
170 <action name="stop" timeout="1800" />
171 <action name="status" depth="0" timeout="60" interval="120" start-delay="180" />
172 <action name="monitor" depth="0" timeout="60" interval="120" start-delay="180" />
173 <action name="validate-all" timeout="5" />
174 <action name="meta-data" timeout="5" />
175 <action name="methods" timeout="5" />
176 </actions>
177 </resource-agent>
178 END
179 }
180
181 trap_handler() {
182 rm -f $TEMPFILE
183 exit $OCF_ERR_GENERIC
184 }
185
186
187 do_exit() {
188 # If we've got a tempfile variable and the tempfile exists...
189 # ... if the return code is 0 *or* the temp file is empty
190 # remove it.
191 if [ -n "$TEMPFILE" ] && [ -e "$TEMPFILE" ]; then
192 if [ $1 -eq 0 ] || [ "$(stat -c %s $TEMPFILE)" = "0" ]; then
193 rm -f $TEMPFILE
194 fi
195 fi
196 exit $1
197 }
198
199
200 #
201 # listener_start: Start the given listener
202 #
203 listener_start() {
204 orasid="ora`echo $SID | tr '[:upper:]' '[:lower:]'`"
205 rc=$OCF_SUCCESS
206 output=`echo "lsnrctl start $NETSERVICENAME" | su - $orasid 2>&1`
207 if [ $? -eq 0 ]
208 then
209 ocf_log info "Oracle Listener $NETSERVICENAME started: $output"
210 rc=$OCF_SUCCESS
211 else
212 ocf_log err "Oracle Listener $NETSERVICENAME start failed: $output"
213 rc=$OCF_ERR_GENERIC
214 fi
215 return $rc
216 }
217
218 #
219 # listener_stop: Stop the given listener
220 #
221 listener_stop() {
222 orasid="ora`echo $SID | tr '[:upper:]' '[:lower:]'`"
223 rc=$OCF_SUCCESS
224 if
225 listener_status
226 then
227 : listener is running, trying to stop it later...
228 else
229 return $OCF_SUCCESS
230 fi
231 output=`echo "lsnrctl stop $NETSERVICENAME" | su - $orasid 2>&1`
232 if [ $? -eq 0 ]
233 then
234 ocf_log info "Oracle Listener $NETSERVICENAME stopped: $output"
235 else
236 ocf_log err "Oracle Listener $NETSERVICENAME stop failed: $output"
237 rc=$OCF_ERR_GENERIC
238 fi
239 return $rc
240 }
241
242 #
243 # listener_status: is the given listener running?
244 #
245 listener_status() {
246 orasid="ora`echo $SID | tr '[:upper:]' '[:lower:]'`"
247 # Note: ps cuts off it's output at column $COLUMNS, so "ps -ef" can not be used here
248 # as the output might be to long.
249 cnt=`ps efo args --user $orasid | grep $NETSERVICENAME | grep -c tnslsnr`
250 if [ $cnt -eq 1 ]
251 then
252 rc=$OCF_SUCCESS
253 else
254 ocf_log info "listener process not running for $NETSERVICENAME for $SID"
255 rc=$OCF_ERR_GENERIC
256 fi
257 return $rc
258 }
259
260 #
261 # x_server_start: Start the given x_server
262 #
263 x_server_start() {
264 rc=$OCF_SUCCESS
265 output=`echo "x_server start" | su - $sidadm 2>&1`
266 if [ $? -eq 0 ]
267 then
268 ocf_log info "MaxDB x_server start: $output"
269 rc=$OCF_SUCCESS
270 else
271 ocf_log err "MaxDB x_server start failed: $output"
272 rc=$OCF_ERR_GENERIC
273 fi
274 return $rc
275 }
276
277 #
278 # x_server_stop: Stop the x_server
279 #
280 x_server_stop() {
281 rc=$OCF_SUCCESS
282 output=`echo "x_server stop" | su - $sidadm 2>&1`
283 if [ $? -eq 0 ]
284 then
285 ocf_log info "MaxDB x_server stop: $output"
286 else
287 ocf_log err "MaxDB x_server stop failed: $output"
288 rc=$OCF_ERR_GENERIC
289 fi
290 return $rc
291 }
292
293 #
294 # x_server_status: is the x_server running?
295 #
296 x_server_status() {
297 sdbuser=`grep "^SdbOwner" /etc/opt/sdb | awk -F'=' '{print $2}'`
298 # Note: ps cuts off it's output at column $COLUMNS, so "ps -ef" can not be used here
299 # as the output might be to long.
300 cnt=`ps efo args --user $sdbuser | grep -c vserver`
301 if [ $cnt -ge 1 ]
302 then
303 rc=$OCF_SUCCESS
304 else
305 ocf_log info "x_server process not running"
306 rc=$OCF_ERR_GENERIC
307 fi
308 return $rc
309 }
310
311 #
312 # oracle_stop: Stop the Oracle database without any condition
313 #
314 oracle_stop() {
315 echo '#!/bin/sh
316 LOG=$HOME/stopdb.log
317 date > $LOG
318
319 if [ -x "${ORACLE_HOME}/bin/sqlplus" ]
320 then
321 SRVMGRDBA_EXE="${ORACLE_HOME}/bin/sqlplus"
322 else
323 echo "Can not find executable sqlplus" >> $LOG
324 exit 1
325 fi
326
327 $SRVMGRDBA_EXE /NOLOG >> $LOG << !
328 connect / as sysdba
329 shutdown immediate
330 exit
331 !
332 rc=$?
333 cat $LOG
334 exit $rc' > $TEMPFILE
335
336 chmod 700 $TEMPFILE
337 chown $sidadm $TEMPFILE
338
339 su - $sidadm -c $TEMPFILE
340 retcode=$?
341 rm -f $TEMPFILE
342
343 if [ $retcode -eq 0 ]; then
344 sapdatabase_status
345 if [ $? -ne $OCF_NOT_RUNNING ]; then
346 retcode=1
347 fi
348 fi
349
350 return $retcode
351 }
352
353 #
354 # maxdb_stop: Stop the MaxDB database without any condition
355 #
356 maxdb_stop() {
357
358 # x_Server must be running to stop database
359 x_server_status
360 if [ $? -ne $OCF_SUCCESS ]; then x_server_start; fi
361
362 if [ $DBJ2EE_ONLY -eq 1 ]; then
363 userkey=c_J2EE
364 else
365 userkey=c
366 fi
367
368 echo "#!/bin/sh
369 LOG=\$HOME/stopdb.log
370 date > \$LOG
371 echo \"Stop database with xuserkey >$userkey<\" >> \$LOG
372 dbmcli -U ${userkey} db_offline >> \$LOG 2>&1
373 exit \$?" > $TEMPFILE
374
375 chmod 700 $TEMPFILE
376 chown $sidadm $TEMPFILE
377
378 su - $sidadm -c $TEMPFILE
379 retcode=$?
380 rm -f $TEMPFILE
381
382 if [ $retcode -eq 0 ]; then
383 sapdatabase_status
384 if [ $? -ne $OCF_NOT_RUNNING ]; then
385 retcode=1
386 fi
387 fi
388
389 return $retcode
390 }
391
392 #
393 # db6udb_stop: Stop the DB2/UDB database without any condition
394 #
395 db6udb_stop() {
396 echo '#!/bin/sh
397 LOG=$HOME/stopdb.log
398 date > $LOG
399 echo "Shut down the database" >> $LOG
400 $INSTHOME/sqllib/bin/db2 deactivate database $DB2DBDFT |tee -a $LOG 2>&1
401 $INSTHOME/sqllib/adm/db2stop force |tee -a $LOG 2>&1
402 exit $?' > $TEMPFILE
403
404 chmod 700 $TEMPFILE
405 chown $sidadm $TEMPFILE
406
407 su - $sidadm -c $TEMPFILE
408 retcode=$?
409 rm -f $TEMPFILE
410
411 if [ $retcode -eq 0 ]; then
412 sapdatabase_status
413 if [ $? -ne $OCF_NOT_RUNNING ]; then
414 retcode=1
415 fi
416 fi
417
418 return $retcode
419 }
420
421 #
422 # oracle_recover: try to clean up oracle after a crash
423 #
424 oracle_recover() {
425 echo '#!/bin/sh
426 LOG=$HOME/recover.log
427 date > $LOG
428 echo "Logfile written by heartbeat SAPDatabase resource agent" >> $LOG
429
430 if [ -x "${ORACLE_HOME}/bin/sqlplus" ]
431 then
432 SRVMGRDBA_EXE="${ORACLE_HOME}/bin/sqlplus"
433 else
434 echo "Can not find executable sqlplus" >> $LOG
435 exit 1
436 fi
437
438 $SRVMGRDBA_EXE /NOLOG >> $LOG << !
439 connect / as sysdba
440 shutdown abort
441 startup mount
442 WHENEVER SQLERROR EXIT SQL.SQLCODE
443 WHENEVER OSERROR EXIT FAILURE
444 alter database recover automatic database;
445 alter database open;
446 exit
447 !
448 rc=$?
449 cat $LOG
450 exit $rc' > $TEMPFILE
451
452 chmod 700 $TEMPFILE
453 chown $sidadm $TEMPFILE
454
455 su - $sidadm -c $TEMPFILE
456 retcode=$?
457 rm -f $TEMPFILE
458
459 return $retcode
460 }
461
462 #
463 # maxdb_recover: try to clean up MaxDB after a crash
464 #
465 maxdb_recover() {
466 # x_Server must be running to stop database
467 x_server_status
468 if [ $? -ne $OCF_SUCCESS ]; then x_server_start; fi
469
470 if [ $DBJ2EE_ONLY -eq 1 ]; then
471 userkey=c_J2EE
472 else
473 userkey=c
474 fi
475
476 echo "#!/bin/sh
477 LOG=\$HOME/recover.log
478 date > \$LOG
479 echo \"Logfile written by heartbeat SAPDatabase resource agent\" >> \$LOG
480 echo \"Cleanup database with xuserkey >$userkey<\" >> \$LOG
481 echo \"db_stop\" >> \$LOG 2>&1
482 dbmcli -U ${userkey} db_stop >> \$LOG 2>&1
483 echo \"db_clear\" >> \$LOG 2>&1
484 dbmcli -U ${userkey} db_clear >> \$LOG 2>&1
485 echo \"db_online\" >> \$LOG 2>&1
486 dbmcli -U ${userkey} db_online >> \$LOG 2>&1
487 rc=\$?
488 cat \$LOG
489 exit \$rc" > $TEMPFILE
490
491 chmod 700 $TEMPFILE
492 chown $sidadm $TEMPFILE
493
494 su - $sidadm -c $TEMPFILE
495 retcode=$?
496 rm -f $TEMPFILE
497
498 return $retcode
499 }
500
501 #
502 # db6udb_recover: try to recover DB/2 after a crash
503 #
504 db6udb_recover() {
505 db2sid="db2`echo $SID | tr '[:upper:]' '[:lower:]'`"
506
507 echo '#!/bin/sh
508 LOG=$HOME/recover.log
509 date > $LOG
510 echo "Logfile written by heartbeat SAPDatabase resource agent" >> $LOG
511 $INSTHOME/sqllib/bin/db2_kill >> $LOG 2>&1
512 $INSTHOME/sqllib/adm/db2start >> $LOG 2>&1
513 $INSTHOME/sqllib/bin/db2 activate database $DB2DBDFT >> $LOG 2>&1
514 rc=$?
515 cat $LOG
516 exit $rc' > $TEMPFILE
517
518 chmod 700 $TEMPFILE
519 chown $db2sid $TEMPFILE
520
521 su - $db2sid -c $TEMPFILE
522 retcode=$?
523 rm -f $TEMPFILE
524
525 return $retcode
526 }
527
528 #
529 # methods: What methods/operations do we support?
530 #
531 sapdatabase_methods() {
532 cat <<-!
533 start
534 stop
535 status
536 monitor
537 recover
538 validate-all
539 methods
540 meta-data
541 usage
542 !
543 }
544
545
546 #
547 # sapuserexit : Many SAP customers need some additional processes/tools to run their SAP systems.
548 # This specialties do not allow a totally generic SAP cluster resource agent.
549 # Someone should write a resource agent for each additional process you need, if it
550 # is required to monitor that process within the cluster manager. To enable
551 # you to extent this resource agent without developing a new one, this user exit
552 # was introduced.
553 #
554 sapuserexit() {
555 NAME="$1"
556 VALUE="$2"
557
558 if [ -n "$VALUE" ]
559 then
560 if [ -x "$VALUE" ]
561 then
562 ocf_log info "Calling userexit ${NAME} with customer script file ${VALUE}"
563 eval "$VALUE" > /dev/null 2>&1
564 ocf_log info "Exiting userexit ${NAME} with customer script file ${VALUE}, returncode: $?"
565 else
566 ocf_log warn "Attribute ${NAME} is set to ${VALUE}, but this file is not executable"
567 fi
568 fi
569 return 0
570 }
571
572
573 #
574 # sapdatabase_start : Start the SAP database
575 #
576 sapdatabase_start() {
577 sapuserexit PRE_START_USEREXIT "$OCF_RESKEY_PRE_START_USEREXIT"
578
579 case $DBTYPE in
580 ADA) x_server_start
581 ;;
582 ORA) listener_start
583 ;;
584 esac
585
586 output=`su - $sidadm -c $SAPSTARTDB`
587 rc=$?
588
589 if [ $DBJ2EE_ONLY -eq 1 ]
590 then
591 sapdatabase_monitor 1
592 rc=$?
593 fi
594
595 if [ $rc -ne 0 -a $OCF_RESKEY_AUTOMATIC_RECOVER -eq 1 ]
596 then
597 ocf_log warn "SAP database $SID start failed: $output"
598 ocf_log warn "Try to recover database $SID"
599
600 output=''
601 sapdatabase_recover
602 rc=$?
603 fi
604
605 if [ $rc -eq 0 ]
606 then
607 ocf_log info "SAP database $SID started: $output"
608 rc=$OCF_SUCCESS
609 sapuserexit POST_START_USEREXIT "$OCF_RESKEY_POST_START_USEREXIT"
610 else
611 ocf_log err "SAP database $SID start failed: $output"
612 rc=$OCF_ERR_GENERIC
613 fi
614
615 return $rc
616 }
617
618 #
619 # sapdatabase_stop: Stop the SAP database
620 #
621 sapdatabase_stop() {
622
623 sapuserexit PRE_STOP_USEREXIT "$OCF_RESKEY_PRE_STOP_USEREXIT"
624
625 # use of the stopdb kernel script is not possible, because there are to may checks in that
626 # script. We want to stop the database regardless of anything.
627 #output=`su - $sidadm -c $SAPSTOPDB`
628
629 case $DBTYPE in
630 ORA) output=`oracle_stop`
631 ;;
632 ADA) output=`maxdb_stop`
633 ;;
634 DB6) output=`db6udb_stop`
635 ;;
636 esac
637
638 if [ $? -eq 0 ]
639 then
640 ocf_log info "SAP database $SID stopped: $output"
641 rc=$OCF_SUCCESS
642 else
643 ocf_log err "SAP database $SID stop failed: $output"
644 rc=$OCF_ERR_GENERIC
645 fi
646
647 case $DBTYPE in
648 ORA) listener_stop
649 ;;
650 ADA) x_server_stop
651 ;;
652 esac
653
654 sapuserexit POST_STOP_USEREXIT "$OCF_RESKEY_POST_STOP_USEREXIT"
655
656 return $rc
657 }
658
659
660 #
661 # sapdatabase_monitor: Can the given database instance do anything useful?
662 #
663 sapdatabase_monitor() {
664 strict=$1
665 rc=$OCF_SUCCESS
666
667 case $DBTYPE in
668 ADA) x_server_status
669 if [ $? -ne $OCF_SUCCESS ]; then x_server_start; fi
670 ;;
671 ORA) listener_status
672 if [ $? -ne $OCF_SUCCESS ]; then listener_start; fi
673 ;;
674 esac
675
676 if [ $strict -eq 0 ]
677 then
678 sapdatabase_status
679 rc=$?
680 else
681 if [ $DBJ2EE_ONLY -eq 0 ]
682 then
683 output=`echo "$SAPDBCONNECT -d -w /dev/null" | su $sidadm 2>&1`
684 if [ $? -le 4 ]
685 then
686 rc=$OCF_SUCCESS
687 else
688 rc=$OCF_NOT_RUNNING
689 fi
690 else
691 MYCP=""
692 EXECMD=""
693
694 # WebAS Java 6.40+7.00
695 IAIK_JCE="$SECSTORE"/iaik_jce.jar
696 IAIK_JCE_EXPORT="$SECSTORE"/iaik_jce_export.jar
697 EXCEPTION="$BOOTSTRAP"/exception.jar
698 LOGGING="$BOOTSTRAP"/logging.jar
699 OPENSQLSTA="$BOOTSTRAP"/opensqlsta.jar
700 TC_SEC_SECSTOREFS="$BOOTSTRAP"/tc_sec_secstorefs.jar
701 JDDI="$BOOTSTRAP"/../server0/bin/ext/jdbdictionary/jddi.jar
702 ANTLR="$BOOTSTRAP"/../server0/bin/ext/antlr/antlr.jar
703 FRAME="$BOOTSTRAP"/../server0/bin/system/frame.jar
704
705 # only start jdbcconnect when all jars available
706 if [ -f "$EXCEPTION" -a -f "$LOGGING" -a -f "$OPENSQLSTA" -a -f "$TC_SEC_SECSTOREFS" -a -f "$JDDI" -a -f "$ANTLR" -a -f "$FRAME" -a -f "$SAPDBCONNECT" ]
707 then
708 MYCP=".:$FRAME:$ANTLR:$JDDI:$IAIK_JCE_EXPORT:$IAIK_JCE:$EXCEPTION:$LOGGING:$OPENSQLSTA:$TC_SEC_SECSTOREFS:$DB_JARS:$SAPDBCONNECT"
709 EXECMD="com.sap.inst.jdbc.connect.JdbcCon -sec $SID:$SID"
710 else
711 # WebAS Java 7.10
712 LAUNCHER=${BOOTSTRAP}/sap.com~tc~bl~offline_launcher~impl.jar
713
714 if [ -f "$DB_JARS" -a -f "$SAPDBCONNECT" -a -f "$LAUNCHER" ]
715 then
716 MYCP="$LAUNCHER"
717 EXECMD="com.sap.engine.offline.OfflineToolStart com.sap.inst.jdbc.connect.JdbcCon ${SAPDBCONNECT}:${SECSTORE}:${DB_JARS}:${BOOTSTRAP} -sec $SID:$SID"
718 fi
719 fi
720
721 if [ -n "$EXECMD" ]
722 then
723 output=`eval ${JAVA_HOME}/bin/java -cp $MYCP $EXECMD`
724 if [ $? -le 0 ]
725 then
726 rc=$OCF_SUCCESS
727 else
728 rc=$OCF_NOT_RUNNING
729 fi
730 else
731 output="Cannot find all jar files needed for database monitoring."
732 rc=$OCF_ERR_GENERIC
733 fi
734 fi
735 fi
736
737 if [ $rc -ne $OCF_SUCCESS ]
738 then
739 ocf_log err "The SAP database $SID is not running: $output"
740 fi
741 return $rc
742 }
743
744
745 #
746 # sapdatabase_status: Are there any database processes on this host ?
747 #
748 sapdatabase_status() {
749 case $DBTYPE in
750 ADA) SEARCH="$SID/db/pgm/kernel"
751 SUSER=`grep "^SdbOwner" /etc/opt/sdb | awk -F'=' '{print $2}'`
752 SNUM=2
753 ;;
754 ORA) SEARCH="ora_[a-z][a-z][a-z][a-z]_"
755 SUSER="ora`echo $SID | tr '[:upper:]' '[:lower:]'`"
756 SNUM=4
757 ;;
758 DB6) SEARCH="db2[a-z][a-z][a-z][a-z][a-z]"
759 SUSER="db2`echo $SID | tr '[:upper:]' '[:lower:]'`"
760 SNUM=5
761 ;;
762 esac
763
764 # Note: ps cuts off it's output at column $COLUMNS, so "ps -ef" can not be used here
765 # as the output might be to long.
766 cnt=`ps efo args --user $SUSER 2> /dev/null | grep -c "$SEARCH"`
767 if [ $cnt -ge $SNUM ]
768 then
769 rc=$OCF_SUCCESS
770 else
771 # ocf_log info "Database Instance $SID is not running on `hostname`"
772 rc=$OCF_NOT_RUNNING
773 fi
774 return $rc
775 }
776
777
778 #
779 # sapdatabase_recover:
780 #
781 sapdatabase_recover() {
782
783 case $DBTYPE in
784 ORA) recoutput=`oracle_recover`
785 ;;
786 ADA) recoutput=`maxdb_recover`
787 ;;
788 DB6) recoutput=`db6udb_recover`
789 ;;
790 esac
791
792 sapdatabase_monitor 1
793 retcode=$?
794
795 if [ $retcode -eq $OCF_SUCCESS ]
796 then
797 ocf_log info "Recover of SAP database $SID was successful: $recoutput"
798 else
799 ocf_log err "Recover of SAP database $SID failed: $recoutput"
800 fi
801
802 return $retcode
803 }
804
805
806 #
807 # sapdatabase_validate: Check the symantic of the input parameters
808 #
809 sapdatabase_validate() {
810 rc=$OCF_SUCCESS
811 if [ `echo "$SID" | grep -c '^[A-Z][A-Z0-9][A-Z0-9]$'` -ne 1 ]
812 then
813 ocf_log err "Parsing parameter SID: '$SID' is not a valid system ID!"
814 rc=$OCF_ERR_ARGS
815 fi
816
817 case "$DBTYPE" in
818 ORA|ADA|DB6) ;;
819 *) ocf_log err "Parsing parameter DBTYPE: '$DBTYPE' is not a supported database type!"
820 rc=$OCF_ERR_ARGS ;;
821 esac
822
823 return $rc
824 }
825
826
827 #
828 # 'main' starts here...
829 #
830
831 if
832 ( [ $# -ne 1 ] )
833 then
834 usage
835 exit $OCF_ERR_ARGS
836 fi
837
838 # These operations don't require OCF instance parameters to be set
839 case "$1" in
840 meta-data) meta_data
841 exit $OCF_SUCCESS;;
842
843 usage) usage
844 exit $OCF_SUCCESS;;
845
846 methods) sapdatabase_methods
847 exit $?;;
848
849 *);;
850 esac
851
852 # Set a tempfile and make sure to clean it up again
853 TEMPFILE="$(mktemp /tmp/SAPDatabase.tmp.XXXXXX)"
854 trap trap_handler INT TERM
855
856 # Everything after here must call do_exit to remove temp file
857
858
859 US=`id -u -n`
860 US=`echo $US`
861 if
862 [ $US != root ]
863 then
864 ocf_log err "$0 must be run as root"
865 do_exit $OCF_ERR_PERM
866 fi
867
868 # mandatory parameter check
869 if [ -z "$OCF_RESKEY_SID" ]; then
870 ocf_log err "Please set OCF_RESKEY_SID to the SAP system id!"
871 do_exit $OCF_ERR_ARGS
872 fi
873 SID=`echo "$OCF_RESKEY_SID"`
874
875 if [ -z "$OCF_RESKEY_DBTYPE" ]; then
876 ocf_log err "Please set OCF_RESKEY_DBTYPE to the database vendor specific tag (ORA,ADA,DB6)!"
877 do_exit $OCF_ERR_ARGS
878 fi
879 DBTYPE=`echo "$OCF_RESKEY_DBTYPE" | tr '[a-z]' '[A-Z]'`
880
881 # optional OCF parameters, we try to guess which directories are correct
882 EXESTARTDB="startdb"
883 EXESTOPDB="stopdb"
884 EXEDBCONNECT="R3trans"
885 if [ -z "$OCF_RESKEY_DBJ2EE_ONLY" ]; then
886 DBJ2EE_ONLY=0
887 else
888 case "$OCF_RESKEY_DBJ2EE_ONLY" in
889 1|true|TRUE|yes|YES) DBJ2EE_ONLY=1
890 EXESTARTDB="startj2eedb"
891 EXESTOPDB="stopj2eedb"
892 EXEDBCONNECT="jdbcconnect.jar"
893 ;;
894 0|false|FALSE|no|NO) DBJ2EE_ONLY=0;;
895 *) ocf_log err "Parsing parameter DBJ2EE_ONLY: '$DBJ2EE_ONLY' is not a boolean value!"
896 do_exit $OCF_ERR_ARGS ;;
897 esac
898 fi
899
900 if [ -z "$OCF_RESKEY_NETSERVICENAME" ]; then
901 case "$DBTYPE" in
902 ORA|ora) NETSERVICENAME="LISTENER";;
903 *) NETSERVICENAME="";;
904 esac
905 else
906 NETSERVICENAME="$OCF_RESKEY_NETSERVICENAME"
907 fi
908
909 if [ -z "$OCF_RESKEY_STRICT_MONITORING" ]; then
910 OCF_RESKEY_STRICT_MONITORING=0
911 else
912 case "$OCF_RESKEY_STRICT_MONITORING" in
913 1|true|TRUE|yes|YES) OCF_RESKEY_STRICT_MONITORING=1;;
914 0|false|FALSE|no|NO) OCF_RESKEY_STRICT_MONITORING=0;;
915 *) ocf_log err "Parsing parameter STRICT_MONITORING: '$OCF_RESKEY_STRICT_MONITORING' is not a boolean value!"
916 do_exit $OCF_ERR_ARGS ;;
917 esac
918 fi
919
920 PATHLIST="
921 $OCF_RESKEY_DIR_EXECUTABLE
922 /usr/sap/$SID/*/exe
923 /usr/sap/$SID/SYS/exe/run
924 /sapmnt/$SID/exe
925 "
926 DIR_EXECUTABLE=""
927 for EXEPATH in $PATHLIST
928 do
929 if [ -x $EXEPATH/$EXESTARTDB -a -x $EXEPATH/$EXESTOPDB -a -x $EXEPATH/$EXEDBCONNECT ]
930 then
931 DIR_EXECUTABLE=$EXEPATH
932 SAPSTARTDB=$EXEPATH/$EXESTARTDB
933 SAPSTOPDB=$EXEPATH/$EXESTOPDB
934 SAPDBCONNECT=$EXEPATH/$EXEDBCONNECT
935 break
936 fi
937 done
938 if [ -z "$DIR_EXECUTABLE" ]
939 then
940 ocf_log warn "Cannot find $EXESTARTDB,$EXESTOPDB and $EXEDBCONNECT executable, please set DIR_EXECUTABLE parameter!"
941 do_exit $OCF_NOT_RUNNING
942 fi
943
944 if [ $DBJ2EE_ONLY -eq 1 ]
945 then
946 if [ -n "$OCF_RESKEY_DIR_BOOTSTRAP" ]
947 then
948 BOOTSTRAP="$OCF_RESKEY_DIR_BOOTSTRAP"
949 else
950 BOOTSTRAP=`echo /usr/sap/$SID/*/j2ee/cluster/bootstrap | head -1`
951 fi
952
953 if [ -n "$OCF_RESKEY_DIR_SECSTORE" ]
954 then
955 SECSTORE="$OCF_RESKEY_DIR_SECSTORE"
956 else
957 SECSTORE=/usr/sap/$SID/SYS/global/security/lib/tools
958 fi
959
960 if [ -n "$OCF_RESKEY_JAVA_HOME" ]
961 then
962 JAVA_HOME="$OCF_RESKEY_JAVA_HOME"
963 PATH=$JAVA_HOME/bin:$PATH
964 else
965 if [ -n "$JAVA_HOME" ]
966 then
967 PATH=$JAVA_HOME/bin:$PATH
968 else
969 ocf_log err "Cannot find JAVA_HOME directory, please set JAVA_HOME parameter!"
970 do_exit $OCF_NOT_RUNNING
971 fi
972 fi
973
974 if [ -n "$OCF_RESKEY_DB_JARS" ]
975 then
976 DB_JARS=$OCF_RESKEY_DB_JARS
977 else
978 if [ -f "$BOOTSTRAP"/bootstrap.properties ]; then
979 DB_JARS=`cat $BOOTSTRAP/bootstrap.properties | grep -i rdbms.driverLocation | sed -e 's/\\\:/:/g' | awk -F= '{print $2}'`
980 fi
981 fi
982 fi
983
984 if [ -z "$OCF_RESKEY_AUTOMATIC_RECOVER" ]
985 then
986 OCF_RESKEY_AUTOMATIC_RECOVER=0
987 else
988 case "$OCF_RESKEY_AUTOMATIC_RECOVER" in
989 1|true|TRUE|yes|YES) OCF_RESKEY_AUTOMATIC_RECOVER=1;;
990 0|false|FALSE|no|NO) OCF_RESKEY_AUTOMATIC_RECOVER=0;;
991 esac
992 fi
993
994 # as root user we need the library path to the SAP kernel to be able to call executables
995 if [ `echo $LD_LIBRARY_PATH | grep -c "^$DIR_EXECUTABLE\>"` -eq 0 ]; then
996 LD_LIBRARY_PATH=$DIR_EXECUTABLE${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH
997 export LD_LIBRARY_PATH
998 fi
999 sidadm="`echo $SID | tr '[:upper:]' '[:lower:]'`adm"
1000
1001 # What kind of method was invoked?
1002 case "$1" in
1003
1004 start) sapdatabase_start
1005 do_exit $?;;
1006
1007 stop) sapdatabase_stop
1008 do_exit $?;;
1009
1010 monitor)
1011 sapdatabase_monitor $OCF_RESKEY_STRICT_MONITORING
1012 do_exit $?;;
1013
1014 status)
1015 sapdatabase_status
1016 do_exit $?;;
1017
1018 recover) sapdatabase_recover
1019 do_exit $?;;
1020
1021 validate-all) sapdatabase_validate
1022 do_exit $?;;
1023
1024 *) sapdatabase_methods
1025 do_exit $OCF_ERR_UNIMPLEMENTED;;
1026 esac