How to restart managed servers simultaneously with WLST?

Datum:

31 januari 2015

Categorie:

Managed Services

In the Weblogic console it’s very easy to restart several managed servers at the same time. But I prefer to restart servers by command line interface. It’s quicker and safer.

1. Introduction

A WLST script could be like this:

[code lang=”js”]
connect(user, password, server)shutdown(‘myServer1’ , ‘Server’)

start(‘myServer1’ , ‘Server’)

shutdown(‘myServer2’ , ‘Server’)

start(‘myServer2’ , ‘Server’)
[/code]

The disadvantage of this script is that you have to wait till each step has been completed before the next step could be executed. So, if you have 4 servers in your domain, it could be 15 minutes to execute a script like this.

It is possible to start an entire cluster in parallel:

[code lang=”js”]start(‘myCluster’,’Cluster’)[/code]

But what if myserver1 and myserver2 are not in the same cluster? In test environments this could be plausible, if myServer1 is an OSB server and myServer2 an SOA server for instance. The ‘shutdown’ commands needs to be executed at the same time.

2. ServerLifeCycleRuntimeMBean

To execute the shutdown commands at the same the, you could use the ServerLifeCycleRuntimeMBean. This mbean provides methods to stop and start managed servers.

[code lang=”js”]domainRuntime()myServerLifeCycleRuntime = cmo.lookupServerLifeCycleRuntime(‘myServer1’)myServerLifeCycleRuntime.shutdown()[/code]

This script runs just a view seconds, it does not wait till the server is finished with shutting down. The method shutdown() returns a ServerLifeCycleTaskRuntimeMBean. This bean keeps track of the status of an task.

[code lang=”js”]
myServerLifeCycleRuntime = cmo.lookupServerLifeCycleRuntime(‘myServer1’)<strong>myShutdownTask = myServerLifeCycleRuntime.shutdown()</strong>

while myShutdownTask.getStatus() == ‘TASK IN PROGRESS’:

print “TASK IN PROGRESS”

java.lang.Thread.sleep(5000)

print “finished!!!!”
[/code]

The bold piece of the script does the magic. It creates a task reference of the shutdown process. And it checks every 5 seconds if the task status is still in ‘TASK IN PROGRESS’. If not, the task is completed.

3. Shutdown or start all servers simultaneously

Now the theory is clear, how to start all the managed servers simultaneously? Simple:

[code lang=”js”]tasks = []for server in cmo.getServerLifeCycleRuntimes():tasks.append(server.shutdown())[/code]

Create an array with all ‘server shutdown tasks’ And then check if al tasks are finished:

[code lang=”js”]
while len(tasks) > 0:for task in tasks:if task.getStatus() != ‘TASK IN PROGRESS’ :

tasks.remove(task)

java.lang.Thread.sleep(5000)
[/code]

Keep Looping through the taks array. If a status not is ‘TASK IN PROGRESS’ Then remove the task from the array. If the array is empty, all tasks are not in progress.

4. Limitations

To execute this script, the Admin services needs to be up and running. This script does not stop or start the Admin server.

5. Conclusion

Most (linux) Administrators prefer command line interface instead off clicking in a web gui. With this script you can: easily, fast and save start or shutdown a whole domain. Reference Oracle Fusion Middleware Oracle WebLogic Server MBean Javadoc

Appendix 1: Complete script

[code lang=”js”]

import sysdef stopAllManagedServers():
domainRuntime();

tasks = []

for server in cmo.getServerLifeCycleRuntimes():

if (server.getName() != ‘AdminServer’ and server.getState() != ‘SHUTDOWN’ ):

tasks.append(server.shutdown())

return tasks

def startAllManagedServers():

domainRuntime();

tasks = []

for server in cmo.getServerLifeCycleRuntimes():

if (server.getName() != ‘AdminServer’ and server.getState() != ‘RUNNING’ ):

tasks.append(server.start())

return tasks

def waitTillCompleted (tasks):

while len(tasks) > 0:

for task in tasks:

if task.getStatus() != ‘TASK IN PROGRESS’ :

tasks.remove(task)

java.lang.Thread.sleep(5000)

def showServerStatus ():

domainRuntime();

for server in cmo.getServerLifeCycleRuntimes():

print server.getName() + ‘ tt ‘ + server.getState()

connect(sys.argv[2], sys.argv[3], sys.argv[4]);

action = sys.argv[1]

tasks = []

if action == ‘start’:

tasks = startAllManagedServers()

elif action == ‘stop’:

tasks = stopAllManagedServers()

else:

print ‘usage: ‘ + sys.argv[0] + ‘ stop|start’

sys.exit()

waitTillCompleted (tasks)

showServerStatus ()

disconnect()

[/code]

Neem contact met op met Pieter voor meer informatie over WLST

Kunnen wij je helpen?

Neem contact op met Ebicus via het contactformulier of raadpleeg direct één van onze collega’s om je direct te ondersteunen!

Bekijk al onze blogs