Friday, April 16, 2010

Startup/Shutdown Script for Oracle

In my current project i wrote a startup/shutdown script for Oracle. Thought to share with you guys, may be helpful for you all. So if you use it in your env then make sure to modify the ORACLE environment variable as per your system.
This script is self-explanatory, Still if you not able to understand then give me a shout :). Well Yes this is the script for Oracle 11.2.0.1.0, so i have used dbshut and dbstart, which automatially start and stop listner. However i also find some kinda of bug in the dbstart and dbstop script, i mean a little tweaking made this script.

#!/bin/bash
#
# chkconfig: 345 99 10
#......................................................
# description: Oracle auto start-stop script
#
# Location: /etc/init.d
#.......................................................
ORACLE_OWNER=oracle; export ORACLE_OWNER

ORACLE_BASE=/u02/app/oracle; export ORACLE_BASE

ORACLE_BIN_DIR=$ORACLE_BASE/product/11.2.0/dbhome_1/bin/; export ORACLE_BIN_DIR

ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1; export ORACLE_HOME
#/u02/app/oracle/product/11.2.0/dbhome_1

# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
[ -f /etc/sysconfig/network ] && . /etc/sysconfig/network
RETVAL=0
prog="oracle"
start()
{
echo -n $"STARTING UP $prog: "
if [ ! -f $ORACLE_BIN_DIR/dbstart ]
then
echo "Oracle not started (no dbstart script)"
else
# Start RDBMS
su - $ORACLE_OWNER -c "$ORACLE_BIN_DIR/dbstart $ORACLE_HOME"
fi
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/oracle
return $RETVAL
}
stop()
{
echo -n $"SHUTTING DOWN $prog: "
if [ ! -f $ORACLE_BIN_DIR/dbshut ]
then
echo "Oracle cannot be stopped [No dbshut Script Found)"
else
su - $ORACLE_OWNER -c "$ORACLE_BIN_DIR/lsnrctl status"
stat=$?
echo $stat
su - $ORACLE_OWNER -c "$ORACLE_BIN_DIR/dbshut $ORACLE_HOME"
fi
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/oracle
return $RETVAL
}

restart()
{
stop
start
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
restart
;;
status)
status $prog
RETVAL=$?
;;

*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit $RETVAL

No comments:

Post a Comment