A useful addition to Ant build scripts for projects in 10g was the ability to restart servers after deploying code (see http://corecontentonly.com/2011/01/03/jdeveloper-ant-magic/). With 11g however, this approach no longer works as UCM now lives under WebLogic, so it’s no longer a straightforward service stop/start.
WLST to the rescue
In 11g servers are stopped and started via the WebLogic admin console. The WebLogic Scripting Tool (WLST) lets you write Jython scripts to perform much of the wizardry that the WebLogic admin console allows. Using the WLST API I’ve written a restart script that takes the server name as the argument and does all the logging in, stopping and starting for you. I’ve also managed to integrate this with our Ant build scripts via the ‘plink’ program (part of the PuTTY suite of tools) so that servers are restarted right after a project build from JDeveloper.
A few caveats
- This post assumes that you already have an Ant build script set up to deploy your class files to the server.
- Security should be considered when using this approach as the WLST script contains the WebLogic user credentials and the Ant script contains Linux user credentials.
The step by step
Right! Now you’ve heard the blurb it’s time to get down to it, so here goes:
- Add the following WLST script to the server that WebLogic resides on. In this case we have just stored it in the WebLogic Linux user’s home directory as ucm_restart.py (You’ll see this later in the Ant script as ‘/home/weblogic/ucm_restart.py’).
# The name of the server to restart should be passed as a parameter.
nmConnect('weblogic', 'YourWeblogicPassword', domainName='ucm_domain')
connected = 1
print('Could not connect to the NodeManager.')
server = sys.argv
print('Current server status: ')
print('Server startup has been initiated by another process.')
- Next you’ll need ‘plink.exe’ to execute the script remotely. Plink can be obtained from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html. In this example I’ve saved it to a shared location “\sharePuTTYplink.exe”.
- Modify the build.xml of your project to execute the plink command by adding the following target: (change paths according to your setup):
<arg value="[email protected]"/>
<arg value="java -cp '/d01/oracle/Middleware/wlserver_10.3/server/lib/weblogic.jar' weblogic.WLST /home/weblogic/ucm_restart.py UCM_server1"/>
Notice the parameter to the script ‘UCM_server1’. Substitute this with the name of the server instance you wish to restart and you’re good to go!
What the plinking heck am I using plink for?!
It is possible to use WLST directly from Ant (see ‘Running WLST from Ant’ on http://download.oracle.com/docs/cd/E12840_01/wls/docs103/config_scripting/using_WLST.html) although I found it difficult to get working. There was a lot of faffing with class paths just to get it to run, and then when it finally did it would fail to connect to the node manager. I also found that it took about 1 and a half minutes before Ant even started the WLST script whereas with plink it was pretty much instantaneous so I’ve abandoned this approach for now (though if anyone has any pointers on getting this to work please do leave a comment below as I would prefer not to have to use plink.)
Posted in: hints & tips, technical
This entry was posted on Tuesday, August 30th, 2011 at 12:14 pm