← all posts · java

WebLogic Scripting Tool

BEA's Jython-based scripting tool for automating WebLogic server administration — create domains, manage deployments, and handle disaster recovery without restarting.

05 Feb 2007 · 5 min read · Stephen Masters java

According to the BEA documentation, the WebLogic Scripting Tool is a command-line scripting interface that system administrators and operators use to monitor and manage WebLogic Server instances and domains. It allows you to write scripts in Jython that are able to connect to a running WebLogic domain and make modifications to the configuration with no need to restart anything. It can also be used for creating and modifying a domain in its offline mode. It comes as standard with WebLogic 9.2 and a version is available for 8.1. It is recommended and supported by BEA for automating WebLogic server administration. I am currently developing WLST scripts to improve the development and deployment process.

I see it as having the following potential benefits:

Streamlining development – As it can be executed from an Ant build and cause an application version to be undeployed and replaced with a new version on a running server, all without intervention. Improving deployments – Manual steps in a deployment are slow and unreliable. At some stage they are guaranteed to go wrong. The scripted nature of this means that a deployment can be tested against multiple environments and proven before going live. You know that the deployment method for production is the one that produced your test environments. Faster, more reliable disaster recovery – Scripts can be developed to handle a number of failures. i.e. If a database fails and needs to be run from a DR server, scripts can be written in advance to re-create all connection pools pointed at the DR location. This way, the disaster recovery process is fast and reliable. The person initiating the fail-over only needs to know where to find the appropriate scripts. They do not need to know the steps themselves. Monitoring – Scripts can be written (many already exist) to connect to the running server and monitor it. This can include things such as checking whether message queues are live, testing connection pools, monitoring the JVM heap and various other tasks. Useful links for getting started This page has only existed for a very short time, so I haven’t had much opportunity to develop my own content. However, there is already a lot of good documentation out there that would help someone get started with WLST. Here I present my bucket of links that I have found useful.

Source code

I have already written a number of WLST objects and scripts to make my life easier. I need to work on pulling them out into the web site in a manner that I’m happy with, but in the meantime if you are interested, please get in touch and I can send you what I have so far.

Update

A few folks have asked about getting hold of some example scripts. Unfortunately most of what I have written is for work, so it is tied to work environments and not mine to share. However, I have created some simple scripts for sharing, that cover scripting the creation of a domain. These are available as GitHub gists for creating WebLogic domains:

config.properties
gist · stephen-masters/589660 properties
123456789101112131415161718192021222324252627282930313233343536
bea_home=/path/to/bea
java_home=/path/to/bea/jdk160_18

domain_template=/path/to/bea/weblogic11/common/templates/domains/wls.jar

admin_server_name=my_admin_server
admin_url=t3\://myserver\:7001
admin_user=weblogic
admin_password=w3blogicpwd
admin_port=7001
admin_port_secure=7002
domain_name=my_domain

my_server_1_port=8001
my_server_2_port=8011

my_domain_log4j_file=/path/to/bea/user_projects/domains/my_domain/log4j.xml

# ----------------------------------------------------------------------
# Datasources
# ----------------------------------------------------------------------

my_ds_name=my_datasource
my_ds_targets=my_server_1,my_server_2
my_ds_jndi=my.datasource
my_ds_url=jdbc\:oracle\:thin\:@dbserver\:dbport\:dbname
my_ds_user=dbusername
my_ds_password=dbuserpassword

# ----------------------------------------------------------------------
# Applications
# ----------------------------------------------------------------------

my_app_name=my_app
my_app_targets=my_server_1
my_app_path=/path/to/my_app_1.0.ear
create_domain.py
gist · stephen-masters/589660 py
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
"""Stage 1 domain creation script.

Read a template domain and make some offline modifications to it to define admin server 
details and create some managed servers. A follow-up online phase is needed once the 
servers have been started up.
"""

execfile("wlst_util_offline.py")

#=======================================================================================
# Open a domain template. 
#=======================================================================================

print "Reading: " + domain_template
readTemplate(domain_template)

#=======================================================================================
# Configure the Administration Server.
#=======================================================================================

print "Moving to Server/AdminServer"
cd('Server/AdminServer')
print "Setting Name to: " + admin_server_name
set('Name', admin_server_name)
print "Setting ListenAddress to nothing."
set('ListenAddress', '')
print "Setting ListenPort to " + admin_port
set('ListenPort', int(admin_port))

create(admin_server_name, 'SSL')
cd('SSL/' + admin_server_name)
set('Enabled', 'True')
set('ListenPort', int(admin_port_secure))

#=======================================================================================
# Define the password for user weblogic. You must define the password before you 
# can write the domain.
#=======================================================================================

print "Admin password: " + admin_password

cd('/')
cd('Security/base_domain/User/weblogic')
cmo.setPassword(admin_password)

#=======================================================================================
# Set Options:
# - CreateStartMenu:  Enable creation of Start Menu shortcut.
# - ServerStartMode:  Set mode to development.
# - JavaHome:         Sets home directory for the JVM used when starting the server.
# - OverwriteDomain:  Overwrites domain, when saving, if one exists.
#=======================================================================================

setOption('CreateStartMenu', 'true')
setOption('ServerStartMode', 'prod')
setOption('JavaHome', bea_home + '/jdk160_18')
setOption('OverwriteDomain', 'true')

#=======================================================================================
# Write the domain and close the domain template.
#=======================================================================================

writeDomain(bea_home + '/user_projects/domains/' + domain_name)
closeTemplate()

#=======================================================================================
# Reopen the domain.
#=======================================================================================

readDomain(bea_home + '/user_projects/domains/' + domain_name)

print 'Creating managed servers...'

create_managed_server('my_server_1', my_server_1_port, '', my_domain_log4j_file)
create_managed_server('my_server_2', my_server_2_port, '', my_domain_log4j_file)

#=======================================================================================
# We're done with configuring the domain. Close the domain template.
#=======================================================================================

updateDomain()
closeDomain()
exit()
wlst_util_offline.py
gist · stephen-masters/589660 py
123456789101112131415161718192021222324252627282930313233343536373839
"""A collection of utility methods used in creating a domain.
"""

import os


def create_managed_server(server_name, port, listen_address, log4jfile):
    """Creates a managed server on the domain."""
    print 'Creating managed server: server_name=' + server_name \
        + ', port=' + str(port) \
        + ', listen_address=' + listen_address \
        + ', log4jfile=' + log4jfile
    cd('/')
    create(server_name, 'Server')
    cd('/Servers/' + server_name)
    set('ListenPort', int(port)) 
    set('ListenAddress', listen_address)
    set('Machine', get_machine_name())
    create(server_name, 'ServerStart')


def get_machine_name():
    """Determines the physical machine name."""
    # HOSTNAME is usual on UNIX, but COMPUTERNAME is the Windows location.
    if os.environ.has_key('HOSTNAME'):
        return os.getenv('HOSTNAME')
    elif os.environ.has_key('COMPUTERNAME'):
        return os.getenv('COMPUTERNAME')
    else:
        return 'UNKNOWN'

    
def create_machine(machineName):
    """Creates a 'machine' on the domain against which servers can be allocated.

    This is only used in clustered environments.
    """
    cd('/')
    create(machineName, 'Machine')

SM
Stephen Masters

Software developer and architect. I build systems for places that move energy, commodities, and money around. I keep a bike-packing journal at velostevie.com.