Thursday, May 29, 2008

Making friends with WebLogic using WLST

We have been playing around with WebLogic for a few weeks now; but I have only recently watched a course on the Jython based web logic scripting langauge, WLST, that you can use to automate common operations. It turns out that the setup for the tool take a few steps, so lets quickly define an alias that starts the tool with the right environment.

alias wlst '/bin/sh -c "source $WL_HOME/server/bin/; java -Dpython.cachedir=/tmp/wlst weblogic.WLST \!*"'

You can run WSLT in interactive or scripting mode, we are going to focus on script mode for the moment though. You will tend to use the interactive mode to debug your scripts. All the examples here can be simply placed in a .py file and passed as a parameter to wlst.

The first thing I wanted to do is the automate setting the HTTP/Tunneling preference which is required to enable deployment from within JDeveloper. Since we get new builds quite often I wanted a quick workaround. You can do this with the server running, and the commands are slightly different, but I went with off-line modification of configuration files.

cd ('Server/AdminServer')
set ('TunnelingEnabled', true)

Now the server is properly configured you will probably want to start it. There is a script to do this but I figured would be interesting to do this using a WLST:

startServer('AdminServer', 'base_domain', 't3://localhost:7001', 'weblogic', 'weblogic', '/ade/gdavison_wls/wls10/beahome/user_projects/domains/base_domain', 'true')

And of course you might want to shut it down later. Since the AdminServer is the default local connection as I am not worried about clusters for the moment we can connection with the default connection information and force a server shutdown.


Of course this has just scratched the surface of what you can do with this tool. The jython underpinning makes it really easy to do powerful things. For example this blog entry shows how to automate setting up a cluster. You can also impressively record operation when using web console and later use them in scripts to configure another server.


Harris said...

Thanks for this information on how to shutdown using WLST. Nothing else I found (even on BEA site) worked.

Gerard Davison said...

No problem!