Monday, 30 January 2017

Utility Scripts : Starting/Stopping Database or Tomcat

Usually we end up spending a lot of time trying to start/stop the instances and also in referring to the administration docs for the respective components. 
It is always advisable to create start/stop scripts that will make our work much easier. 

Below are the script I created for starting or stopping an instance

Save the files as db.sh and tomcat.sh and run then as $ sh <filename>.sh

Database- db.sh
https://github.com/sudhakarbetha/Utilities/blob/master/control/src/scripts/db.sh

 #This is a Utility for Database instance - start/stop

#Show Usage on Failure
function usage()
{
    echo "Usage:"
    echo "To start, run as $ sh db.sh start"
    echo "To stop, run as $ sh db.sh stop"
    exit 1
}

#Start DB
function start_db()
{
echo "Starting Database"
$ORACLE_HOME/bin/sqlplus 'sys/welcome1 as sysdba'  <<eof
startup
select name from v$services
alter pluggable database all open
quit
eof
}

#Stop DB
function stop_db()
{
echo "Stopping Database"
$ORACLE_HOME/bin/sqlplus 'sys/welcome1 as sysdba'  <<eof
shutdown immediate
quit
eof
}

#Main Program starts here
if [ $# == 0 ]
then
        usage
fi

ACTION=$1
export ORACLE_HOME=/scratch/sbetha/Database/product/12.1.0/dbhome_1
export ORACLE_SID=orcl
export LISTENER=$ORACLE_HOME/bin/lsnrctl

echo "ORACLE_HOME=$ORACLE_HOME"
echo "ORACLE_SID=$ORACLE_SID"

if [ "$ACTION" == "start" ]
 then
        start_db
   
        echo "Starting Listener - $LISTENER start"
        $LISTENER start
        echo "Getting Listener status - $LISTENER status"
        $LISTENER status


elif [ "$ACTION" == "stop" ]
 then
        stop_db
       
        echo "Getting Listener status - $LISTENER status"
        $LISTENER status
        echo "Stopping Listener - $LISTENER stop"
        $LISTENER stop
       
else
        echo "Unknown Operation $ACTION"
    usage
fi

echo "Done Action=$ACTION"




Tomcat - tomcat.sh 

https://github.com/sudhakarbetha/Utilities/blob/master/control/src/scripts/tomcat.sh


# Ths is a Utility to start/stop Tomcat

function usage()
{
    echo "Usage:"
    echo "To start, run as $ sh tomcat.sh start"
    echo "To stop, run as $ sh tomcat.sh stop"
    exit 1
}

if [ $# == 0 ]
then
    usage
fi

ACTION=$1
export JAVA_HOME="/scratch/sbetha/Shiphomes/Java/jdk7"
export CATALINA_HOME="/scratch/sbetha/Tomcat/tomcat_new"
export CATALINA_BASE="/scratch/sbetha/Tomcat/tomcat_new"
export JAVA_OPTIONS="-Xms1024M -Xmx4096M -XX:PermSize=1024M -XX:MaxPermSize=4096M"
if [ "$ACTION" == "start" ]
 then
    echo "$CATALINA_HOME/bin/startup.sh"
    $CATALINA_HOME/bin/startup.sh
elif [ "$ACTION" == "stop" ]
 then
    echo "$CATALINA_HOME/bin/shutdown.sh"
    $CATALINA_HOME/bin/shutdown.sh
else
    echo "Unknown Operation $ACTION"
    usage
fi
echo "Done Action=$ACTION"

No comments:

Post a Comment

Linux : Create a new user for the machine

Creating a new user in linux is sometimes needed, when you want to share the user access with anyone. SSH to the machine over the newly cre...