#!/bin/bash
. /etc/rc.d/init.d/functions
ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
ORACLE_SID=center
ORACLE_NAME=oracle
LOCKFILE="$ORACLE_HOME/.oracle.lock"
RESTART_RETRIES=3
DB_PROCNAMES="pmon"
LSNR_PROCNAME="tnslsnr"
start() {
echo "Starting Oracle10g Server... "
tmpfile=/home/oracle/`basename $0`-start.$$
logfile=/home/oracle/`basename $0`-start.log
echo "startup" > $tmpfile
echo "quit" >> $tmpfile
su - $ORACLE_NAME -c "sqlplus \"/ as sysdba\" < $tmpfile &> $logfile"
if [ $? -ne 0 ]; then
echo "ORACLE_HOME Incorrectly set?"
echo "See $logfile for more information."
return 1
fi
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
echo "Starting listern..."
((su - $ORACLE_NAME -c "$ORACLE_HOME/bin/lsnrctl start") >> $logfile 2>&1) || return 1
if [ -n "$LOCKFILE" ]; then
touch $LOCKFILE
fi
return 0
}
stop() {
echo "Shutting down Oracle10g Server..."
declare tmpfile
declare logfile
tmpfile=/home/oracle/`basename $0`-stop.$$
logfile=/home/oracle/`basename $0`-stop.log
if [ -z "$LOCKFILE" ] || [ -f $LOCKFILE ]; then
echo
else
echo "oracle is not run"
return 0
fi
echo "shutdown abort" > $tmpfile
echo "quit" >> $tmpfile
su - $ORACLE_NAME -c "sqlplus \"/ as sysdba\" < $tmpfile &> $logfile"
if [ $? -ne 0 ]; then
echo "ORACLE_HOME Incorrectly set?"
echo "See $logfile for more information."
return 1
fi
rm -f $tmpfile
grep -q failure $logfile
if [ $? -eq 0 ]; then
echo
echo "Possible reason: ORACLE_SID Incorrectly set."
echo "See $logfile for more information."
return 1
fi
status $LSNR_PROCNAME
if [ $? -ne 0 ] ; then
if [ -n "$LOCKFILE" ]; then
rm -f $LOCKFILE
fi
return 0
fi
((su - $ORACLE_NAME -c "$ORACLE_HOME/bin/lsnrctl stop") >> $logfile 2>&1) || return 1
if [ -n "$LOCKFILE" ]; then
rm -f $LOCKFILE
fi
return 0
}
get_lsnr_status() {
declare -i subsys_lock=$1
status $LSNR_PROCNAME
if [ $? == 0 ] ; then
return 0
elif [ $subsys_lock -ne 0 ]; then
return 3
elif [ $? -ne 0 ] ; then
return 1
fi
}
get_db_status() {
declare -i subsys_lock=$1
declare -i i=0
declare -i rv=0
declare ora_procname
for procname in $DB_PROCNAMES ; do
ora_procname="ora_${procname}_${ORACLE_SID}"
status $ora_procname
if [ $? -eq 0 ] ; then
continue
elif [ $subsys_lock -ne 0 ]; then
return 3
elif [ $? -ne 0 ] ; then
return 1
fi
done
}
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
}
status_ias() {
declare -i subsys_lock=1
declare -i last
if [ -z "$LOCKFILE" ] || [ -f $LOCKFILE ]; then
subsys_lock=0
fi
get_db_status $subsys_lock
update_status $?
last=$?
get_lsnr_status $subsys_lock
update_status $? $last
last=$?
if [ $last -eq 0 ] && [ $subsys_lock -ne 0 ]; then
touch $LOCKFILE
fi
return $last
}
restart() {
echo -n "Restart Oracle10g Server"
stop
start
echo
}
case "$1" in
start)
start
exit $?
;;
stop)
stop
exit $?
;;
status)
status_ias
exit $?
;;
restart|reload)
stop
start
;;
*)
echo "Usage: $0 {start|stop|reload|restart|status}"
exit 1
;;
esac
exit 0