Monday, 7 March 2016

Autostart Script for Linux

If you want your database to startup when the server starts up, as well as shutdown when the server shuts down - log in as root and carry out the following steps.


Create the following file
/etc/init.d/dbora

Add the following lines:
#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.

ORA_HOME=/app/oracle/product/10.2.0/se
ORA_OWNER=oracle

if [ ! -f $ORA_HOME/bin/dbstart ]
then
    echo "Oracle startup: cannot start"
    exit
fi

case "$1" in
    'start')
        # Start the Oracle databases:
        # The following command assumes that the oracle login
        # will not prompt the user for any values
        su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
        su - $ORA_OWNER -c $ORA_HOME/bin/dbstart
        touch /var/lock/subsys/dbora
        ;;
    'stop')
        # Stop the Oracle databases:
        # The following command assumes that the oracle login
        # will not prompt the user for any values
        su - $ORA_OWNER -c $ORA_HOME/bin/dbshut
        su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
        rm -f /var/lock/subsys/dbora
        ;;
esac

Change the file permissions:
chmod 750 /etc/init.d/dbora

Add the file as service:
chkconfig --add dbora

Test (will shutdown abort and startup all database in the /etc/oratab file, so be careful):
 /etc/init.d/dbora stop
 /etc/init.d/dbora start

No comments:

Post a Comment