Home > Weblogic > Weblogic Domain Startup and Status check WLST scripts

Weblogic Domain Startup and Status check WLST scripts

Below are two scripts that need minimal modification in order to start all servers in a Weblogic domain (including admin server) and check the status of all servers in a domain, respectively.

The status_wls.jy script will connect to the AdminServer and return the status of all managed servers in the domain. It can be ran on any machine hosting at least one managed server in the domain. The scripts needs no other modification than the administrator username (usually weblogic user), password and admin server URL.

def serverStatus(server):
cd('/ServerLifeCycleRuntimes/' + server.getName() )
return cmo.getState()
#
username = 'weblogic'
password = 'weblogic'
URL='t3://admin.radu.ro:7001'
redirect('/scripts/logs/startWLS.log');
try:
connect(username,password,URL)
except:
print 'AdminServer is not running. Please start AdminServer on host omega-adm-02 in order to check the state of the servers in this domain'
print 'You can use the local /scripts/start_wls.sh to start all Weblogic servers on this host including the AdminServer or the /home/oracle/bin/startOSBAdmin.sh on omega-adm-02 to start the AdminServer only'
exit()
servers = cmo.getServers()
domainRuntime()
print '#### Weblogic Domain Status ####'
for server in servers:
serverState = serverStatus(server)
print 'Server ' + str(server.getName()) + ' is ' + serverState # + ' on ' + str(machine.getName())
print '################################'
disconnect()
stopRedirect()
exit()


The start_wls.jy script should be ran on a machine that hosts at least one managed server in the domain. Firstly it will check the Node Manager on that machine and start it if not already up. Then it will connect to the Admin Server of the domain, or start it if it’s not already up. Then it will loop through the managed servers in the domain and start the ones that are not already running and that are hosted by this machine.

  # Function to get server state
def serverStatus(server):
  cd(‘/ServerLifeCycleRuntimes/’ + server.getName() )
  return cmo.getState()
#
def startAdminserver():
  nmStart(‘AdminServer’)
  nmDisconnect()
#
def startNM():
  startNodeManager(NodeManagerHome=nmhome,PropertiesFile=nmpfile, verbose=false)
  nmConnect(‘weblogic’,password,hostname,’5556′,domain,domain_dir,’plain’)
# End of functions
#
# Set some constants
redirect(‘/scripts/logs/startWLS.log’);
username = ‘weblogic’
password = ‘weblogic’
domain = ‘WLSDomain’
hostname= ‘localhost’
mwHome = ‘/home/oracle/bea’
admin = ‘admin.radu.ro’
#
# Derived constants
url = ‘t3://’ + admin + ‘:7001’
domain_dir = mwHome + ‘/user_projects/domains/’ + domain
nmhome = mwHome + ‘/wlserver_10.3/common/nodemanager’
nmpfile = mwHome + ‘/wlserver_10.3/common/nodemanager/nodemanager.properties’
#
# Start the nodemanager if not running
try:
 nmConnect(username,password,hostname,’5556′,domain,domain_dir,’plain’)
except:
 print “Node Manager is not running. Starting Node Manager and retrying to connect…”
 startNodeManager(NodeManagerHome=nmhome,PropertiesFile=nmpfile, verbose=false)
#Connect to the AdminServer
try:
  connect(‘weblogic’,password,url)
except:
  # Aiks: AdminServer is not running. Start it now and retry
  print “Unable to connect to AdminServer, server not running. Please see ./log/startWLS.log for complete error”
  startAdminserver()
  connect(‘weblogic’,password,url)
#
# Loop through the managed servers and start all servers running on localhost
svrs = cmo.getServers()
domainRuntime()
for server in svrs:
  # Do not start the adminserver, it’s already running
  if server.getName() != ‘AdminServer’:
    # Get state and machine
    serverState = serverStatus(server)
    serverConfig()
    machine = server.getMachine();
    print server.getName() + ” is ” + serverState + ” on ” + machine.getName()
    domainRuntime()
    # startup if needed
    if serverState != “RUNNING”:
      if machine.getName() == hostname:
        try:
         start(server.getName(),’Server’)
         serverState = serverStatus(server)
         print “Now ” + server.getName() + ” is ” + serverState + ” on ” + machine.getName()
        except:  
         print “Unable to start server ” + server.getName() + “. Please consult the server’s log file: ”
         print ” ” + domain_dir + “/servers/” + server.getName() + “/logs/” + server.getName() + “.out”
disconnect()
stopRedirect()
exit()

To execute each script, you first need to set your environment by running the $MW_HOME/wlserver_10.3/server/bin/setWLSEnv.sh script and then run java weblogic.WLST status.jy. This can also be put in an executable script:

For example: startWLSDomain.sh

cd /home/oracle/bea/wlserver_10.3/server/bin/
. ./setWLSEnv.sh >> /dev/null
java weblogic.WLST /home/oracle/bea/wlserver_10.3/server/bin/startWLS.jy
exit

Advertisements
  1. July 13, 2012 at 9:46 am

    Hi,

    Thanks for the awesome scripts. just few additions incase of using custom trust and security certificates.

    in status.jy : the protocol used should be t3s
    URL = ‘t3s://localhost:7001’

    also the command to initiate the WLST session in status.sh shell script should be

    java -Dweblogic.security.SSL.ignoreHostnameVerification=true -Dweblogic.security.TrustKeyStore=CustomTrust -Dweblogic.security.CustomTrustKeyStoreFileName=/path-to-trust-certificate-file -Dweblogic.security.CustomTrustKeyStoreType=JKS -Dweblogic.security.CustomTrustKeyStorePassPhrase=
    weblogic.WLST status.jy

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: