#
# Get the status of the OPMN-managed processes.
#
get_opmn_status()
{
declare -i subsys_lock=$1
declare -i ct_errors=0
opmnctl status &> /dev/null
if [ $? -eq 2 ]; then
#
# OPMN not running??
#
echo "opmn is stopped"
if [ $subsys_lock -eq 0 ]; then
#
# Don't handle full opmn-restart. XXX
#
return 1
fi
# That's okay, it's not supposed to be!
return 3
fi
#
# Print out the PIDs for everyone.
#
echo "opmn is running..."
echo "opmn components:"
#
# Check the OPMN-managed processes
#
get_opmn_proc_status OID || ((ct_errors++))
get_opmn_proc_status HTTP_Server || ((ct_errors++))
get_opmn_proc_status OC4J OC4J_SECURITY || ((ct_errors++))
#
# One or more OPMN-managed processes failed and could not be
# restarted.
#
if [ $ct_errors -ne 0 ]; then
return 1
fi
return 0
}
#
# Oracle needs the system's hostname to match the VIP. RHCS needs to not be
# tinkering with the hostname. Thus, we trick Oracle into believing that the
# hostname is the vhost by overloading gethostname().
#
hostname_hackery()
{
if [ "`hostname`" = "$ORACLE_HOSTNAME" ]; then
return 0
fi
PRELOADDIR=$ORACLE_HOME
cat > $PRELOADDIR/hostname.c <<EOT
/*
Hack to make Oracle 10g work in failover environments
without adjusting the hostname.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#ifndef ORACLE_HOSTNAME
#define ORACLE_HOSTNAME "$ORACLE_HOSTNAME"
#endif
int
gethostname(char *buf, size_t len)
{
char *val = ORACLE_HOSTNAME;
if (!buf || len <= 0) {
errno = EINVAL;
return -1;
}
memset(buf,0,len);
if (!strlen(val))
return 0;
if (snprintf(buf, len, "%s", val) == len) {
errno = ENAMETOOLONG;
return -1;
}
return 0;
}
EOT
if [ -e $PRELOADDIR/hostname.so ]; then
export LD_PRELOAD=$PRELOADDIR/hostname.so
return 0
fi
action "Creating hostname preload library:" gcc -o $PRELOADDIR/hostname.so $PRELOADDIR/hostname.c -shared -Wall -fPIC || return 1
rm $PRELOADDIR/hostname.c
export LD_PRELOAD=$PRELOADDIR/hostname.so
return 0
}
#
# Helps us keep a running status so we know what our ultimate return
# code will be. Returns 1 if the $1 and $2 are not equivalent, otherwise
# returns $1. The return code is meant to be the next $1 when this is
# called, so, for example:
#
# update_status 0 <-- returns 0
# update_status $? 0 <-- returns 0
# update_status $? 3 <-- returns 1 (values different - error condition)
# update_status $? 1 <-- returns 1 (same, but happen to be error state!)
#
# update_status 3
# update_status $? 3 <-- returns 3
#
# (and so forth...)
#
update_status()
{
declare -i old_status=$1
declare -i new_status=$2
if [ -z "$2" ]; then
return $old_status
fi
if [ $old_status -ne $new_status ]; then
return 1
fi
return $old_status
}
#
# Print an error message to the user and exit.
#
oops()
{
echo "Please configure this script ($0) to"
echo "match your installation."
echo
echo " $1 failed validation checks."
exit 1
}
#
# Do some validation on the user-configurable stuff at the beginning of the
# script.
#
validation_checks()
{
#
# If the oracle user doesn't exist, we're done.
#
[ -n "$ORACLE_USER" ] || oops ORACLE_USER
id -u $ORACLE_USER > /dev/null || oops ORACLE_USER
id -g $ORACLE_USER > /dev/null || oops ORACLE_USER
#
# If the oracle home isn't a directory, we're done
#
[ -n "$ORACLE_HOME" ] || oops ORACLE_HOME
#[ -d "$ORACLE_HOME" ] || oops ORACLE_HOME
#
# If the oracle SID is NULL, we're done
#
[ -n "$ORACLE_SID" ] || oops ORACLE_SID
#
# If we don't know the type, we're done
#
[ "$ORACLE_TYPE" = "10g" ] || [ "$ORACLE_TYPE" = "10g-ias" ] || oops ORACLE_TYPE
#
# If the hostname is zero-length, fix it
#
[ -n "$ORACLE_HOSTNAME" ] || ORACLE_HOSTNAME=`hostname`
#
# Super user? Automatically change UID and exec as oracle user.
# Oracle needs to be run as the Oracle user, not root!
#
if [ "`id -u`" = "0" ]; then
echo "Restarting $0 as $ORACLE_USER."
exec sudo -u $ORACLE_USER $0 $*
fi
#
# If we're not root and not the Oracle user, we're done.
#
[ "`id -u`" = "`id -u $ORACLE_USER`" ] || exit 1
[ "`id -g`" = "`id -g $ORACLE_USER`" ] || exit 1
#
# Go home.
#
cd $ORACLE_HOME
return 0
}
#
# Start Oracle9i Application Server Infrastructure
#
start_oracle()
{
faction "Starting Oracle Database:" start_db || return 1
action "Starting Oracle Listener:" lsnrctl start || return 1
if [ "$ORACLE_TYPE" = "10g" ]; then
action "Starting iSQL*Plus:" isqlplusctl start || return 1
action "Starting Oracle EM DB Console:" emctl start dbconsole || return 1
elif [ "$ORACLE_TYPE" = "10g-ias" ]; then
action "Starting Oracle EM:" emctl start em || return 1
action "Starting iAS Infrastructure:" opmnctl startall || return 1
fi
if [ -n "$LOCKFILE" ]; then
touch $LOCKFILE
fi
return 0
}
#
# Stop Oracle9i Application Server Infrastructure
#
stop_oracle()
{
if ! [ -e "$ORACLE_HOME/bin/lsnrctl" ]; then
echo "Oracle Listener Control is not available"
echo " ($ORACLE_HOME not mounted?)"
return 0
fi
if [ "$ORACLE_TYPE" = "10g" ]; then
action "Stopping Oracle EM DB Console:" emctl stop dbconsole || return 1
action "Stopping iSQL*Plus:" isqlplusctl stop || return 1
elif [ "$ORACLE_TYPE" = "10g-ias" ]; then
action "Stopping iAS Infrastructure:" opmnctl stopall || return 1
action "Stopping Oracle EM:" emctl stop em || return 1
fi
faction "Stopping Oracle Database:" stop_db || return 1
action "Stopping Oracle Listener:" lsnrctl stop
faction "Waiting for all Oracle processes to exit:" exit_idle
if [ $? -ne 0 ]; then
echo "WARNING: Not all Oracle processes exited cleanly"
fi
if [ -n "$LOCKFILE" ]; then
rm -f $LOCKFILE
fi
return 0
}
#
# Find and display the status of iAS infrastructure.
#
# This has three parts:
# (1) Oracle database itself
# (2) Oracle listener process
# (3) OPMN and OPMN-managed processes
#
# - If all are (cleanly) down, we return 3. In order for this to happen,
# $LOCKFILE must not exist. In this case, we try and restart certain parts
# of the service - as this may be running in a clustered environment.
#
# - If some but not all are running (and, if $LOCKFILE exists, we could not
# restart the failed portions), we return 1 (ERROR)
#
# - If all are running, return 0. In the "all-running" case, we recreate
# $LOCKFILE if it does not exist.
#
status_oracle()
{
declare -i subsys_lock=1
declare -i last
declare -i depth=$1
#
# Check for lock file. Crude and rudimentary, but it works
#
if [ -z "$LOCKFILE" ] || [ -f $LOCKFILE ]; then
subsys_lock=0
fi
# Check database status
get_db_status $subsys_lock $depth
update_status $? # Start
last=$?
# Check & report listener status
get_lsnr_status $subsys_lock $depth
update_status $? $last
last=$?
if [ "$ORACLE_TYPE" = "10g" ]; then
# XXX Add isqlplus status check?!
emctl status dbconsole 2>&1 | grep "is running"
update_status $? $last
last=$?
elif [ "$ORACLE_TYPE" = "10g-ias" ]; then
# Check & report opmn / opmn-managed process status
get_opmn_status $subsys_lock $depth
update_status $? $last
last=$?
fi
#
# No lock file, but everything's running. Put the lock
# file back. XXX - this kosher?
#
if [ $last -eq 0 ] && [ $subsys_lock -ne 0 ]; then
touch $LOCKFILE
fi
return $last
}
