#!/bin/bash
. /etc/init.d/functions
# . /etc/sysconfig/oracledb
declare SCRIPT="`basename $0`"
declare SCRIPTDIR="`dirname $0`"
[ -n "$OCF_RESKEY_user" ] && ORACLE_USER=$OCF_RESKEY_user
[ -n "$OCF_RESKEY_home" ] && ORACLE_HOME=$OCF_RESKEY_home
[ -n "$OCF_RESKEY_name" ] && ORACLE_SID=$OCF_RESKEY_name
[ -n "$OCF_RESKEY_lockfile" ] && LOCKFILE=$OCF_RESKEY_lockfile
[ -n "$OCF_RESKEY_type" ] && ORACLE_TYPE=$OCF_RESKEY_type
[ -n "$OCF_RESKEY_vhost" ] && ORACLE_HOSTNAME=$OCF_RESKEY_vhost
#-----------------------------------------------------------------------------------------
# 1. Oracle user. Must be the same across all cluster members. In the event
# that this script is run by the super-user, it will automatically switch
# to the Oracle user and restart. Oracle needs to run as the Oracle
# user, not as root.
#
[ -n "$ORACLE_USER" ] || ORACLE_USER=oracle
#
# 2. Oracle home. This is set up during the installation phase of Oracle.
# From the perspective of the cluster, this is generally the mount point
# you intend to use as the mount point for your Oracle Infrastructure
# service.
#
[ -n "$ORACLE_HOME" ] || ORACLE_HOME=/u01/app/oracle/product/10.2.0
#
# 3. This is your SID. This is set up during oracle installation as well.
#
[ -n "$ORACLE_SID" ] || ORACLE_SID=orac
#
# 4. The oracle user probably doesn't have the permission to write to
# /var/lock/subsys, so use the user's home directory.
#
[ -n "$LOCKFILE" ] || LOCKFILE="/home/$ORACLE_USER/.oracle-ias.lock"
#[ -n "$LOCKFILE" ] || LOCKFILE="$ORACLE_HOME/.oracle-ias.lock"
#[ -n "$LOCKFILE" ] || LOCKFILE="/var/lock/subsys/oracle-ias" # Watch privileges
#
# 5. Type of Oracle Database. Currently supported: 10g 10g-iAS(untested!)
#
[ -n "$ORACLE_TYPE" ] || ORACLE_TYPE=10g
#
# 6. Oracle virtual hostname. This is the hostname you gave Oracle during
# installation.
#
[ -n "$ORACLE_HOSTNAME" ] || ORACLE_HOSTNAME=datebaseha
#-------------------------------------------------------------------------------------
ORACLE_TYPE=`echo $ORACLE_TYPE | tr A-Z a-z`
export ORACLE_USER ORACLE_HOME ORACLE_SID LOCKFILE ORACLE_TYPE
export ORACLE_HOSTNAME
#-----------------------------------------------------------------------------------
export LD_LIBRARY_PATH=$ORACLE_HOME/lib

ORACLE_HOME/opmn/lib
export PATH=$ORACLE_HOME/bin

ORACLE_HOME/opmn/bin

ORACLE_HOME/dcm/bin

