Wednesday, May 26, 2010

Automating Database Startup and Shutdown on Linux

Automating Database Startup and Shutdown on Linux

Edit the "/etc/oratab" file setting the restart flag for each instance to 'Y'.

 

Next, create a file called "/etc/init.d/oracle" as the root user, containing the following.

 

###########################################################################

#!/bin/bash                                                               #

#                                                                         #

# Run-level Startup script for the Oracle Instance and Listener           #

#                                                                         #

# chkconfig: 345 98 34                                                    #

# description: Startup/Shutdown Oracle listener, dbconsole and instances  #

#                                                                         #

###########################################################################

 

ORA_HM="/d01/app/oracle/product/10.2.0.2.0"

ORA_OWNR="oracle"

 

# if the executables do not exist -- display error

 

if [ ! -f $ORA_HM/bin/dbstart -o ! -d $ORA_HM ]

then

        echo "Oracle startup: cannot start"

        exit 1

fi

 

# depending on parameter -- startup, shutdown, restart

# of the instance and listener or usage display

 

case "$1" in

    start)

        # Oracle listener and instance startup

        echo -n "Starting Oracle: "

        su - $ORA_OWNR -c "$ASM_HM/bin/lsnrctl start"

        su - $ORA_OWNR -c $ORA_HM/bin/dbstart

        touch /var/lock/subsys/oracle

        su - $ORA_OWNR -c "export ORACLE_SID=MMDEVDB;$ORA_HM/bin/emctl start dbconsole"

              su - $ORA_OWNR -c "export ORACLE_SID=MMDEVPSDB;$ORA_HM/bin/emctl start dbconsole"

        su - $ORA_OWNR -c "export ORACLE_SID=MMQADB;$ORA_HM/bin/emctl start dbconsole"

              su - $ORA_OWNR -c "export ORACLE_SID=MMQAPSDB;$ORA_HM/bin/emctl start dbconsole"

        echo "OK"

        ;;

    stop)

        # Oracle listener and instance shutdown

        echo -n "Shutdown Oracle: "

        su - $ORA_OWNR -c "export ORACLE_SID=MMDEVDB;$ORA_HM/bin/emctl stop dbconsole"

        su - $ORA_OWNR -c "export ORACLE_SID=MMDEVPSDB;$ORA_HM/bin/emctl stop dbconsole"

        su - $ORA_OWNR -c "export ORACLE_SID=MMQADB;$ORA_HM/bin/emctl stop dbconsole"

        su - $ORA_OWNR -c "export ORACLE_SID=MMQAPSDB;$ORA_HM/bin/emctl stop dbconsole"

        su - $ORA_OWNR -c "$ASM_HM/bin/lsnrctl stop"

        su - $ORA_OWNR -c $ORA_HM/bin/dbshut

        rm -f /var/lock/subsys/oracle

        echo "OK"

        ;;

    reload|restart)

        $0 stop

        $0 start

        ;;

    *)

        echo "Usage: $0 start|stop|restart|reload"

        exit 1

esac

exit 0

#########################################################################################

 

chmod 750 /etc/init.d/oracle

 

chkconfig --level 345 oracle on

 

How to turn off/on the script.

[root@bl-mm-db-dev ~]# /sbin/chkconfig oracle off

[root@bl-mm-db-dev ~]# /sbin/chkconfig --levels 345 oracle on


No comments:

Post a Comment

Followers