OracleDB‎ > ‎

Startup Script

Oracle database automatic startup at boot time

Automatically Start / Stop the Database and Listener

   If you want to start the database automatically on boot-time perform the following steps:
      1. Copy standard oracle scripts dbstart and dbshut to $ORACLE_BASE/admin
      2. Create start/stop script in /etc/init.d
      3. Activate this start/stop script with chkconfig
      4. Edit /etc/oratab to start/stop the desired Databases

Copy standard oracle scripts dbstart and dbshut to $ORACLE_BASE/admin

cd $ORACLE_HOME/bin cp dbstart dbshut $ORACLE_BASE/admin

Create start/stop script in /etc/init.d as user root.

#!/bin/bash # # chkconfig: 12345 99 10 # description: Oracle auto start-stop script # -------------------------------------------------------------------------- # File: oracle # # Purpose: Oracle auto start-stop script # # Location: /etc/init.d # # Certified: Oracle 10.2.0.3 on Enterprise Linux 5 # -------------------------------------------------------------------------- # Variables ORACLE_OWNER=oracle; export ORACLE_OWNER ORACLE_BASE=/export/home/oracle; export ORACLE_BASE ORACLE_SCRIPTS_DIR=$ORACLE_BASE/admin; export ORACLE_SCRIPTS_DIR ORACLE_HOME=$ORACLE_BASE/product/10.2.0; export ORACLE_HOME # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. [ -f /etc/sysconfig/network ] && . /etc/sysconfig/network RETVAL=0 prog="oracle" start() { echo -n $"Starting $prog: " if [ ! -f $ORACLE_SCRIPTS_DIR/dbstart ] then echo "Oracle not started (no dbstart script)" else # Start RDBMS su - $ORACLE_OWNER -c $ORACLE_SCRIPTS_DIR/dbstart # Start Enterprise Manager Console # su - $ORACLE_OWNER $ORACLE_HOME/bin/emctl start dbconsole # Start iSQL*Plus # su - $ORACLE_OWNER $ORACLE_HOME/bin/isqlplusctl start fi RETVAL=$? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/oracle return $RETVAL } stop() { echo -n $"Shutting down $prog: " if [ ! -f $ORACLE_SCRIPTS_DIR/dbshut ] then echo "Oracle not stopped (no dbshut script)" else # Stop iSQL*Plus # su - $ORACLE_OWNER $ORACLE_HOME/bin/isqlplusctl stop # Stop Enterprise Manager Console # su - $ORACLE_OWNER $ORACLE_HOME/bin/emctl stop dbconsole # Stop RDBMS su - $ORACLE_OWNER -c $ORACLE_SCRIPTS_DIR/dbshut fi RETVAL=$? [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/oracle return $RETVAL } # See how we were called. case "$1" in start) start  ;; stop) stop  ;; *) echo $"Usage: $0 {start|stop}" exit 1 esac exit $RETVAL

Activate this start/stop script with chkconfig as root as follows

su - root chkconfig --add oracle chkconfig --list oracle

Edit /etc/oratab to start/stop the desired databases

      su - root cat /etc/oratab
   # Entries are of the form:
   # $ORACLE_SID:$ORACLE_HOME:<N|Y>:
   GENTIC:/export/home/oracle/product/10.2.0:Y



An alternate oracle startup script
#!/bin/sh
# /etc/rc.d/init.d/oracle
# Description: The following script
# starts and stops all Oracle databases and listeners
case "$1" in
start)
echo -n "Starting Oracle Databases: "
date +"! %T %a %D : Starting Oracle Databases after
system start 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."
echo ""
echo "--------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Finished." >> /var/log/oracle
echo "--------------------------------------" >> /var/log/oracle
;;
stop)
echo -n "Shutting Down Oracle Listeners: "
echo "----------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Shutting Down All Oracle Databases
as part of system shutdown." >> /var/log/oracle
echo "----------------------------------------" >> /var/log/oracle
su - oracle -c "lsnrctl stop" >> /var/log/oracle
echo "Done."
echo -n "Shutting Down Oracle Databases: "
su - oracle -c dbshut >> /var/log/oracle
echo "Done."
echo ""
echo "-----------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Finished." >> /var/log/oracle
echo "-----------------------------------------" >> /var/log/oracle
;;
restart)
echo -n "Restarting Oracle Databases: "
echo "------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Restarting Oracle Databases
after system startup." >> /var/log/oracle
echo "------------------------------------------" >> /var/log/oracle
su - oracle -c dbshut >> /var/log/oracle
su - oracle -c dbstart >> /var/log/oracle
echo "Done."
echo -n "Restarting the Oracle Listener: "
su - oracle -c "lsnrctl stop" >> /var/log/oracle
echo "Done."
echo ""
echo "---------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Finished." >> /var/log/oracle
echo "---------------------------------------------" >> /var/log/oracle
;;
*)
echo "Usage: oracle {start|stop|restart}"
exit 1
esac


Comments