PATH
declare -i RESTART_RETRIES=3
declare -r DB_PROCNAMES="pmon"
declare -r LSNR_PROCNAME="tnslsnr"
declare -r LOCKFILE="/home/$ORACLE_USER/.oracle-ias.lock"
#--------------------------------------------------------#
# (Hopefully) No user-serviceable parts below this line. #
#--------------------------------------------------------#
meta_data()
{
cat <<EOT
<?xml version="1.0" ?>
<resource-agent name="oracledb" version="rgmanager 2.0">
<version>1.0</version>
<longdesc lang="en">
Oracle 10g Failover Instance
</longdesc>
<shortdesc lang="en">
Oracle 10g Failover Instance
</shortdesc>
<parameters>
<parameter name="name" primary="1">
<longdesc lang="en">
Instance name (SID) of oracle instance
</longdesc>
<shortdesc lang="en">
Oracle SID
</shortdesc>
<content type="string"/>
</parameter>
<parameter name="user" unique="1" required="1">
<longdesc lang="en">
Oracle user name. This is the user name of the Oracle
user which the Oracle AS instance runs as.
</longdesc>
<shortdesc lang="en">
Oracle User Name
</shortdesc>
<content type="string"/>
</parameter>
<parameter name="home" unique="1" required="1">
<longdesc lang="en">
This is the Oracle (application, not user) home directory.
This is configured when you install Oracle.
</longdesc>
<shortdesc lang="en">
Oracle Home Directory
</shortdesc>
<content type="string"/>
</parameter>
<parameter name="type" required="1">
<longdesc lang="en">
This is the Oracle installation type.
Only "10g" and "10g-ias" are supported, and 10g-ias is
untested.
</longdesc>
<shortdesc lang="en">
Oracle Installation Type
</shortdesc>
<content type="string"/>
</parameter>
<parameter name="vhost" required="0" unique="1">
<longdesc lang="en">
Virtual Hostname matching the installation hostname of
Oracle 10g. Note that during the start/stop of an oracledb
resource, your hostname will temporarily be changed to
this hostname. As such, it is recommended that oracledb
resources be instanced as part of an exclusive service only.
</longdesc>
<shortdesc lang="en">
Virtual Hostname
</shortdesc>
<content type="string"/>
</parameter>
</parameters>
<actions>
<action name="start" timeout="900"/>
<action name="stop" timeout="90"/>
<action name="recover" timeout="990"/>
<!-- Checks to see if it's mounted in the right place -->
<action name="status" timeout="10"/>
<action name="monitor" timeout="10"/>
<!-- Checks to see if we can read from the mountpoint -->
<action name="status" depth="10" timeout="30" interval="5m"/>
<action name="monitor" depth="10" timeout="30" interval="5m"/>
<!-- Checks to see if we can write to the mountpoint (if !ROFS) -->
<action name="status" depth="20" timeout="90" interval="10m"/>
<action name="monitor" depth="20" timeout="90" interval="10m"/>
<action name="meta-data" timeout="5"/>
<action name="verify-all" timeout="5"/>
</actions>
<special tag="rgmanager">
<attributes maxinstances="1"/>
</special>
</resource-agent>
EOT
}
#
# "action"-like macro supporting functions
#
faction()
{
echo -n "$1"
shift
$*
if [ $? -eq 0 ]; then
echo_success
echo
return 0
fi
echo_failure
echo
return 1
}
#
# Start Oracle9i (database portion)
#
start_db()
{
declare tmpfile
declare logfile
declare -i rv
tmpfile=/tmp/$SCRIPT-start.$$
logfile=/tmp/$SCRIPT-start.log
#
# Set up our sqlplus script. Basically, we're trying to
# capture output in the hopes that it's useful in the case
# that something doesn't work properly.
#
echo "startup" > $tmpfile
echo "quit" >> $tmpfile
sqlplus "/ as sysdba" < $tmpfile &> $logfile
rv=$?
# Dump logfile to /var/log/messages
initlog -q -c "cat $logfile"
if [ $rv -ne 0 ]; then
echo "ORACLE_HOME Incorrectly set?"
echo "See $logfile for more information."
return 1
fi
#
# If we see:
# ORA-.....: failure, we failed
#
rm -f $tmpfile
grep -q "failure" $logfile
if [ $? -eq 0 ]; then
rm -f $tmpfile
echo "ORACLE_SID Incorrectly set?"
echo "See $logfile for more information."
return 1
fi
return 0
}
#
# Stop Oracle9i (database portion)
#
stop_db()
{
declare tmpfile
declare logfile
declare -i rv
tmpfile=/tmp/$SCRIPT-stop.$$
logfile=/tmp/$SCRIPT-stop.log
# Setup for Stop ...
echo "shutdown abort" > $tmpfile
echo "quit" >> $tmpfile
sqlplus "/ as sysdba" < $tmpfile &> $logfile
rv=$?
# Dump logfile to /var/log/messages
initlog -q -c "cat $logfile"
if [ $rv -ne 0 ]; then
echo "ORACLE_HOME Incorrectly set?"
echo "See $logfile for more information."
return 1
fi
#
# If we see 'failure' in the log, we're done.
#
rm -f $tmpfile
grep -q failure $logfile
if [ $? -eq 0 ]; then
echo_failure
echo
echo "

ossible reason: ORACLE_SID Incorrectly set."
echo "See $logfile for more information."
return 1
fi
return 0
}