Oracle Database Init Script - /etc/init.d/dbora

Many Oracle shops want their database to automatically start when their server boots up, and to automatically shutdown when they shutdown the server.

Below I will share with you the Oracle init script that I use on my server. It has been tested with Oracle 10gR2 on RedHat Linux AS3.

  1. Login as the root user on your server.
  2. Put the following script in the file named /etc/init.d/dbora:
    #!/bin/sh
    # chkconfig: 345 99 10
    # description: Oracle auto start-stop script.
    #
    # Change the value of ORACLE_HOME to specify the correct Oracle home
    # directory for your installation.
    
    export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
    export PATH=$PATH:$ORACLE_HOME/bin
    export ORACLE_SID=PROD
    
    case "$1" in
        start)
            echo -n "Starting Oracle: "
            su - oracle -c $ORACLE_HOME/bin/dbstart
            touch /var/lock/oracle
    
            su - oracle -c "export ORACLE_SID=PROD;$ORACLE_HOME/bin/emctl start dbconsole"
            su - oracle -c "export ORACLE_SID=RPTG;$ORACLE_HOME/bin/emctl start dbconsole"
            su - oracle -c "export ORACLE_SID=DWHSE;$ORACLE_HOME/bin/emctl start dbconsole"
            echo "OK"
            ;;
        stop)
            echo -n "Shutdown Oracle: "
            su - oracle -c $ORACLE_HOME/bin/dbshut
            rm -f /var/lock/oracle
            su - oracle -c "$ORACLE_HOME/bin/emctl stop dbconsole"
            echo "OK"
            ;;
        *)
            echo "Usage: 'basename $0' start|stop"
            exit 1
    esac
    exit 0
    exit
    
  3. Make sure you set the appropriate permissions on the file.

    chmod 755 dbora
    
  4. Use the chkconfig command to add the dbora startup/shutdown script to the list of system services.

    chkconfig --add dbora
    
  5. Set the script to start for runlevels 3, 4 and 5.

    chkconfig --level 345 dbora on
    
  6. Verify the chkconfig configuration. Run the command:

    chkconfig --list dbora
    

    The output should look like:

    dbora           0:off   1:off   2:off   3:on    4:on    5:on    6:off
    

    Notice that it is set to on for run levels 3, 4, and 5.

Special Notes
There is one special thing to note with this script. This is the reason for the multiple start calls to the emctl command. This is the line that looks like:
su - oracle -c "export ORACLE_SID=PROD;$ORACLE_HOME/bin/emctl start dbconsole"

The reason for this is so that the enterprise manager console (the web based admin tool) is started for every database SID I have. You’ll notice that emctl gets called 3 times, once for every SID (PROD, RPTG, DWHSE).

The emctl command starts the service that by default for the first database runs on port 5500. So to access enterprise manager for my PROD instance, the url is:
http://myserver.timarcher.com:5500/em/

The next emctl that gets started is on port 5501, and so on.



v2.0