Ravish Mody

One of the users Hong from Oracle Technology Network was having difficulty in chaining the log setting for n number of servers in a domain using Admin console. Now the same things has to be done on say n number of domains so say if one has 10 servers in a 1 domain and has total 10 Domains then  in total he has to do the same changes for 100 servers which is very time consuming using Admin-consoles.

Thus came Middleware Magic Team to the rescue and we created a WLST script which would do the same using thing very easily and quickly without any tedious job. Just give the domain and there servers details in the domain.properties files and you are good to go.

Steps to Edit Server Log Configuration For Multiple Domains Using WLST

Step1). Create a Directory somewhere in your file system like : “C:WLST_log”

Step2). Write a Properties filedomain.properties inside “C:WLST_log” like following:


total.domain.count=2

###################
  Logging Options
###################
rotationType=bySize
numberOfFilesLimited=no
fileMinSize=3000
rotateLogOnStartup=no
fileCount=5

###################
 Domain-1 Details
###################
domain.1.name=Domain_7001
domain.1.admin.url=t3://10.10.10.10:7001
domain.1.admin.username=weblogic
domain.1.admin.password=weblogic

total.domain.1.server.count=2

domain.1.server.1.name=AdminServer
domain.1.server.2.name=MS-1

###################
 Domain-2 Details
###################
domain.2.name=Test_Domain
domain.2.admin.url=t3://20.20.20.20:7001
domain.2.admin.username=weblogic
domain.2.admin.password=weblogic

total.domain.2.server.count=2

domain.2.server.1.name=AdminServer
domain.2.server.2.name=MS-1

Step2). Now in the same directory write the following WLST Script “domainLogConfigurtionChange.py” like following:

Updated [03/10/2011]

Thanks to Vishal Mahajan who spotted few bugs in our previous script and helped us to fix them

#############################################################################
#
# @author Copyright (c) 2010 - 2011 by Middleware Magic, All Rights Reserved.
#
#############################################################################

from java.io import FileInputStream

propInputStream = FileInputStream("domain.properties")
configProps = Properties()
configProps.load(propInputStream)

totalNumbersofDomains=configProps.get("total.domain.count")

rotationType=configProps.get("rotationType")
numberOfFilesLimited=configProps.get("numberOfFilesLimited")
fileMinSize=configProps.get("fileMinSize")
rotateLogOnStartup=configProps.get("rotateLogOnStartup")
fileCount=configProps.get("fileCount")

def str2bool(v):
	return v.lower() in ("yes", "true", "t", "1")

domainTmpCount=1
while (domainTmpCount <= int(totalNumbersofDomains)) :

	domainName = configProps.get("domain."+ str(domainTmpCount)+".name")
	domainAdminUrl = configProps.get("domain."+ str(domainTmpCount)+".admin.url")
	domainAdminUserName = configProps.get("domain."+ str(domainTmpCount)+".admin.username")
	domainAdminPassword = configProps.get("domain."+ str(domainTmpCount)+".admin.password")
	serverCount = configProps.get("total.domain."+ str(domainTmpCount)+".server.count")

	connect(domainAdminUserName, domainAdminPassword, domainAdminUrl)
	print '##################################################'
	print 'Changing Log Settings For Domain: ', domainName
	print '##################################################'

	serverTmpCount=1
	edit()
	while (serverTmpCount <= int(serverCount)) :
		startEdit()
		currentServerName = configProps.get("domain."+ str(domainTmpCount)+".server."+ str(serverTmpCount)+".name")
		print '----------------------------------------------------'
		print 'Changing Log Setting for serverName: ' , currentServerName
		print '----------------------------------------------------'
		cd('/Servers/' + currentServerName + '/Log/' + currentServerName)
		cmo.setRotationType(rotationType)
		cmo.setNumberOfFilesLimited(str2bool(numberOfFilesLimited))
		cmo.setFileMinSize(int(fileMinSize))
		cmo.setRotateLogOnStartup(str2bool(rotateLogOnStartup))
		cmo.setFileCount(int(fileCount))
		cmo.setFileName('logs/' + currentServerName + '.log')
		activate()
		print '===> Log Setting for serverName: ' , currentServerName, ' has been changed Succeefully !!'
		print ''
		serverTmpCount = serverTmpCount +1
	print '***** Log Settings For Domain: ', domainName ,' has been changed Succeefully !! *****'
	print ''
	domainTmpCount = domainTmpCount +1

