Startup or Shutdown of multiple WebLogic Managed Servers via WLST script
Posted by Dirk Nachbar on Wednesday, August 15, 2012 with 7 comments
Normally you will have multiple Managed Servers within one WebLogic Server Domain. The classical approach to startup or shutdown these multiple Managed Servers are:
Specially when you are trying to shutdown multiple Managed Servers within such a WLST script that uses the command shutdown(), if you hit such an error the WLST script will terminate and the potential following shutdown() commands for other Managed Servers will not be executed.
With below WLST script, you can avoid this problem and perform your startup or shutdown tasks in a more elegant way.
The WLST script is using a properties file, in my case named domain.properties which contains following:
The property serverlist is containing a comma seperated list of Managed Servers which you want to control.
The WLST script is moreover using an input value (start or stop). Before performing either the start() or the shutdown() command, the script will check for the MBean ServerRuntimeMBean if its existing or not for the given Managed Server.
Place the properties file domain.properties and the WLST script start_stop_managedservers.py in one directory, adjust the properties file to your landscape.
To call the WLST script start_stop_managedservers.py just source the required script setWLSEnv.[sh|cmd] out of your WLS_HOME/server/bin directory and then execute following command:
- using the WebLogic Server provided scripts startManagedWebLogic.[sh|cmd] and stopManagedWebLogic.[sh|cmd] in your Domain Directory
- using a WLST script with the command shutdown()
weblogic.server.ServerLifecycleException: Can not get to the relevant ServerRuntimeMBean for server DemoManaged
Specially when you are trying to shutdown multiple Managed Servers within such a WLST script that uses the command shutdown(), if you hit such an error the WLST script will terminate and the potential following shutdown() commands for other Managed Servers will not be executed.
With below WLST script, you can avoid this problem and perform your startup or shutdown tasks in a more elegant way.
The WLST script is using a properties file, in my case named domain.properties which contains following:
adminurl=t3://localhost:7001 adminusername=weblogic adminpassword=weblogic serverlist=DemoManaged,ManagedServer
The property serverlist is containing a comma seperated list of Managed Servers which you want to control.
The WLST script is moreover using an input value (start or stop). Before performing either the start() or the shutdown() command, the script will check for the MBean ServerRuntimeMBean if its existing or not for the given Managed Server.
import getopt # Load the properties file with all necessary values loadProperties('domain.properties') # Split the provided Server List String for the FOR LOOP in start and stop command serverlistSplit=String(serverlist).split(",") # Get the command, must be 'start' or 'stop' getcommand=sys.argv[1] # Check the provided command if getcommand != 'start' and getcommand != 'stop': print 'usage: <start stop="stop">' exit() # Connect to the Weblogic Admin Server # Connection Details are retrieved from properties file connect(adminusername, adminpassword, adminurl) # Change to the root of the MBean hierarchy domainRuntime() # Start Block if getcommand == 'start': # Loop over the splitted Server List string for s in serverlistSplit: # Is a ServerRuntime MBean existing for current Managed Server? # If yes, the current Managed Server is already running and we dont need to do anything bean = getMBean('ServerRuntimes/' + s) if bean: print 'Server ' + s + ' is ' + bean.getState() else: start(s, 'Server', block='false') print 'Started Server ' + s # Stop Block if getcommand == 'stop': # Loop over the splitted Server List string for s in serverlistSplit: # Is a ServerRuntime MBean existing for current Managed Server? # If no, the current Managed Server is already down and we dont need to do anything bean = getMBean('ServerRuntimes/' + s) if bean: shutdown(s, 'Server') print 'Stopped Server ' + s else: print 'Server ' + s + ' is not running' disconnect() exit()
Place the properties file domain.properties and the WLST script start_stop_managedservers.py in one directory, adjust the properties file to your landscape.
To call the WLST script start_stop_managedservers.py just source the required script setWLSEnv.[sh|cmd] out of your WLS_HOME/server/bin directory and then execute following command:
java weblogic.WLST start_stop_managedservers.py [start|stop]
Categories: Oracle WebLogic Server
Cameron Laird shared an interesting alternative:
ReplyDeleteContrast this with
...
def startAction(bean, s):
# If yes, the current Managed Server is already running and we need do nothing more.
if bean:
print 'Server ' + s + ' is ' + bean.getState()
else:
start(s, 'Server', block='false')
print 'Started Server ' + s
def stopAction(bean, s):
# If no, the current Managed Server is already down and we need do nothing more.
if bean:
shutdown(s, 'Server')
print 'Stopped Server ' + s
else:
print 'Server ' + s + ' is not running'
action['start'] = startAction
action['stop'] = stopAction
# Loop over the splitted Server List string
for s in serverlistSplit:
# Does the current Managed Server have a corresponding
# ServerRuntime MBean?
action[getcommand](getMBean('ServerRuntimes/' + s), s)
http://bit.ly/ROgfZa
Hi Thomas,
ReplyDeletethanks for the comment, its really an interesting refactoring.
Cheers
Dirk
Hi,
ReplyDeleteIs the above script is suitable for Linux machine? We are using the weblogic in linux through SSH. I would like to stop all the managed servers in a Weblogic. With the help of above script is that possible!!!!
Hi,
ReplyDelete[root@RIS-LB83 bin]# java weblogic.WLST start_stop_managedservers.py stop
-bash: java: command not found
[root@RIS-LB83 bin]#
When ever i tried to stop the servers. it getting the above error as command not found
You can also modify the .py script to invoke start with block='true' parameter to make the start order be deterministic, e.g., to enforce inter-server dependencies or to prevent the database server from being overwhelmed by multiple servers building their connection pools at the same time.
ReplyDeleteHi,
ReplyDeleteCan we start and stop Admin server and Nodemanager by using same above script
startServer('demoServer','demoDomain','t3://localhost:8001','myweblogic','wlstdomain','c://mydomains/wlst','false', 60000,jvmArgs='-XX:MaxPermSize=75m, -Xmx512m, -XX:+UseParallelGC')
help('startNodeManager') Start Node Manager.
Hi Dirk, Nice & simple script to start and stop the servers. Can you please help, I am stuck. How can I modify this script to connect to multiple domains/adminURL and start the cluster in that domain. Have to start one cluster in each domain and cluster name is different in each domain. Thanks, Harish
ReplyDelete