Efficient Starting and Stopping of WebLogic Servers in Scripts

Introduction

When I first started writing scripts to start and stop WebLogic servers... ok, even after years of doing it... a fellow Oracle coworker tuned me in to trying a better approach. You see, initially I would start a server and then loop for a particular amount of time that I thought it would take for the server to be in the RUNNING state. This is problematic for a true automation process because the timing can potentially be off so subsequent processes can start before the servers are ready, or they may take a lot longer to start after servers have successfully reached the RUNNING state.

The Solution

Use the lwp-request (simple WWW user agent) command to make requests to our running server and check the returned response to see if the server is started or not. This command can be used to determine started and stopped states, depending on which action you are performing. A good practice is also to encapsulate the functionality into a shell function, within a script file of its own that can be sourced by multiple scripts. This way, any changes are only made in a single location and are realized throughout the scripting infrastructure.

Example Function Code


checkwls.sh

export SLEEPTIME=5

#Loop determining state of WLS
function check_wls {
    ACTION=$1
    while true
    do
        echo -e "***** Waiting for WebLogic server to get $ACTION *****"
        sleep $SLEEPTIME
        status=`lwp-request http://host01:7001 | grep "500 Can't connect"`
        if [ "$ACTION" == "started" ] && [ -z "$status" ]; then
            break
        elif [ "$ACTION" == "shutdown" ] && [ ! -z "$status" ]; then
            break
        fi
    done
    echo -e "\nWebLogic Server has $ACTION\n"
}


Example of Importing and Using the Function in Another Script


startAdmin.sh

source /practices/tune/bin/checkwls.sh

#Start AdminServer within a gnome terminal window
cd /u01/domains/tune/wlsadmin
gnome-terminal -t "AdminServer" -e "bash -c \"./startWebLogic.sh; exec bash;\""

#Wait and check for AdminServer to start using imported function
check_wls started

#For stopping the server use
check_wls stopped


Explanation and Summary

  1. The check_wls function uses the passed in action to determine if it is checking to see if the server has started or stopped. This is stored in the $ACTION variable.
  2. The function begins an infinite loop.
  3. The function sleeps for $SLEEPTIME (which is a hardcoded 5 seconds) to allow the server some time to reach its intended state.
  4. The server is called using lwp-request using the http://host01:7001 hardcoded URL. This can easily be a passed in variable to use the function for any server in a domain. The result of the lwp-request call piped into a grep call for an HTTP 500 connection error is captured in the $status variable.
  5. The $status variable is checked based on the intended action of starting or stopping the server. If $status is correct for that action, the function breaks the loop and returns control to the calling script.
  6. Using 5 second sleep intervals allows some time for processing, and also means that there will not be a long period of time between when the server is started and when the script recognizes it.
  7. The script recognizes the server's state using an actual call and response from the server so it is able to efficiently determine exactly when the next processing step is safe to execute.

Comments:

Mark, this is a nice and efficient piece of code to check the status. Thank you for the script.

Posted by guest on December 27, 2013 at 06:59 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About


Mark Lindros
Oracle FMW Curriculum Developer

Former BEA and Oracle TM Consultant, Support Engineer, and internal Staff Engineer

I have been in the IT industry since 1994, fulfilling various roles along the way. My entire career spans the enterprise application space. I started as a Tuxedo specialist, and later changed my focus to Java EE and WebLogic Server. I have extensive field experience implementing solutions using multiple Oracle FMW products.

When I'm not stuck behind my desk unraveling technology, I can be found enjoying my family, working out, playing video games, mountain biking, and enjoying life.

This blog is for posting interesting technical findings I make while using Oracle FMW products.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today