Automatically starting things
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)
[sourcecode language=”bash”]
#!/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
[/sourcecode]
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.