Automatic start and stop at reboot

The following represents the Oracle recommended method for automating database startup and shutdown of instances and listener. The examples that are based on Oracle 11 are also valid for Oracle 12.

  1. Create instances for each environment and edit the file /etc/oratab setting the restart flag for each instance to 'Y'.

    Examples:

    PROD:/u01/app/oracle/product/11:Y 
    TEST:/u01/app/oracle/product/11:Y
  2. Logged on as the root user, create a file /etc/rc.d/init.d/dbora
  3. Enter the following, making sure that you set the variables ORA_HOME correctly.
    #!/bin/sh
    # 
    # 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=/u01/app/oracle/product/11
    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/dbstart $ORA_HOME"
            ;;
        'stop')
            # Stop the Oracle databases:
            # The following command assumes that the oracle login 
            # will not prompt the user for any values
            echo su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME"
            su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME"
            ;;
    esac
    
  4. Change the group of the script dbora to the dba group and set the permissions to 750, using the following commands:
    # chgrp dba dbora
    # chmod 750 dbora
    
  5. Create symbolic links to the script dbora in the appropriate run-level script directories, using the following commands:
    # ln -s /etc/rc.d/init.d/dbora /etc/rc.d/rc2.d/S99dbora
    # ln -s /etc/rc.d/init.d/dbora /etc/rc.d/rc2.d/K01dbora