#!/bin/bash # # chkconfig: 2345 80 05 # Description: This script is responsible for taking care of configuring the Oracle Database and its associated services. # # processname: oracledb_ORCL-19c # # Set path if path not set case $PATH in "") PATH=/bin:/usr/bin:/sbin:/etc export PATH ;; esac # Check if the root user is running this script if [ $(id -u) != "0" ] then echo "You must be root user to run the configurations script. Login as root user and try again." exit 1 fi # Setting the required environment variables export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1 export ORACLE_SID=orcl export LISTENER_NAME=LISTENER2 # General exports and vars export PATH=$ORACLE_HOME/bin:$PATH LSNR=$ORACLE_HOME/bin/lsnrctl SQLPLUS=$ORACLE_HOME/bin/sqlplus ORACLE_OWNER=oracle RETVAL=0 RETVAL1=0 # Commands SU=`which su` GREP=`which grep` EGREP=`which egrep` # To start the DB start() { # Check if the DB is already started pmon=`ps -ef | $EGREP pmon_$ORACLE_SID'\>' | $GREP -v grep` if [ "$pmon" = "" ]; then # Unset the proxy env vars before calling sqlplus unset_proxy_vars echo "Starting Oracle Net Listener." $SU -s /bin/bash $ORACLE_OWNER -c "$LSNR start $LISTENER_NAME" RETVAL=$? if [ $RETVAL -eq 0 ] then echo "Oracle Net Listener started." fi echo "Starting Oracle Database instance $ORACLE_SID." $SU -s /bin/bash $ORACLE_OWNER -c "$SQLPLUS -s /nolog << EOF connect / as sysdba startup exit; EOF" RETVAL1=$? if [ $RETVAL1 -eq 0 ] then echo "Oracle Database instance $ORACLE_SID started." fi else echo "The Oracle Database instance $ORACLE_SID is already started." exit 0 fi echo if [ $RETVAL -eq 0 ] && [ $RETVAL1 -eq 0 ] then return 0 else echo "Failed to start Oracle Net Listener using $ORACLE_HOME/bin/tnslsnr and Oracle Database using $ORACLE_HOME/bin/sqlplus." exit 1 fi } # To stop the DB stop() { # Check if the DB is already stopped pmon=`ps -ef | $EGREP pmon_$ORACLE_SID'\>' | $GREP -v grep` if [ "$pmon" = "" ] then echo "Oracle Database instance $ORACLE_SID is already stopped." exit 1 else # Unset the proxy env vars before calling sqlplus unset_proxy_vars echo "Shutting down Oracle Database instance $ORACLE_SID." $SU -s /bin/bash $ORACLE_OWNER -c "$SQLPLUS -s /nolog << EOF connect / as sysdba shutdown immediate exit; EOF" RETVAL=$? if [ $RETVAL -eq 0 ] then echo "Oracle Database instance $ORACLE_SID shut down." fi sleep 10s echo "Stopping Oracle Net Listener." $SU -s /bin/bash $ORACLE_OWNER -c "$LSNR stop $LISTENER_NAME" RETVAL1=$? if [ $RETVAL1 -eq 0 ] then echo "Oracle Net Listener stopped." fi fi echo if [ $RETVAL -eq 0 ] && [ $RETVAL1 -eq 0 ] then return 0 else echo "Failed to stop Oracle Net Listener using $ORACLE_HOME/bin/tnslsnr and Oracle Database using $ORACLE_HOME/bin/sqlplus." exit 1 fi } # Enh 27965939 - Unsets the proxy env variables unset_proxy_vars() { if [ "$http_proxy" != "" ] then unset http_proxy fi if [ "$HTTP_PROXY" != "" ] then unset HTTP_PROXY fi if [ "$https_proxy" != "" ] then unset https_proxy fi if [ "$HTTPS_PROXY" != "" ] then unset HTTPS_PROXY fi } restart() { # Check if the DB is already stopped pmon=`ps -ef | $EGREP pmon_$ORACLE_SID'\>' | $GREP -v grep` if [ "$pmon" = "" ] then start else stop start fi } case "$1" in start) start ;; stop) stop ;; restart) restart ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1 ;; esac exit 0