# Function that either forwards log messages to the ocf_log function
# provided by heartbeat or simply prints them to standard out via echo.
# This is determined by setting the variable "idslogger" to "echo" or "ocf".
# The default for "idslogger" is "ocf".
#
ids_log() {
# Where should the passed log messages be passed to,
# to the standard output via the echo command ("echo")
# or to the ocf_log function provided by heartbeat ("ocf") ?
# Default is "ocf".
idslogger="ocf"
# When the variable "idsdebug" is not set to "true"
# this function (ids_log) will not print any info message
# that has been forwarded to it!
# This is done in order to spare if-statements within the
# other functions in this script and to centralize the decision
# whether to have a chatty resource script or not... ;)
# Nevertheless, error messages will always be printed!
idsdebug=false
# Only continue if the two expected parameters
# are not empty and "idsdebug" is set to "true"
# or the message is of type "error".
if [ $# -eq 2 -a -n "$1" -a -n "$2" ]; then
if [ "$idsdebug" = "true" -o "$1" = "error" ]; then
case $idslogger in
# Print messages to stdout via echo command.
echo)
echo "`date +'%b %d %H:%M:%S'`: [$1] $2";;
# Pass messages to ocf_log function.
ocf|*)
ocf_log "$1" "$2";;
esac
fi
fi
}
#
# Function that prints the current values of important environment variables
# needed by the script and the IDS instance itself. The just mentioned variables are:
# - INFORMIXDIR
# - INFORMIXSERVER
# - ONCONFIG
# - PATH
# - LD_LIBRARY_PATH
#
ids_debug() {
ids_log info "called ids_debug"
ids_log info "INFORMIXDIR=$INFORMIXDIR"
ids_log info "OCF_RESKEY_informixdir=$OCF_RESKEY_informixdir"
ids_log info "INFORMIXSERVER=$INFORMIXSERVER"
ids_log info "OCF_RESKEY_informixserver=$OCF_RESKEY_informixserver"
ids_log info "ONCONFIG=$ONCONFIG"
ids_log info "OCF_RESKEY_onconfig=$OCF_RESKEY_onconfig"
ids_log info "PATH=$PATH"
ids_log info "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
ids_log info "dbname=$OCF_RESKEY_dbname"
ids_log info "sqltestquery=$OCF_RESKEY_sqltestquery"
ids_log info "this script is run as user: `id`"
ids_log info "...in the current working directory: `pwd`"
}
#
# Function that validates if the passed parameters are valid and sets them if valid.
# If the first three parameters have not been passed,
# this function checks whether they have been already set in the parent's shell environment.
# The variables that are checked and set (only the capitalized ones are set) are:
# - INFORMIXDIR
# - INFORMIXSERVER
# - ONCONFIG
# - PATH
# - LD_LIBRARY_PATH
# - dbname
# - sqltestquery
#
ids_validate() {
ids_log info "called ids_validate"
rc=$OCF_SUCCESS
# Check if INFORMIX, INFORMIXSERVER and ONCONFIG
# have been passed or set and validate them.
# OCF vars not passed, vars empty - set and export them to the shell environment.
if [ -n "$OCF_RESKEY_informixdir" -a -n "$OCF_RESKEY_informixserver" -a -n "$OCF_RESKEY_onconfig" ]; then
ids_log info "ids_validate: passed vars not empty"
INFORMIXDIR=$OCF_RESKEY_informixdir
export INFORMIXDIR
INFORMIXSERVER=$OCF_RESKEY_informixserver
export INFORMIXSERVER
ONCONFIG=$OCF_RESKEY_onconfig
export ONCONFIG
fi
# Check if INFORMIXDIR is non-empty and a directory (and if there was an error so far).
if [ $rc -eq $OCF_SUCCESS -a -n "$INFORMIXDIR" -a -d "$INFORMIXDIR" ]; then
ids_log info "ids_validate: INFORMIXDIR is valid: $INFORMIXDIR"
rc=$OCF_SUCCESS
else
ids_log error "ids_validate: INFORMIXDIR is invalid: $INFORMIXDIR"
rc=$OCF_ERR_ARGS
fi
# Check if INFORMIXSERVER is non-empty (and if there was an error so far).
if [ $rc -eq $OCF_SUCCESS -a -n "$INFORMIXSERVER" ]; then
ids_log info "ids_validate: INFORMIXSERVER is valid: $INFORMIXSERVER"
rc=$OCF_SUCCESS
else
ids_log error "ids_validate: INFORMIXSERVER is invalid: $INFORMIXSERVER"
rc=$OCF_ERR_ARGS
fi
# Check if ONCONFIG is non-empty and a non-empty file (and if there was an error so far).
if [ $rc -eq $OCF_SUCCESS -a -n "$ONCONFIG" -a -s "$INFORMIXDIR/etc/$ONCONFIG" ]; then
ids_log info "ids_validate: ONCONFIG is a non-empty file in: \$INFORMIXDIR/etc/\$ONCONFIG where ONCONFIG=$ONCONFIG"
rc=$OCF_SUCCESS
else
if [ -z "$ONCONFIG" -a -s "$INFORMIXDIR/etc/onconfig" ]; then
ONCONFIG="onconfig"
export ONCONFIG
ids_log info "ids_validate: ONCONFIG is a non-empty file in: \$INFORMIXDIR/etc/\$ONCONFIG where ONCONFIG=$ONCONFIG"
rc=$OCF_SUCCESS
else
if [ -z "$ONCONFIG" -a -s "$INFORMIXDIR/etc/onconfig.std" ]; then
ONCONFIG="onconfig.std"
export ONCONFIG
ids_log info "ids_validate: ONCONFIG is a non-empty file in: \$INFORMIXDIR/etc/\$ONCONFIG where ONCONFIG=$ONCONFIG"
rc=$OCF_SUCCESS
else
ids_log error "ids_validate: ONCONFIG is invalid, searched for it in: \$INFORMIXDIR/etc/\$ONCONFIG where ONCONFIG=$ONCONFIG"
rc=$OCF_ERR_ARGS
fi
fi
fi
# Check if the commands oninit, onstat, onmode and dbaccess exist in INFORMIXDIR/bin/
# and whether they are executable (do this only if there wasn't an error so far).
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
ids_log info "ids_validate: oninit, onstat and dbaccess exist and are executable in: \$INFORMIXDIR/bin/"
rc=$OCF_SUCCESS
else
ids_log error "ids_validate: oninit, onstat or dbacces don't exist or they are not executable in: \$INFORMIXDIR/bin/"
rc=$OCF_ERR_PERM
fi
# Extend PATH and LD_LIBRARY_PATH as needed for the IDS instance to run properly
# BUT: only do this if it hasn't been done before! Otherwise PATH and LD_LIBRARY_PATH will
# keep on growing every time heartbeat calls the IDS resource agent script! ;)
echo $PATH | grep $INFORMIXDIR > /dev/null 2>&1
inpath=$?
if [ $rc -eq $OCF_SUCCESS -a $inpath -ne 0 ]; then
PATH="${INFORMIXDIR}/bin":${PATH}
export PATH
ids_log info "ids_validate: PATH did not contain INFORMIXDIR, added \$INFORMIXDIR/bin"
else
ids_log info "ids_validate: INFORMIXDIR already in PATH, where PATH=$PATH"