weblogicwlst

How to start and stop multiple weblogic managed servers at one go through WLST


I am writing a code to start , stop, undeploy and deploy my application on weblogc.

My components need to be deployed on few managed servers.

When I do new deployments manually I can start and stop the servers in parallel, by ticking multiple boxes and selecting start and stop from the dop down. See below. enter image description here

but when trying from WLST, i could do that in one server at a time.

ex:

start(name='ServerX',type='Server',block='true')
start(name='ServerY',type='Server',block='true')

shutdown(name='ServerX',entityType='Server',ignoreSessions='true',timeOut=600,force='true',block='true')
shutdown(name='ServerY',entityType='Server',ignoreSessions='true',timeOut=600,force='true',block='true')

Is there a way I can start stop multiple servers in once command?


Solution

  • Instead of directly starting and stopping servers, you create tasks, then wait for them to complete.

    e.g.

    tasks = []
    for server in cmo.getServerLifeCycleRuntimes():
        # to shut down all servers
        if (server.getName() != ‘AdminServer’ and server.getState() != ‘RUNNING’ ):
            tasks.append(server.start())
        #or to start them up:
        #if (server.getName() != ‘AdminServer’ and server.getState() != ‘SHUTDOWN’ ):
        #   tasks.append(server.shutdown())
    
    
    #wait for tasks to complete
    while len(tasks) > 0:
        for task in tasks:
            if task.getStatus()  != ‘TASK IN PROGRESS’ :
                tasks.remove(task)
    
        java.lang.Thread.sleep(5000)