8 # OCF resource agent that manages an
9 # IBM Informix Dynamic Server (IDS) instance
10 # as an High-Availability resource.
13 # Author: Lars D. Forseth, <lars.forseth@de.ibm.com> or <lars@forseth.de>
14 # Created: May 25th 2007
15 # Last Modified: July 30th 2007
16 # Support: linux-ha@lists.linux-ha.org
17 # License: GNU General Public License (GPL), Version 2 or later
18 # Copyright: (c) 2002 - 2007 International Business Machines, Inc.
20 # This code is inspired by the db2 OCF resource agent
21 # written by Alan Robertson, <alanr@unix.sh>
24 # This program is free software; you can redistribute it and/or modify
25 # it under the terms of the GNU General Public License as published by
26 # the Free Software Foundation; either version 2 of the License, or
27 # (at your option) any later version.
30 # This program is distributed in the hope that it would be useful, but
31 # WITHOUT ANY WARRANTY; without even the implied warranty of
32 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
34 # Further, this software is distributed without any warranty that it is
35 # free of the rightful claim of any third person regarding infringement
36 # or the like. Any license provided herein, whether implied or
37 # otherwise, applies only to this software file. Patent licenses, if
38 # any, provided herein do not apply to combinations of this program with
39 # other software, or any other product whatsoever.
41 # You should have received a copy of the GNU General Public License
42 # along with this program; if not, write the Free Software Foundation,
43 # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
46 # Example usage as it would appear in /etc/ha.d/haresources:
47 # node1 192.168.0.1 ids::/informix::ids1::onconfig.ids1
50 # --> Note that passing dbname and sqltestquery in heartbeat version 1 style is not supported!
52 # See usage() function below for more details...
55 # OCF instance parameters:
56 # OCF_RESKEY_informixdir
57 # OCF_RESKEY_informixserver
60 # OCF_RESKEY_sqltestquery
65 # Include general OCF functions and variables (such as OCF return codes).
67 . ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs
71 # Function that displays the usage of this script.
75 methods=`echo $methods | tr ' ' '|'`
80 $0 manages an IBM Informix Dynamic Server (IDS) instance as an High-Availability resource.
82 The 'start' operation starts the database.
83 The 'stop' operation stops the database.
84 The 'status' operation reports whether the database is running
85 The 'monitor' operation reports whether the database seems to be working
86 The 'validate-all' operation reports whether the parameters are valid
87 The 'methods' operation lists the methods $0 supports
88 The 'usage' operation displays this text
89 The 'meta-data' operation returns the meta-data (in XML) of this resource script
95 # Function that displays the possible methods this script supports.
112 # Function that displays the meta-data of this OCF resource agent.
116 <?xml version="1.0"?>
117 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
118 <resource-agent name="ids">
119 <version>1.0</version>
123 OCF resource agent to manage an IBM Informix Dynamic Server (IDS) instance as an High-Availability resource.
125 <shortdesc lang="en">OCF resource agent for the IBM's database server called Informix Dynamic Server (IDS)</shortdesc>
130 <parameter name="informixdir" required="0">
132 The value the environment variable INFORMIXDIR has after a typical installation of IDS.
133 Or in other words: the path (without trailing '/') where IDS was installed to.
134 If this parameter is unspecified the script will try to get the value from the shell environment.
136 <shortdesc lang="en">
137 INFORMIXDIR environment variable
139 <content type="string" default="" />
142 <parameter name="informixserver" required="0">
144 The value the environment variable INFORMIXSERVER has after a typical installation of IDS.
145 Or in other words: the name of the IDS server instance to manage.
146 If this parameter is unspecified the script will try to get the value from the shell environment.
148 <shortdesc lang="en">
149 INFORMIXSERVER environment variable
151 <content type="string" default="" />
154 <parameter name="onconfig" required="0">
156 The value the environment variable ONCONFIG has after a typical installation of IDS.
157 Or in other words: the name of the configuration file for the IDS instance specified in INFORMIXSERVER.
158 The specified configuration file will be searched at '$INFORMIXDIR/etc/$ONCONFIG'.
159 If this parameter is unspecified the script will try to get the value from the shell environment.
161 <shortdesc lang="en">
162 ONCONFIG environment variable
164 <content type="string" default="" />
167 <parameter name="dbname" required="0">
169 This parameter defines which database to use in order to monitor the IDS instance.
170 If this parameter is unspecified the script will use the 'sysmaster' database as a default.
172 <shortdesc lang="en">
173 database to use for monitoring, defaults to 'sysmaster'
175 <content type="string" default="sysmaster" />
178 <parameter name="sqltestquery" required="0">
180 SQL test query to run on the database specified by the parameter 'dbname'
181 in order to monitor the IDS instance and determine if it's functional or not.
182 If this parameter is unspecified the script will use 'SELECT COUNT(*) FROM systables;' as a default.
184 <shortdesc lang="en">
185 SQL test query to use for monitoring, defaults to 'SELECT COUNT(*) FROM systables;'
187 <content type="string" default="SELECT COUNT(*) FROM systables;" />
194 <action name="start" timeout="120" />
195 <action name="stop" timeout="120" />
196 <action name="status" timeout="60" />
197 <action name="monitor" depth="0" timeout="30" interval="10" start-delay="10" />
198 <action name="validate-all" timeout="5" />
199 <action name="meta-data" timeout="5" />
200 <action name="methods" timeout="5" />
201 <action name="usage" timeout="5" />
211 # Function that either forwards log messages to the ocf_log function
212 # provided by heartbeat or simply prints them to standard out via echo.
213 # This is determined by setting the variable "idslogger" to "echo" or "ocf".
214 # The default for "idslogger" is "ocf".
218 # Where should the passed log messages be passed to,
219 # to the standard output via the echo command ("echo")
220 # or to the ocf_log function provided by heartbeat ("ocf") ?
224 # When the variable "idsdebug" is not set to "true"
225 # this function (ids_log) will not print any info message
226 # that has been forwarded to it!
227 # This is done in order to spare if-statements within the
228 # other functions in this script and to centralize the decision
229 # whether to have a chatty resource script or not... ;)
230 # Nevertheless, error messages will always be printed!
233 # Only continue if the two expected parameters
234 # are not empty and "idsdebug" is set to "true"
235 # or the message is of type "error".
236 if [ $# -eq 2 -a -n "$1" -a -n "$2" ]; then
237 if [ "$idsdebug" = "true" -o "$1" = "error" ]; then
239 # Print messages to stdout via echo command.
241 echo "`date +'%b %d %H:%M:%S'`: [$1] $2";;
242 # Pass messages to ocf_log function.
252 # Function that prints the current values of important environment variables
253 # needed by the script and the IDS instance itself. The just mentioned variables are:
261 ids_log info "called ids_debug"
263 ids_log info "INFORMIXDIR=$INFORMIXDIR"
264 ids_log info "OCF_RESKEY_informixdir=$OCF_RESKEY_informixdir"
266 ids_log info "INFORMIXSERVER=$INFORMIXSERVER"
267 ids_log info "OCF_RESKEY_informixserver=$OCF_RESKEY_informixserver"
269 ids_log info "ONCONFIG=$ONCONFIG"
270 ids_log info "OCF_RESKEY_onconfig=$OCF_RESKEY_onconfig"
272 ids_log info "PATH=$PATH"
273 ids_log info "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
275 ids_log info "dbname=$OCF_RESKEY_dbname"
276 ids_log info "sqltestquery=$OCF_RESKEY_sqltestquery"
278 ids_log info "this script is run as user: `id`"
279 ids_log info "...in the current working directory: `pwd`"
284 # Function that validates if the passed parameters are valid and sets them if valid.
285 # If the first three parameters have not been passed,
286 # this function checks whether they have been already set in the parent's shell environment.
287 # The variables that are checked and set (only the capitalized ones are set) are:
298 ids_log info "called ids_validate"
301 # Check if INFORMIX, INFORMIXSERVER and ONCONFIG
302 # have been passed or set and validate them.
304 # OCF vars not passed, vars empty - set and export them to the shell environment.
305 if [ -n "$OCF_RESKEY_informixdir" -a -n "$OCF_RESKEY_informixserver" -a -n "$OCF_RESKEY_onconfig" ]; then
306 ids_log info "ids_validate: passed vars not empty"
308 INFORMIXDIR=$OCF_RESKEY_informixdir
311 INFORMIXSERVER=$OCF_RESKEY_informixserver
312 export INFORMIXSERVER
314 ONCONFIG=$OCF_RESKEY_onconfig
318 # Check if INFORMIXDIR is non-empty and a directory (and if there was an error so far).
319 if [ $rc -eq $OCF_SUCCESS -a -n "$INFORMIXDIR" -a -d "$INFORMIXDIR" ]; then
320 ids_log info "ids_validate: INFORMIXDIR is valid: $INFORMIXDIR"
323 ids_log error "ids_validate: INFORMIXDIR is invalid: $INFORMIXDIR"
327 # Check if INFORMIXSERVER is non-empty (and if there was an error so far).
328 if [ $rc -eq $OCF_SUCCESS -a -n "$INFORMIXSERVER" ]; then
329 ids_log info "ids_validate: INFORMIXSERVER is valid: $INFORMIXSERVER"
332 ids_log error "ids_validate: INFORMIXSERVER is invalid: $INFORMIXSERVER"
336 # Check if ONCONFIG is non-empty and a non-empty file (and if there was an error so far).
337 if [ $rc -eq $OCF_SUCCESS -a -n "$ONCONFIG" -a -s "$INFORMIXDIR/etc/$ONCONFIG" ]; then
338 ids_log info "ids_validate: ONCONFIG is a non-empty file in: \$INFORMIXDIR/etc/\$ONCONFIG where ONCONFIG=$ONCONFIG"
341 if [ -z "$ONCONFIG" -a -s "$INFORMIXDIR/etc/onconfig" ]; then
344 ids_log info "ids_validate: ONCONFIG is a non-empty file in: \$INFORMIXDIR/etc/\$ONCONFIG where ONCONFIG=$ONCONFIG"
347 if [ -z "$ONCONFIG" -a -s "$INFORMIXDIR/etc/onconfig.std" ]; then
348 ONCONFIG="onconfig.std"
350 ids_log info "ids_validate: ONCONFIG is a non-empty file in: \$INFORMIXDIR/etc/\$ONCONFIG where ONCONFIG=$ONCONFIG"
353 ids_log error "ids_validate: ONCONFIG is invalid, searched for it in: \$INFORMIXDIR/etc/\$ONCONFIG where ONCONFIG=$ONCONFIG"
359 # Check if the commands oninit, onstat, onmode and dbaccess exist in INFORMIXDIR/bin/
360 # and whether they are executable (do this only if there wasn't an error so far).
361 if [ $rc -eq $OCF_SUCCESS -a -x "$INFORMIXDIR/bin/oninit" -a -x "$INFORMIXDIR/bin/onstat" -a -x "$INFORMIXDIR/bin/onmode" -a -x "$INFORMIXDIR/bin/dbaccess" ]; then
362 ids_log info "ids_validate: oninit, onstat and dbaccess exist and are executable in: \$INFORMIXDIR/bin/"
365 ids_log error "ids_validate: oninit, onstat or dbacces don't exist or they are not executable in: \$INFORMIXDIR/bin/"
369 # Extend PATH and LD_LIBRARY_PATH as needed for the IDS instance to run properly
370 # BUT: only do this if it hasn't been done before! Otherwise PATH and LD_LIBRARY_PATH will
371 # keep on growing every time heartbeat calls the IDS resource agent script! ;)
372 echo $PATH | grep $INFORMIXDIR > /dev/null 2>&1
375 if [ $rc -eq $OCF_SUCCESS -a $inpath -ne 0 ]; then
376 PATH="${INFORMIXDIR}/bin":${PATH}
378 ids_log info "ids_validate: PATH did not contain INFORMIXDIR, added \$INFORMIXDIR/bin"
380 ids_log info "ids_validate: INFORMIXDIR already in PATH, where PATH=$PATH"
383 echo $LD_LIBRARY_PATH | grep $INFORMIXDIR > /dev/null 2>&1
386 if [ $rc -eq $OCF_SUCCESS -a $inldlibpath -ne 0 ]; then
387 LD_LIBRARY_PATH="${INFORMIXDIR}/lib:${INFORMIXDIR}/lib/esql"
388 export LD_LIBRARY_PATH
389 ids_log info "ids_validate: LD_LIBRARY_PATH did not contain INFORMIXDIR, added \$INFORMIXDIR/lib and \$INFORMIXDIR/lib/esql, added them"
391 ids_log info "ids_validate: INFORMIXDIR already in LD_LIBRARY_PATH, where LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
394 # Check if dbname is empty (and if there was an error so far)
395 # if it is empty, assign default.
396 if [ $rc -eq $OCF_SUCCESS -a -n "$OCF_RESKEY_dbname" ]; then
397 ids_log info "ids_validate: dbname is valid: $OCF_RESKEY_dbname"
400 ids_log info "ids_validate: dbname is invalid: $OCF_RESKEY_dbname"
401 ids_log info "ids_validate: using 'sysmaster' as default..."
402 OCF_RESKEY_dbname="sysmaster"
403 export OCF_RESKEY_dbname
407 # Check if sqltestquery is empty (and if there was an error so far)
408 # if it is empty, assign default.
409 if [ $rc -eq $OCF_SUCCESS -a -n "$OCF_RESKEY_sqltestquery" ]; then
410 ids_log info "ids_validate: sqltestquery is valid: $OCF_RESKEY_sqltestquery"
413 ids_log info "ids_validate: sqltestquery is invalid: $OCF_RESKEY_sqltestquery"
414 ids_log info "ids_validate: using 'SELECT COUNT(*) FROM systables;' as default..."
415 OCF_RESKEY_sqltestquery="SELECT COUNT(*) FROM systables;"
416 export OCF_RESKEY_sqltestquery
420 # Return exit status code.
426 # Function that start the IDS instance and reports any error that
427 # may occur while starting.
431 ids_log info "called ids_start"
433 # Get current status of IDS instance.
439 # IDS instance already running - exit with success.
441 ids_log info "ids_start: IDS instance already running: $stat"
444 # IDS instance in undefined state - exit with error.
446 ids_log error "ids_start: IDS instance in undefined state: $stat"
448 rc=$OCF_ERR_GENERIC;;
450 # IDS instance not running - try to start it.
452 ids_log info "ids_start: executing 'oninit' now..."
455 ids_log info "ids_start: done executing 'oninit': $stat"
457 # The oninit command terminated successfully - check new state of IDS instance.
458 if [ $stat -eq 0 ]; then
459 # Initialize stat with failure exit status code.
460 stat=$OCF_ERR_GENERIC
461 # Endless loop that waits until IDS is completely online.
462 # If IDS takes too long to achieve this or even hangs,
463 # the timeout settings of heartbeat will cancel the starting
464 # of the IDS resource and therefore terminate the loop.
465 while [ $stat -ne $OCF_SUCCESS ]; do
469 # IDS is running now - success.
470 ids_log info "ids_start: IDS instance successfully started: $stat"
472 # The oninit command terminated with an error - starting the IDS resource failed!
474 ids_log error "ids_start: starting IDS instance failed: $stat"
480 # Unexpected state - return OCF_ERR_UNIMPLEMENTED error.
482 ids_log error "ids_start: unexpected state returned from ids_status: $stat"
484 rc=$OCF_ERR_UNIMPLEMENTED;;
488 # Return exit status code.
494 # Function that stops the IDS instance and reports any error that
495 # may occur while stopping.
499 ids_log info "caled ids_stop"
506 # IDS instance is not running - success stopping it.
508 ids_log info "ids_stop: IDS instance is not running: $stat"
511 # IDS instance is in an undefined state - exit with error.
513 ids_log error "ids_stop: IDS instance in undefined state: $stat"
515 rc=$OCF_ERR_GENERIC;;
517 # IDS instance is running - try to stop it.
519 ids_log info "ids_stop: running 'onmode -kuy' now..."
522 ids_log info "ids_stop: done running 'onmode -kuy' now: $stat"
524 # The onmode command terminated successfully - check new state of the IDS instance.
525 if [ $stat -eq 0 ]; then
528 # New state is: not running - success.
529 if [ $stat -eq $OCF_NOT_RUNNING ]; then
530 ids_log info "ids_stop: IDS instance successfully stopped: $stat"
532 # New state is: running or even undefined - failure!
534 ids_log error "ids_stop: stopping IDS instance failed: $stat"
539 # The onmode command terminated with an error - stopping the IDS resource failed!
541 ids_log error "ids_stop: stopping IDS instance (by executing 'onmode -kuy') failed: $stat"
547 # Unexpected state - return OCF_ERR_UNIMPLEMENTED error.
549 ids_log error "ids_stop: unexpected state returned from ids_status: $stat"
551 rc=$OCF_ERR_UNIMPLEMENTED;;
555 # Return exit status code indicating whether IDS was successfully stopped or not.
561 # Function that determines the current status/state of the IDS instance,
562 # meaning whether it is running (the case when output of "onstat -" contains "On-Line"),
563 # not running (the case when output of "onstat -" contains "shared memory not initialized")
564 # or in an undefined state (the case output of "onstat -" contains "Quiescent", "Single-User", or other).
565 # If the IDS instance is declared running the exit status code will indicate succes, otherwise failure of course.
569 ids_log info "called ids_status"
571 # Get current status from the onstat tool and store it.
576 # IDS instance is running.
578 ids_log info "ids_status: IDS instance running: $stat"
581 # IDS instance is not running.
582 *"shared memory not initialized"*)
583 ids_log info "ids_status: IDS instance not running: $stat"