Quantcast
Channel: Doyensys Allappsdba Blog..
Viewing all articles
Browse latest Browse all 1640

Auto startup / shutdown the database while OS starts / restart

$
0
0


Please  touch the file as root user

1. copy the oracle.txt file into /etc/init.d/oracle.
2. chmod 750 /etc/init.d/oracle
3. chkconfig --add oracle
4. To start the custom listener open the first $ORACLE_HOME/bin/dbstart and edit file as dbstart and dbshut.




cat  /etc/init.d/oracle
#!/bin/sh
#
# /etc/rc.d/init.d/dbase
# Description: Starts and stops the Oracle database and listeners
# See how we were called.
ORAHOME1=/u01/app/oracle/product/11.2.0/db_1
ORAHOME2=/u01/app/oracle/product/11.2.0/PROD

case "$1" in
  start)
        echo -n "Starting All Oracle Databases: "
        echo "----------------------------------------------------">> /var/log/dbase.log
        date +"! %T %a %D : Starting Oracle Databases as part of system up.">> /var/log/dbase.log
        echo "----------------------------------------------------">> /var/log/dbase.log
                echo -n "Starting Oracle Listeners:PROD"
        su - oracle -c "$ORAHOME2/bin/lsnrctl start PROD">> /var/log/dbase.log
        echo "Done."
        su - oracle -c dbstart >> /var/log/dbase.log
        echo "Done."
                echo -n "Starting Oracle Listeners:ORCL "
        su - oracle -c "$ORAHOME1/bin/lsnrctl start ORCL">> /var/log/dbase.log
        echo "Done."
        echo ""
        echo "----------------------------------------------------">> /var/log/dbase.log
        date +"! %T %a %D : Finished.">> /var/log/dbase.log
        echo "----------------------------------------------------">> /var/log/dbase.log

        echo ""
        echo "----------------------------------------------------">> /var/log/dbase.log
        date +"! %T %a %D : Finished.">> /var/log/dbase.log
        echo "----------------------------------------------------">> /var/log/dbase.log
                touch /var/lock/subsys/oracle
        ;;
  stop)
        echo -n "Shutting Down Oracle Listeners: "
        echo "----------------------------------------------------">> /var/log/dbase.log
        date +"! %T %a %D : Shutting Down Oracle Databases because of system down.">> /var/log/dbase.log
        echo "----------------------------------------------------">> /var/log/dbase.log
        su - oracle -c "$ORAHOME1/bin/lsnrctl stop ORCL">> /var/log/dbase.log
        echo "Done. ORCL"
                su - oracle -c "$ORAHOME2/bin/lsnrctl stop PROD">> /var/log/dbase.log
        echo "Done. PROD"
        rm -f /var/lock/subsys/oracle
        echo -n "Shutting Down All Oracle Databases: "
        su - oracle -c dbshut >> /var/log/dbase.log
        echo "Done."
        echo ""
        echo "----------------------------------------------------">> /var/log/dbase.log
        date +"! %T %a %D : Finished.">> /var/log/dbase.log
        echo "----------------------------------------------------">> /var/log/dbase.log
        ;;
  restart)
        echo -n "Restarting Oracle Databases: "
        echo "----------------------------------------------------">> /var/log/dbase.log
        date +"! %T %a %D : Restarting Oracle Databases as part of system up.">> /var/log/dbase.log
        echo "----------------------------------------------------">> /var/log/dbase.log
        su - oracle -c dbshut >> /var/log/dbase.log
        su - oracle -c dbstart >> /var/log/dbase.log
        echo "Done."
        echo -n "Restarting Oracle Listeners: ORCL"
        su - oracle -c "$ORAHOME1/bin/lsnrctl stop ORCL">> /var/log/dbase.log
        su - oracle -c "$ORAHOME1/bin/lsnrctl start ORCL">> /var/log/dbase.log
                 echo "Done. ORCL"
                echo -n "Restarting Oracle Listeners: PROD"
        su - oracle -c "$ORAHOME2/bin/lsnrctl stop PROD">> /var/log/dbase.log
        su - oracle -c "$ORAHOME2/bin/lsnrctl start PROD">> /var/log/dbase.log
        echo "Done. PROD"
        echo ""
        echo "----------------------------------------------------">> /var/log/dbase.log
        date +"! %T %a %D : Finished.">> /var/log/dbase.log
        echo "----------------------------------------------------">> /var/log/dbase.log
        touch /var/lock/subsys/oracle
        ;;
  *)
        echo "Usage: oracle {start|stop|restart}"
        exit 1
esac












 To start the custom Listener got to $ORACLE_HOME/bin/dbstart and edit like this


#PROD
ORACLE_HOME_LISTNER=/u01/app/oracle/product/11.2.0/PROD
if [ ! $ORACLE_HOME_LISTNER ] ; then
  echo "ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener"
  echo "Usage: $0 ORACLE_HOME"
else
  LOG=$ORACLE_HOME_LISTNER/listener.log

  # Set the ORACLE_HOME for the Oracle Net Listener, it gets reset to
  # a different ORACLE_HOME for each entry in the oratab.
  export ORACLE_HOME=$ORACLE_HOME_LISTNER

  # Start Oracle Net Listener
  if [ -x $ORACLE_HOME_LISTNER/bin/tnslsnr ] ; then
    echo "$0: Starting Oracle Net Listener">> $LOG 2>&1
    $ORACLE_HOME_LISTNER/bin/lsnrctl start PROD >> $LOG 2>&1 &
    VER10LIST=`$ORACLE_HOME_LISTNER/bin/lsnrctl version | grep "LSNRCTL for " | cut -d'' -f5 | cut -d'.' -f1`
    export VER10LIST
  else
    echo "Failed to auto-start Oracle Net Listener using $ORACLE_HOME_LISTNER/bin/tnslsnr"
  fi
fi
To stop the Custom listener go to $ORACLE_HOME/bin/dbshut and edit the file
as same
#PROD
# The  this to bring down Oracle Net Listener
ORACLE_HOME_LISTNER=/u01/app/oracle/product/11.2.0/PROD
if [ ! $ORACLE_HOME_LISTNER ] ; then
  echo "ORACLE_HOME_LISTNER is not SET, unable to auto-stop Oracle Net Listener"
  echo "Usage: $0 ORACLE_HOME"
else
  LOG=$ORACLE_HOME_LISTNER/listener.log

  # Set the ORACLE_HOME for the Oracle Net Listener, it gets reset to
  # a different ORACLE_HOME for each entry in the oratab.
  export ORACLE_HOME=$ORACLE_HOME_LISTNER

  # Stop Oracle Net Listener
  if [ -f $ORACLE_HOME_LISTNER/bin/tnslsnr ] ; then
    echo "$0: Stoping Oracle Net Listener">> $LOG 2>&1
    $ORACLE_HOME_LISTNER/bin/lsnrctl stop PROD >> $LOG 2>&1 &
  else
    echo "Failed to auto-stop Oracle Net Listener using $ORACLE_HOME_LISTNER/bin/tnslsnr"
  fi
fi


Viewing all articles
Browse latest Browse all 1640

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>