Why we needWebLogic Server State? What all those states?
![]() |
WebLogic Server Life cycle state diagram |
- We are collecting all the list of servers present in the WebLogic domain
- state function applied on each server as item passed to it
- repeat this step 2 until all server list ends
wls:/demodomain/serverConfig> x=ls('Servers',returnMap='true') dr-- demoadm dr-- demoms1 dr-- demoms2 wls:/demodomain/serverConfig> x [demoadm, demoms1, demoms2] wls:/demodomain/serverConfig> for i in x: ... state(i,'Server') ... Current state of "demoadm" : RUNNING Current state of "demoms1" : SHUTDOWN Current state of "demoms2" : SHUTDOWNCluster listing
wls:/demodomain/serverConfig> c=ls('Clusters',returnMap='true') dr-- clstr01 wls:/demodomain/serverConfig> c [clstr01] wls:/demodomain/serverConfig> state(c[0],'Cluster') There are 2 server(s) in cluster: clstr01 States of the servers are demoms1---SHUTDOWN demoms2---SHUTDOWN
![]() |
ServerLIfecycleRuntime Mbean tree |
Using above shown MBean hierarchy we can fetch the all WebLogic domain server instance's states. If your production WebLogic domain consists of two digit (eg. 60 instances) or three digit number (eg. 120 instances) of managed server then, it is difficult to see all server’s state at once. Weblogic Administration console is unable to show all the servers in the domain on a single page. Navigating in between also a time eating process so think! think better way!! WLST has the solution.
To get the status of all servers in the domain can be obtained with the following steps
- Connect to the WebLogic Admin Server
- Fetch the Managed server list from the domainRuntime MBean
- Iterate the loop and get the state of each Managed Server with ServerLifeCycle Runtime MBean
- Repeat if required the step 3 as per the user input to Continue...
- Finally if all desired output is visible then disconnect from the AdminServer and exit.
################################################## # This script is used to check the status of all WL instances including the admin ########################################################### def conn(): UCF='/path/.AdminScripts/userConfigFile.sec' UKF='/path/.AdminScripts/userKeyFile.sec' admurl = "t3://hostname:wlport" try: connect(userConfigFile=UCF, userKeyFile=UKF, url=admurl) except ConnectionException,e: print '\033[1;31m Unable to find admin server...\033[0m' exit() def ServrState(): print 'Fetching state of every WebLogic instance' #Fetch the state of the every WebLogic instance for name in serverNames: cd("/ServerLifeCycleRuntimes/" + name.getName()) serverState = cmo.getState() if serverState == "RUNNING": print 'Server ' + name.getName() + ' is :\033[1;32m' + serverState + '\033[0m' elif serverState == "STARTING": print 'Server ' + name.getName() + ' is :\033[1;33m' + serverState + '\033[0m' elif serverState == "UNKNOWN": print 'Server ' + name.getName() + ' is :\033[1;34m' + serverState + '\033[0m' else: print 'Server ' + name.getName() + ' is :\033[1;31m' + serverState + '\033[0m' quit() def quit(): print '\033[1;35mRe-Run the script HIT any key..\033[0m' Ans = raw_input("Are you sure Quit from WLST... (y/n)") if (Ans == 'y'): disconnect() stopRedirect() exit() else: ServrState() if __name__== "main": redirect('./logs/Server.log', 'false') conn() serverNames = cmo.getServers() domainRuntime() ServrState()
Smart Script
- To get individual managed server status you need to pass arguments as managed server name, type as 'Server'.
- Other one is to get individual Cluster wise status.
Note: Hope you follow the WLST Tricks & tips
try: connect(url = "t3://adminhostname:adminport") except: print "Connection failed" state('appclstr','Cluster') state('web1clstr','Cluster') ... state('webNclstr','Cluster')
Server state with redirecting, re in WLST
Wang mailed me his situation clarity of explanation why he chosen state command. And how he resolved with Python script tricks here. Its a great learning for me so sharing with you when I saw same question in StackExchange today(28 April 2014) after 3 years!! "The reason I do not use (for now) domainConfig is because some how few Weblogic domains are not in a good state, and when I run the domainConfig command, it complains that it is not enabled. Hence the alternative way I've selected here is using state command. But it don't return the state. It always return None. But it prints out the state of the server. Here you go, Better way is capture that printing output to a file using WLST command redirect-stopRedirect and then, use the Python regular expression to extract the state of each server. The following is the Python snippet how I use the redirect:# Fill your own connection details serverlist=cmo.getServers() for s in serverlist: server_nm = s.getName() urldict[server_nm]='t3s://'+s.getListenAddress()+':'+str(s.getAdministrationPort()) #domainRuntime() #cd('ServerLifeCycleRuntimes/'+server_nm) fileName='/tmp/myserver_state.txt' redirect(fileName) state(server_nm,'Server') stopRedirect() f = open(fileName) try: for line in f.readlines(): if re.search('Current state',line): status[server_nm]=line except: continue Ks = status.keys() for s in Ks: if re.search('RUNNING',status[s]): try: connect(username,password,urldict[s]) except: continue cd("/Servers/" + s) ...best regards! Dianyuan Wang