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
#===========================================================
flag=0
if [ "$1" = "" ]; then
        echo "Usage : $0 [instance]"
        exit
else
        instance="$1"
        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 : 
        do 
                jps -v |grep $instance
                if [ $? -eq 1 ]; then
                        echo 'kill success'
                        flag=`expr $flag + 1`
                        break;
                else 
                        echo 'kill failed... sleeping 1 sec'
                        sleep 1
                fi 
        done 

 #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
        fi
fi

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

12 comments:

  1. Good Script

    It Helps me a lot for My Jboss server Automation scripts.
    I really thank full for you for sharing Your Knowledge and to think us about these technologies!
    :)

    ReplyDelete
  2. Can we use this script to restart an instance which is tied to a nodemanager. Doesn't nodemanager keep track of the instance and try to restart it as soon as the script kills it?

    ReplyDelete
  3. This script is not for who have NodeManager in their environment. If you have NodeManager you can use WLST to bounce the instance.

    ReplyDelete
  4. kill -3 doesnot work on GNU/Linux.. any ideas?

    ReplyDelete
  5. That command works in GNU/Linux also... if not try kill -QUIT . But the output will be generated in the standard out. If the server is running in background you can check the redirecting log file have the threadDump. other option is jstack .

    ReplyDelete
  6. I am facing a problem. Once the script reaches the line kill -9 $pid
    it kills the server process and stops executing further. What could I be missing? I have tried entering an echo statement right below the kill -9 $pid to see if it goes beyond that point but no luck.
    I am using x86_64 x86_64 x86_64 GNU/Linux

    ReplyDelete
  7. Did you check pwdx working in ur Linux machine? if not use cwd.

    ReplyDelete
  8. i want to understanded about thread dump & heep dump concet in weblogic 11g (10.3.3)

    ReplyDelete
  9. hi this is das i want the some regular use commands for weblogic in linux

    ReplyDelete
  10. How Can you kill JVM processes? How about running, and not finished threads? There are other ways to stop Admin Server and other managed servers...

    ReplyDelete
  11. Monitor: WebSolutionsWeblogicProd:S&P-PROD-NJ09- Web Solutions-Webogic_ws_4-nj09mhf0459.edmz:22440-url-
    Group: Web Solutions-Weblogic-Prod
    Status: timed out reading

    Hi I am getting above error everyday or two.
    May i know the issue here for timed out.
    Not able to find anything in logs.
    Jus servlet exception and javax.servlet.jsp.JspException: Broken pipe

    Can you share a script when this issue comes it should auotmatically restart that instance.

    Naveen N
    navin.wls6@gmail.com

    ReplyDelete
  12. Monitor: WebSolutionsWeblogicProd:S&P-PROD-NJ09- Web Solutions-Webogic_ws_4-nj09mhf0459.edmz:22440-url-
    Group: Web Solutions-Weblogic-Prod
    Status: timed out reading

    Hi I am getting above error everyday or two.
    May i know the issue here for timed out.
    Not able to find anything in logs.
    Jus servlet exception and javax.servlet.jsp.JspException: Broken pipe

    Can you share a script when this issue comes it should auotmatically restart that instance.

    Naveen N
    navin.wls6@gmail.com

    ReplyDelete

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
QK7QN6U9ZST6