Archive for January, 2007

WLST startServer re-visited

Monday, January 1st, 2007

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();