WLST startServer re-visited

From the past few months I have been working on a project to create a framework for our WebLogic application developers that can be used to easily build, configure and manage their WebLogic Servers. Needless to say the framework is built extensively with WLST.
After the WebLogic domain is configured we also provide infrastructure to manage their domain, mainly to start, stop, get the status of their domain and also to move their configuration from dev to uat and to production.
We use WLST’s startServer to start the Administration and Manager Server’s, although startServer does what we need but falls short in many ways. For example it does not provide a way to add PRE_CLASSPATH or POST_CLASSPATH to the Server’s classpath. Also it inherits the classpath from the JVM where WLST is invoked from which maynot be desirable in many situations.
Although startServer provides a way to redirect the server’s stdOut to a file, as soon as you exit the WLST client the redirection stops and there is no way to get WLST to redirect the server’s stdout/stderr to a file. With all these shortcomings I almost wish we could have an option in startServer command to use the startWebLogic.sh or startManagedWebLogic.sh script to start the Server. Since that option is not available I would like to share the workaround I used to get around the problem.
This workaround will use the startWebLogic.sh that is under the domain directory. The biggest advantage of making WLST to use a script is any custom extensions you have added to the script like the PRE_CLASSPATH/POST_CLASSPATH settings are preserved when you start the server, and also you can redirect the stdout/stderr to a file.

Copy the definitions below to your script and invoke the command’s by passing in the required arguments.

def startAdminServerViaScript(domainDirectory, adminServerName):
··· try:
······svrOutLoc = domainDirectory+”/servers/”+adminServerName+”/logs/”+adminServerName+”.out”
······os._shellEnv.system(domainDirectory+”/bin/startWebLogic.sh > “+svrOutLoc+” 2>&1 &\n”)
···except Exception,e:
······e.printStackTrace()
······raise “Error starting the admin server”

def startManagedServerViaScript(domainDirectory, managedServerName, adminUrl):
···try:
······svrOutLoc = domainDirectory+”/servers/”+managedServerName+”/logs/”+managedServerName+”_”+”.out”
······os._shellEnv.system(domainDirectory+”/bin/startManagedWebLogic.sh “+managedServerName+” “+adminUrl+” > “+svrOutLoc+” 2>&1 &\n”)
···except Exception,e:
······e.printStackTrace()
······raise “Error starting the weblogic server “+managedServerName

Both the functions will basically invoke the start scripts that are part of your domain from WLST. Note that both these functions work on Unix/Linux and if you are using windows make appropriate changes to call the right scripts.

_uacct = “UA-2684269-2″;
urchinTracker();

3 Responses to “WLST startServer re-visited”

  1. Jon says:

    Question for you Satya,

    Liked your post but am wondering how do you handle the node manager? I’m working with WebLogic 9.2 and am trying to come up with good scripts to start things up without having to use the admin console. So far, I am looking at starting things up using wlst which starts the node manager first and then starts the admin server and managed server(s).

    What I’m looking for is a way to supress output when I’m doing something like

    if not nm():
    print ‘not connected’

    I don’t want it to output the results of nm(), just the ‘not connected’

    Any ideas?

    Thanks,

    Jon McAlexander
    jonmcalexander@wellsfargo.com

  2. John says:

    Hi Satya,

    I am trying to call startWebLogic.cmd from wlst, I looke at your BLOG and tried the following command after lanching wlst:
    wls:/offline> import system
    wls:/offline> os.system('C:\juli\bea101\user_projects\domains\testwlst\startWebL
    ogic.cmd')

    I always got the error message:
    Traceback (innermost last):
    File "console", line 1, in ?
    File "Lib/javaos.py", line 198, in system
    File "Lib/javaos.py", line 224, in execute
    OSError: (0, 'Failed to execute command ([\'sh\', \'-c\', \'C:\\\\juli\\bea101\\
    \\user_projects\\\\domains\\testwlst\\\\startWebLogic.sh\']): java.io.IOExceptio
    n: CreateProcess: sh -c "C:\\juli\bea101\\user_projects\\domains\testwlst\\start
    WebLogic.sh" error=2')

    Do you have any idea what's going on?

    Thanks in advance!

    Juan Li
    lilly.jli@gmail.com

  3. Nikhil says:

    i was looking for a way to monitor managed servers in a cluster only before i deploy to the cluster. i.e step 1 : check if managed servers in cluster A are up step 2:deploy to cluster A

    i have seen scripts to check status for all managed server but not for specific ones in a cluster only

    Thanks
    Nikhil