Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
"""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()
"""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')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.