Step3). Now Open a Command/Shell Prompt and then run the “setWLSEnv.sh” script to set the CLASSPATH and PATH environment variables. Run the “. ./setWLSEnv.sh” by adding two DOTs separated by a single space …..before the actual script like following : (use ‘cd’ command to move inside the <BEA_HOME>/wlserver_10.3/server/bin) then run the following command….
. ./setWLSEnv.sh


Note: Here The first DOT represents that set the Environment in the current Shell, AND the second ./ represents execute the script from the current directory.

Step4). Run the Above WLST Script like following:

java weblogic.WLST domainLogConfigurtionChange.py

Following would be the Output

java weblogic.WLST domainLogConfigurtionChange.py

Initializing WebLogic Scripting Tool (WLST) ...

Jython scans all the jar files it can find at first startup. Depending on the system, this process may take a few minutes to complete, and WLST may not return a prompt right away.

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Connecting to t3://localhost:7001 with userid weblogic ...
Successfully connected to Admin Server 'AdminServer' that belongs to domain 'Domain_7001'.

Warning: An insecure protocol was used to connect to the
server. To ensure on-the-wire security, the SSL port or
Admin port should be used instead.

##################################################
Changing Log Settings For Domain:  Domain_7001
##################################################
Location changed to edit tree. This is a writable tree with
DomainMBean as the root. To make changes you will need to start
an edit session via startEdit().

For more help, use help(edit)
You already have an edit session in progress and hence WLST will
continue with your edit session.

Starting an edit session ...
Started edit session, please be sure to save and activate your
changes once you are done.
----------------------------------------------------
Changing Log Setting for serverName:  AdminServer
----------------------------------------------------
Activating all your changes, this may take a while ...
The edit lock associated with this edit session is released
once the activation is completed.
Activation completed
===> Log Setting for serverName:  AdminServer  has been changed Succeefully !!

Starting an edit session ...
Started edit session, please be sure to save and activate your
changes once you are done.
----------------------------------------------------
Changing Log Setting for serverName:  MS-1
----------------------------------------------------
Activating all your changes, this may take a while ...
The edit lock associated with this edit session is released
once the activation is completed.

The following non-dynamic attribute(s) have been changed on MBeans
that require server re-start:
MBean Changed : com.bea:Name=MS-1,Type=Log,Server=MS-1
Attributes changed : FileName

Activation completed
===> Log Setting for serverName:  MS-1  has been changed Succeefully !!

***** Log Settings For Domain:  Domain_7001  has been changed Succeefully !! *****

Connecting to t3://10.65.193.88:7001 with userid weblogic ...
Successfully connected to Admin Server 'AdminServer' that belongs to domain 'test_domain'.

Warning: An insecure protocol was used to connect to the
server. To ensure on-the-wire security, the SSL port or
Admin port should be used instead.

##################################################
Changing Log Settings For Domain:  test_domain
##################################################
You already have an edit session in progress and hence WLST will
continue with your edit session.

Starting an edit session ...
Started edit session, please be sure to save and activate your
changes once you are done.
----------------------------------------------------
Changing Log Setting for serverName:  AdminServer
----------------------------------------------------
Activating all your changes, this may take a while ...
The edit lock associated with this edit session is released
once the activation is completed.

The following non-dynamic attribute(s) have been changed on MBeans
that require server re-start:
MBean Changed : com.bea:Name=AdminServer,Type=Log,Server=AdminServer
Attributes changed : RotateLogOnStartup

Activation completed
===> Log Setting for serverName:  AdminServer  has been changed Succeefully !!

Starting an edit session ...
Started edit session, please be sure to save and activate your
changes once you are done.
----------------------------------------------------
Changing Log Setting for serverName:  MS-1
----------------------------------------------------
Activating all your changes, this may take a while ...
The edit lock associated with this edit session is released
once the activation is completed.

The following non-dynamic attribute(s) have been changed on MBeans
that require server re-start:
MBean Changed : com.bea:Name=MS-1,Type=Log,Server=MS-1
Attributes changed : RotateLogOnStartup

Activation completed
===> Log Setting for serverName:  MS-1  has been changed Succeefully !!

***** Log Settings For Domain:  test_domain  has been changed Succeefully !! *****

Regards,
Ravish Mody

If you enjoyed this post, please considerleaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.