Tuesday, November 30, 2010

Script for Bouncing a WebLogic instance

In the last post I was made deeper research on getting the process id of all WebLogic instances with a script. After looking to that script, My asked me 'Why don't you try for a script for bouncing a WebLogic instance?'. I thought that's really good idea, this makes WebLogic Admin life more easier, which is very much need for every WebLogic Admin. Let me get all the clues before putting the logic into the script.

The bounce script will take the input as WebLogic instance name.
Then the script should do search for the corresponding Java Process id of given WebLogic instance.
That Java Process ID can be used for finding:
1. Thread dump
2. Domain directory
3. Shutdown instance (kill the process)

Above 1, 3 are commonly used commands but 2nd one required when situation like this, on the same machine if there exists multiple WebLogic domain instances then how to find the WebLogic instance started from? Here, I need to find the origin directory of startManagedWebLogic.sh used which gives the WebLogic domain directory. How to resolve this? The solution is pwdx command in Solaris gives you this directory path by passing process id to it.

This solution gives me to start the WebLogic instance which is residing in irrespective WebLogic domain. That's all I need to make the bounce script.

The bounce script goes like this
# This script you can keep in common accessing PATH
# such as in $JAVA_HOME/bin
# For WebLogic instance take ThreadDump, Shutdown, and Start
if [ "$1" = "" ]; then
        echo "Usage : $0 [instance]"
        pid=`jps -v|grep $instance|awk '{print $1}'`
        echo 'pid ' $pid
        domainPath=` pwdx $pid |awk '{print $2}'`
        kill -3 $pid
        sleep 3
        kill -3 $pid
        sleep 3
        kill -3 $pid

 #Now shutting down the instance here
        kill -9 $pid

 #verifying the instance is existance if not wait
        while : 
                jps -v |grep $instance
                if [ $? -eq 1 ]; then
                        echo 'kill success'
                        flag=`expr $flag + 1`
                        echo 'kill failed... sleeping 1 sec'
                        sleep 1

 #Once kill is success then you can proceed for Start it
 # Here you can call startManagedWebLogic.sh script
        if [ $flag -gt 0 ]; then
                . ${domainPath}/startinstance.sh $instance

Recently one of my blog ->pingbox user asked me about pwdx command, does it works on HP-UX? I thought I should update this post with proper references.
There is compatibility list given for pwdx command:
pwdx compatibility

Alternate solution is cwd for Linux.
Please suggest your ideas, Keep commenting

Blurb about this blog

Blurb about this blog

Essential Middleware Administration takes in-depth look at the fundamental relationship between Middleware and Operating Environment such as Solaris or Linux, HP-UX. Scope of this blog is associated with beginner or an experienced Middleware Team members, Middleware developer, Middleware Architects, you will be able to apply any of these automation scripts which are takeaways, because they are generalized it is like ready to use. Most of the experimented scripts are implemented in production environments.
You have any ideas for Contributing to a Middleware Admin? mail to me wlatechtrainer@gmail.com