Using WLST in portal restart script

There's probably a variety of procedures that folks use for starting services for distributed applications. At one of our current clients, we have a central Windows batch file that restarts the various portal components that are deployed across several Windows servers. The portal services were being restarted using the Service Controller command ('sc') to start each service on its respective server. For instance, Automation Server was started with something like this:

sc \automation_host_name start "ptautomationserver"

Using the Service Controller to restart services remotely works great for the components that are registered as Windows services. But, we did not have windows services corresponding to the managed weblogic instances that ran the portal web application. Yes, I could have gone the "King-Size Homer" way and used the Drinking Bird at the weblogic console, but that would likely lead to trouble.

So there may be other ways, but I decided to use WLST to restart our portal cluster within weblogic. For those not familiar with WLST, it's a command-line and scripting tool that provides some of the core functionality available in the Weblogic [web-based] Admin Console and Weblogic Configuration Wizard. For the task at-hand, we invoke WLST in scripted mode with a Jython script by adding the following lines in the windows file:

C:\oracle\wlserver_10.3\server\bin\setWLSEnv.cmd
java weblogic.WLST restartPortalCluster.py

And then added the following lines into the Jython (restartPortalCluster.py) file:
# INITIALIZE VARIABLES
waitTime = 10000
oracleHomeDir=c:\oracle
weblogicHomeDir=C:\oracle\wlserver_10.3
adminURL=t3://localhost:7001
usrConfigFile=D:\appsscriptsuserconfig.secure
usrKeyFile=D:\appsscriptsuserkey.secure
portalClusterName=PortalCluster
# CONNECT TO THE ADMIN SERVER
try:
connect(usrConfigFile,usrKeyFile, adminURL)
except ConnectionException,e:
print 'Unable to connect to admin server.'
exit()
# STOP THE PORTAL CLUSTER
shutdown(portalClusterName, 'Cluster', force='true')
# WAIT FOR SHUTDOWN (otherwise get an error that server cannot be started still in shutdown)
print "Now waiting to make sure the server did shutdown..."
java.lang.Thread.sleep(waitTime)
# START THE PORTAL CLUSTER
start(portalClusterName, 'Cluster', adminURL)
# end
exit()

Note: Regarding the user key file referenced above, this file can be generated by using the command-line WLST to connect the Weblogic Admin server with the connect() command and then invoking the storeUserConfig() command to create the key file. This eliminates the need for putting the plain-text user password in the Jython script.

That's it! Now, we don't have to mess with the Weblogic Console for restarts. There's a lot more capability that comes with WLST. In part, I'm considering improving the above script to get the status of the servers to ensure they are shutdown before restarting the cluster. As always, your feedback is always welcome.

thanks,
Vasanth

Comments

Subscribe to Our Newsletter

Stay In Touch