Oracle MVA

Tales from a Jack of all trades

Archive for July 2010

WLST: startup script for weblogic

with 8 comments

I needed a startup script for my weblogic environment. Somehow I couldn’t find any startup scripts on Google, which surprised me enormously. This resulted into me having to take my first babysteps into this WLST stuff. Documentation isn’t too clear to me (yet). Here’s what I have so far: 

# Function to get server state
def serverStatus(server):
  cd('/ServerLifeCycleRuntimes/' + server.getName() )
  return cmo.getState()
#
def startAdminserver():
  nmConnect(username, password, 'localhost', 5556, domain, domain_dir)
  nmStart('AdminServer')
  nmDisconnect()
# End of functions
#
# Set some constants
username = 'weblogic'
password = 'verySecretPassword'
localhost="wls1.area51.local"
domain = 'my_domain'
mwHome = '/u01/app/oracle/middleware'
#
# Derived constants
url = 't3://' + localhost + ':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
startNodeManager(NodeManagerHome=nmhome,PropertiesFile=nmpfile)
#
# Connect to the AdminServer
try:
  connect(username, password,url)
except:
  # Aiks: AdminServer is not running. Start it now and retry
  startAdminserver()
  connect(username, 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)
    machine = server.getListenAddress()
    print server.getName() + " is " + serverState + " on " + machine
    #
    # startup if needed
    if serverState == "SHUTDOWN":
      if machine == localhost:
        start(server.getName(),'Server')
        serverState = serverStatus(server)
        print "Now " + server.getName() + " is " + serverState + " on " + machine
disconnect()
exit()

The script can be started by setting your environment using the setDomainEnv.sh, which can be found in your domain_home/bin dirctory, and then call the script using

java weblogic.WLST startupScript.jy

Obviously the normal warnings apply: guarantees to the corner.

Advertisements

Written by Jacco H. Landlust

July 1, 2010 at 5:37 pm

Posted in Weblogic