in Linux, Oracle

Oracle startup and shutdown script: very famous (dbora) ;)

This is the most complete dbora script i came up with, i used linux subsystem and pid file for complete status workings… please have a look and n point out if there is anything to be done further in it…

 

#!/bin/sh
# chkconfig: 345 55 25
# /etc/init.d/dbora
# Description: Starts and stops the Oracle database and listener
# Author: ConArtist
# Date: 21/04/14
# source function library

. /etc/rc.d/init.d/functions
PID_FILE=/var/run/dbora.pid
LOG_FILE=/var/log/oracle
ORA_HOME=/u01/app/oracle/product/12.1.0.1/

status()
{
    . /etc/rc.d/init.d/functions
    status -p $PID_FILE dbora
}

case "$1" in
  start)
        echo "Starting Oracle Database and Listener: "
        echo "----------------------------------------------------" >> $LOG_FILE
        date +"! %T %a %D : Starting Oracle Database as part of system up." >> $LOG_FILE
        echo "----------------------------------------------------" >> $LOG_FILE
        echo -n "Starting Oracle Database: "
        su - oracle -c "dbstart $ORA_HOME" >> $LOG_FILE  && success || failure
        echo
        echo -n "Starting Oracle Listener: "
        su - oracle -c "lsnrctl start" >> $LOG_FILE && success || failure
        echo
        echo ""
        echo "----------------------------------------------------" >> $LOG_FILE
        date +"! %T %a %D : Finished." >> $LOG_FILE
        echo "----------------------------------------------------" >> $LOG_FILE
        touch /var/lock/subsys/dbora
        touch $PID_FILE
        ps -e | grep tnslsnr | awk '{print $1;}' > $PID_FILE
        ;;
  stop)
        date +"! %T %a %D : Shutting Down Oracle Database and Listener: "
        echo "----------------------------------------------------" >> $LOG_FILE
        date +"! %T %a %D : Shutting Down Oracle Database as part of system down." >> $LOG_FILE
        echo "----------------------------------------------------" >> $LOG_FILE
        echo -n "Shutting Down Oracle Listener: "
        su - oracle -c "lsnrctl stop" >> $LOG_FILE && success || failure
        echo
        rm -f /var/lock/subsys/dbora
        rm -f $PID_FILE
        echo -n "Shutting Down Oracle Database: "
        su - oracle -c "dbshut $ORA_HOME" >> $LOG_FILE  && success || failure
        echo
        echo ""
        echo "----------------------------------------------------" >> $LOG_FILE
        date +"! %T %a %D : Finished." >> $LOG_FILE
        echo "----------------------------------------------------" >> $LOG_FILE
        ;;
  restart)
        echo "----------------------------------------------------" >> $LOG_FILE
        date +"! %T %a %D : Restarting Oracle Database" >> $LOG_FILE
        echo "----------------------------------------------------" >> $LOG_FILE
        echo -n "Restarting Oracle Database: "
        su - oracle -c "dbshut $ORA_HOME">> $LOG_FILE && success || failure
        su - oracle -c "dbstart $ORA_HOME" >> $LOG_FILE && success || failure
        echo
        echo -n "Restarting Oracle Listener: "
        su - oracle -c "lsnrctl stop" >> $LOG_FILE && success || failure
        su - oracle -c "lsnrctl start" >> $LOG_FILE && success || failure
        echo
        echo "----------------------------------------------------" >> $LOG_FILE
        date +"! %T %a %D : Finished." >> $LOG_FILE
        echo "----------------------------------------------------" >> $LOG_FILE
        touch /var/lock/subsys/dbora
        ps -e | grep tnslsnr | awk '{print $1;}' > $PID_FILE
        status
        ;;
  status)
        status
        ;;
  *)
        echo "Usage: dbora {start|stop|restart|status}"
        exit 1
esac

You can also download and try this script yourself… script link