Automatically starting things

September 25, 2012 at 10:57 am | Posted in Linux, Oracle Developement | Leave a comment
Tags: , ,

To automatically start an Oracle database (11.2.0 in this case) on Linux RHEL 5, first edit the /etc/oratab file to allow for the dbstart command to startup the database. The oratab file contains an entry for each database. Each entry contains three elements separated by colons:

SID:Oracle_Home_path:start_flag

Example:

orcl:/u01/app/oracle/product/11.2.0/db_1:Y

Make sure that the start flag is set to Y.

Next, create a file orastart with the startup instruction in the /etc/init.d directory:

(I’ve added some logging instructions for better troubleshooting)

#!/bin/bash
# chkconfig: 345 99 10
# description: Starts Oracle database
#
#
#
LOG=/var/log/orastart.log
ORACLE_HOME=/u01/app/oracle/product/11.2.0.3/db_1
OWNER=oracle
echo "=============================================" >> $LOG
echo "$(date) Starting Database" >> $LOG
su - $OWNER -c "$ORACLE_HOME/bin/lsnrctl start" >> $LOG
su - $OWNER -c $ORACLE_HOME/bin/dbstart $ORACLE_HOME >> $LOG
echo "$(date) Finished." >> $LOG

Make sure to include the chkconfig and description comments. The three numbers after the command determine the start and stop priorities for the different runlevels. In this case, for runlevels 3, 4, and 5, the start priority is 99 and the stop priority is 10.

Grant execute permissions to the file.

Finally, add the file with the startup instructions to the runlevel information:

(as root)

$ cd /etc/init.d
$ chkconfig --add orastart

To verify that the startdb file has been added you can use:

$ chkconfig --list | grep startdb
orastart         0:off   1:off   2:off   3:on    4:on    5:on    6:off

Now reboot your machine and watch the database start up.

Further reading:

Automating Database Startup and Shutdown.

6 Stages of Linux Boot Process

About chkconfig

Advertisements

Leave a Comment »

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.
Entries and comments feeds.

%d bloggers like this: