Oracle MVA

Tales from a Jack of all trades

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

8 Responses

Subscribe to comments with RSS.

  1. Jacco,
    Nice example, thanx for the post it will save me some time to write it myself.

    You probebly know of the following option but i thought it would be advisable to add it to the posting for security reasons.

    you could elliminate the username and password from this script by storing them in a user configuration file or place them in a boot.properties file.

    This way the password is encrypted on the system.

    for the complete reference of these constructions

    http://download.oracle.com/docs/cd/E14571_01/web.1111/e13813/reference.htm#i1005916

    Vincent Kolmer

    July 8, 2010 at 12:40 pm

    • AFAIK there is no boot.properties for the nodemanager. You do really need a username / password or userConfigFile / userKeyFile. Please keep in mind that you can set the username and password for the nodemanager seperatly from the AdminServer. Also you cannot use an external provider (LDAP) for the account that starts the nodemanager (obviously you can use an LDAP provider for authentication in the AdminServer). If non-administrators (let’s say developers in a development / testing environment) need to start the nodemanager, you’re in trouble. For the AdminServer you can configure extra accounts (or a provider, e.g. to LDAP) with operator privileges. There is no reason to use admin privileges for that 😉

      IMO the userKeyFile and userConfigFile provide no extra security. To use them, you need to be able to read them. If you can read them, you can copy them. Therefore: no extra security as such (you can just as easily copy these files to an other machine). Sure a user doesn’t know the contents of the files, but this user doesn’t have to (the user can use the privileges of the account provided by these files). Sounds like a bogus solution to me 😉

      So in short: yes you have to really really really (ALWAYS) think about file security when you put a username and a password in a file. I do think this post was about the startup script itselve rather than about the file permissions on the script 😉

      Jacco H. Landlust

      July 8, 2010 at 5:45 pm

      • I do agree on your point here about the storing of user-name and password in an encrypted file on the local system, it is a farce in so many ways.

        In a lot of sites the security officer does not allow user-names and passwords in scripts but encrypted and stored on the local file system is often allowed…*DOH*…
        But hey, “that’s the way the cookie crumbles”

        And I stand corrected in regard of the boot.properties file.
        For the nodemanger this would be the userConfigFile or userKeyFile.
        _0_ my humble apologies.

        Vincent Kolmer

        July 9, 2010 at 12:48 pm

  2. Hi Jacco,

    I tried executing this script for my environment. But then i am getting the below error.

    java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Invalid node manager user name: Null or empty

    in line 7 i.e
    nmConnect(username, password, ‘localhost’, 5556, domain, domain_dir)

    Could you please guide me on this. Thanks in advance

    krishna

    August 30, 2010 at 10:06 pm

    • HI Krishna,

      Seems like the username is not replaced with the contents of the “username” variable. Could you try replacing the variable in the nmConnect function with a literal (e.g. ‘weblogic’).

      Jacco H. Landlust

      August 30, 2010 at 10:16 pm

  3. Hi Jacco,

    i have run the unix version of this script. The script was successfully started. But then after all the servers are started, if i go to Deployments -> all the components are in FAILED state.
    I could see the below errors in the adminserver log file
    <Failed to initialize the application 'ALSB Transform' due to error weblogic.management.DeploymentException: .
    weblogic.management.DeploymentException:

    Caused By: java.lang.ClassNotFoundException: com.bea.wli.sb.stages.StageAppListener

    <Failed to initialize the application 'ALSB Publish' due to error weblogic.management.DeploymentException: .
    weblogic.management.DeploymentException:

    Caused By: java.lang.ClassNotFoundException: com.bea.wli.sb.stages.StageAppListener

    Similarly i could find many classnotfound exceptions. I had passed the seWLSENV.sh while calling the WLST.

    source /opt/app/oracle/mw_home/user_projects/domains/osb_domain/bin/setDomainEnv.sh; java weblogic.WLST /opt/app/oracle/mw_home/user_projects/domains/osb_domain/tmp/${USER}.run.py

    Could you please help.

    krishna

    September 10, 2010 at 10:52 pm

  4. Hi Jacco,

    i tried debugging it furthur and then i connected directly to WLST and had run the below commands

    nmConnect(‘weblogic’,’welcome1′,’localhost’,’5556′,’osb_domain’,’/opt/app/oracle/mw_home/user_projects/domains/osb_domain’)
    And then
    nmStart(‘OSBAdminServer’)

    Even in that case it starts the server but deployments are in failed state. Is there any problem with the node manager configuration or some thing? I had changed the Node manager Properties file and enabled the below property as well

    StartScriptEnabled=true

    krishna

    September 10, 2010 at 11:19 pm

    • Obviously there is something wrong, but without looking at the logfiles I have no clue. Usually this has nothing to do with the nodemanager, path’s or missing libs are more likely.

      Sorry I can’t help you

      Jacco H. Landlust

      September 15, 2010 at 1:15 pm


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: