1. first change the file /etc/oratab
The format of the /etc/oratab file is as follows:
database_sidracle_home_dir:Y|N
example: orcl:/home/oracle:Y

2. Now, we need to create the script which will run dbshut and dbstart in the /etc/rc.d/init.d directory.

a.) Create the following file as /etc/rc.d/init.d/oracle
b.) Chmod 777 oracle



#!/bin/sh
#chkconfig:345 99 10
# /etc/rc.d/init.d/oracle
# Description: Starts and stops the Oracle database and listeners
case "$1" in
start)
echo -n "Starting Oracle Databases: " >> /var/log/oracle
date +"! %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
su - oracle -c dbstart >> /var/log/oracle
echo "Done."
echo -n "Starting Oracle Listeners: "
su - oracle -c "lsnrctl start" >> /var/log/oracle
echo "Done."
date +"! %T %a %D : Finished." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
touch /var/lock/subsys/oracle
;;
stop)
echo -n "Shutting Down Oracle Listeners: "
echo "----------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Shutting Down Oracle Databases as part of system down." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
su - oracle -c "lsnrctl stop" >> /var/log/oracle
echo "Done."
rm -f /var/lock/subsys/oracle
echo -n "Shutting Down Oracle Databases: "
su - oracle -c dbshut >> /var/log/oracle
echo "Done."
;;
restart)
echo -n "Restarting Oracle Databases: "
echo "----------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Restarting Oracle Databases as part of system up." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
su - oracle -c dbstop >> /var/log/oracle
su - oracle -c dbstart >> /var/log/oracle
echo "Done."
echo -n "Restarting Oracle Listeners: "
su - oracle -c "lsnrctl stop" >> /var/log/oracle
su - oracle -c "lsnrctl start" >> /var/log/oracle
echo "Done."
echo ""
echo "----------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Finished." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
touch /var/lock/subsys/oracle
;;
*)
echo "Usage: oracle {start|stop|restart}"
exit 1
esac

3. check the log file /var/log/oracle for error messages


4. Once this script is working we need to create start and kill symbolic links in the appropriate runlevel directories /etc/rc.d/rcX.d.

5. The following commands will ensure that the databases will come up in runlevel2,3 and 4:*

Now create the following links
ln -s /etc/rc.d/init.d/oracle /etc/rc.d/rc2.d/S99oracle
ln -s /etc/rc.d/init.d/oracle /etc/rc.d/rc3.d/S99oracle
ln s /etc/rc.d/init.d/oracle /etc/rc.d/rc4.d/S99oracle
*
To stop the databases on reboot or restart we need the following links: *

ln -s etc/rc.d/init.d/oracle /etc/rc.d/rc0.d/K01oracle
ln -s etc/rc.d/init.d/oracle /etc/rc.d/rc6.d/K01oracle
*

[root@localhost ~]# chkconfig --add oracle
[root@localhost ~]# chkconfig --list | grep oracle

oracle 0ff 1ff 2n 3n 4n 5n 6ff



[root@localhost ~]# /etc/init.d/oracle stop
Shutting Down Oracle Listeners: Done.
Shutting Down Oracle Databases: Done.

[root@localhost ~]# ps -ef| grep pmon
root 6313 4142 0 19:53 pts/1 00:00:00 grep pmon

[root@localhost ~]# /etc/init.d/oracle start
Done.
Starting Oracle Listeners: Done.

[root@localhost ~]# ps -ef| grep pmon
oracle 6404 1 0 19:53 ? 00:00:00 ora_pmon_orcl
root 6476 4142 0 19:53 pts/1 00:00:00 grep pmon
[root@localhost ~]#