Automatically Starting/Stopping an Oracle 10g Database Server on Red Hat Enterprise Linux (RHEL4)

Category: Software and Systems Engineering
Author: Sean O'Donnell
Fri, Apr. 13th, 2007 @ 14:57:03 (MDT)

Due to the nature of the beast (so to say), Oracle 10g Enterprise Server doesn't install any startup or shutdown scripts for the Red Hat Enterprise Linux 4 (RHEL4) Operating System (or any other Linux-based OS, as far as I know).

Luckily, it's a very simple process that only takes about 5 minutes, once. This example is intended to be used with Red Hat Enterprise Linux 4 (RHEL4), and is intended more for my own personal reference, but others may find it useful as well.

/etc/init.d/dbora

The shell script below is intended to be executed during the startup and shutdown of the Operating System.

#!/bin/sh -x
#
# file: /etc/init.d/dbora
#
# This script is intended to allow the automated 
# startup and shutdown of an oracle database server.

# Author: Sean O'Donnell <sean@seanodonnell.com>
#

# the user that oracle runs as (default: oracle)
ORACLE=oracle

# database instance id
ORACLE_SID=devdb1

# ORACLE_HOME (file system) path
ORACLE_HOME=/usr/local/oracle/product/10.2.0/db_1

PATH=${PATH}:$ORACLE_HOME/bin

export ORACLE_SID ORACLE_HOME PATH

case $1 in
  'start')
    su - $ORACLE -c "$ORACLE_HOME/bin/lsnrctl start"
    su - $ORACLE -c $ORACLE_HOME/bin/dbstart
    su - $ORACLE -c "$ORACLE_HOME/bin/emctl start dbconsole"
  ;;
  'stop')
    su - $ORACLE -c "$ORACLE_HOME/bin/emctl stop dbconsole"
    su - $ORACLE -c $ORACLE_HOME/bin/dbshut
    su - $ORACLE -c "$ORACLE_HOME/bin/lsnrctl stop"
  ;;
  *)
    echo "usage: $0 {start|stop}"
  ;;
esac

exit

You can copy/paste/modify the script above, and save-as: '/etc/init.d/dbora'.

Once you've created the boot-script (/etc/init.d/dbora), you'll want to change the group ownership to the DBA group (dba), and change the file permissions to allow group-level execution.

chgrp dba /etc/init.d/dbora
chmod 750 /etc/init.d/dbora

You'll then want to create symbolic links to the boot-script directories.

ln -s /etc/init.d/dbora /etc/rc.d/rc3.d/K01dbora
ln -s /etc/init.d/dbora /etc/rc.d/rc3.d/S99dbora
ln -s /etc/init.d/dbora /etc/rc.d/rc5.d/K01dbora
ln -s /etc/init.d/dbora /etc/rc.d/rc5.d/S99dbora

Your Operating System should now automatically start/stop the Oracle Database Server upon startup and shutdown.

Copyleft (<) 1998-2019 www.seanodonnell.com