The following sections describe the WebLogic Scripting Tool:
The WebLogic Scripting Tool (WLST) is a command-line scripting interface that system administrators and operators use to monitor and manage WebLogic Server instances and domains. The WLST scripting environment is based on the Java scripting interpreter, Jython. In addition to WebLogic scripting functions, you can use common features of interpreted languages, including local variables, conditional variables, and flow control statements. WebLogic Server developers and administrators can extend the WebLogic scripting language to suit their environmental needs by following the Jython language syntax. See
http://www.jython.org
.
WLST lets you perform the following tasks:
WLST functionality includes the capabilities of these WebLogic Server command-line utilities: the weblogic.Admin
utility that you use to interrogate MBeans and configure a WebLogic Server instance (deprecated in this release of WebLogic Server), the wlconfig
Ant task tool for making WebLogic Server configuration changes, and the weblogic.Deployer
utility for deploying applications. For more information about these command-line utilities, see:
You can create, configure, and manage domains using WLST, command-line utilities, and the Administration Console interchangeably. The method that you choose depends on whether you prefer using a graphical or command-line interface, and whether you can automate your tasks by using a script. See Script Mode.
You can use the scripting tool online (connected to a running Administration Server or Managed Server instance) and offline (not connected to a running server). For information on WLST online and offline commands, see WLST Online and Offline Command Summary.
Online, WLST provides simplified access to Managed Beans (MBeans), Java objects that provide a management interface for an underlying resource that you can manage through JMX. WLST is a JMX client; all the tasks you can do using WLST online, can also be done programmatically using JMX.
For information on using JMX to manage WebLogic Server resources, see Developing Custom Management Utilities with JMX.
When WLST is connected to an Administration Server instance, the scripting tool lets you navigate and interrogate MBeans, and supply configuration data to the server. When WLST is connected to a Managed Server instance, its functionality is limited to browsing the MBean hierarchy.
While you cannot use WLST to change the values of MBeans on Managed Servers, it is possible to use the Management APIs to do so. BEA Systems recommends that you change only the values of configuration MBeans on the Administration Server. Changing the values of MBeans on Managed Servers can lead to an inconsistent domain configuration.
Using WLST offline, you can create a new domain or update an existing domain without connecting to a running WebLogic Server—supporting the same functionality as the Configuration Wizard.
Offline, WLST only provides access to persisted configuration information. You can create new configuration information, and retrieve and change existing configuration information that is persisted in the domain configuration files (located in the config
directory, for example, config.xml
) or in a domain template JAR created using Template Builder.
Note: | Because WLST offline enables you to access and update the configuration objects that appear in the configuration files only, if you wish to view and/or change attribute values for a configuration object that is not already persisted in the configuration files as an XML element, you must first create the configuration object. |
WLST is a command-line interpreter that interprets commands either interactively, supplied one-at-a-time from a command prompt, or in batches, supplied in a file (script), or embedded in your Java code. The modes of operation represent methods for issuing WLST commands:
Interactive mode, in which you enter a command and view the response at a command-line prompt, is useful for learning the tool, prototyping command syntax, and verifying configuration options before building a script. Using WLST interactively is particularly useful for getting immediate feedback after making a critical configuration change. The WLST scripting shell maintains a persistent connection with an instance of WebLogic Server. Because a persistent connection is maintained throughout the user session, you can capture multiple steps that are performed against the server. See Recording User Interactions.
In addition, each command that you enter for a WebLogic Server instance uses the same connection that has already been established, eliminating the need for user re-authentication and a separate JVM to execute the command.
Scripts invoke a sequence of WLST commands without requiring your input, much like a shell script. Scripts contain WLST commands in a text file with a .py
file extension, for example, filename
.py
. You use script files with the Jython commands for running scripts. See Running Scripts.
In Listing 2-1, WLST connects to a running Administration Server instance, creates 10 Managed Servers and two clusters, and assigns the servers to a cluster.
Edit the script to contain the username, password, and URL of the Administration Server and start the server before running this script. See Running Scripts.
from java.util import *
from javax.management import *
import javax.management.Attribute
print 'starting the script .... '
connect('username
','password
','t3://localhost:7001
')
clusters = "cluster1","cluster2"
ms1 = {'managed1':7701,'managed2':7702,'managed3':7703, 'managed4':7704, 'managed5':7705}
ms2 = {'managed6':7706,'managed7':7707,'managed8':7708, 'managed9':7709, 'managed10':7710}
clustHM = HashMap()
edit()
startEdit()
for c in clusters:
print 'creating cluster '+c
clu = create(c,'Cluster')
clustHM.put(c,clu)
cd('..\..')
clus1 = clustHM.get(clusters[0])
clus2 = clustHM.get(clusters[1])
for m, lp in ms1.items():
managedServer = create(m,'Server')
print 'creating managed server '+m
managedServer.setListenPort(lp)
managedServer.setCluster(clus1)
for m1, lp1 in ms2.items():
managedServer = create(m1,'Server')
print 'creating managed server '+m1
managedServer.setListenPort(lp1)
managedServer.setCluster(clus2)
save()
activate(block="true")
disconnect()
print 'End of script ...'
exit()
In embedded mode, you instantiate an instance of the WLST interpreter in your Java code and use it to run WLST commands and scripts. All WLST commands and variables that you use in interactive and script mode can be run in embedded mode.
Listing 2-2 illustrates how to instantiate an instance of the WLST interpreter and use it to connect to a running server, create two servers, and assign them to clusters.
package wlst;
import java.util.*;
import weblogic.management.scripting.utils.WLSTInterpreter;
import org.python.util.InteractiveInterpreter;
/**
* Simple embedded WLST example that will connect WLST to a running server,
* create two servers, and assign them to a newly created cluster and exit.
* <p>Title: EmbeddedWLST.java</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: BEA Systems</p>
* @author Satya Ghattu (sghattu@bea.com)
*/
public class EmbeddedWLST
{
static InteractiveInterpreter interpreter = null;
EmbeddedWLST() {
interpreter = new WLSTInterpreter();
}
private static void connect() {
StringBuffer buffer = new StringBuffer();
buffer.append("connect('weblogic','weblogic')");
interpreter.exec(buffer.toString());
}
private static void createServers() {
StringBuffer buf = new StringBuffer();
buf.append(startTransaction());
buf.append("man1=create('msEmbedded1','Server')\n");
buf.append("man2=create('msEmbedded2','Server')\n");
buf.append("clus=create('clusterEmbedded','Cluster')\n");
buf.append("man1.setListenPort(8001)\n");
buf.append("man2.setListenPort(9001)\n");
buf.append("man1.setCluster(clus)\n");
buf.append("man2.setCluster(clus)\n");
buf.append(endTransaction());
buf.append("print ‘Script ran successfully ...’ \n");
interpreter.exec(buf.toString());
}
private static String startTransaction() {
StringBuffer buf = new StringBuffer();
buf.append("edit()\n");
buf.append("startEdit()\n");
return buf.toString();
}
private static String endTransaction() {
StringBuffer buf = new StringBuffer();
buf.append("save()\n");
buf.append("activate(block='true')\n");
return buf.toString();
}
public static void main(String[] args) {
new EmbeddedWLST();
connect();
createServers();
}
}
The following sections summarize the steps for setting up and using WLST:
To set up your environment for WLST:
CLASSPATH
environment variable and WL_HOME
\server\bin
to the PATH
environment variable, where WL_HOME
refers to the top-level installation directory for WebLogic Server.
You can use a WL_HOME
\server\bin\setWLSEnv
script to set both variables.
On Windows, a shortcut on the Start menu sets the environment variables and invokes WLST (ToolsWebLogic Scripting Tool).
java -Dweblogic.security.SSL.ignoreHostnameVerification=true -Dweblogic.security.TrustKeyStore=DemoTrust weblogic.WLST
Otherwise, at a command prompt, enter one of the following commands:
java weblogic.WLST
java weblogic.WLST -loadProperties propertyFilename
Note: | You can use the -loadProperties option to loads property values from a file and make them available in a WLST session. The usage of this option is similar to the usage of the loadProperties command. For more information, see loadProperties |
For more information, see Creating and Configuring WebLogic Domains Using WLST Offline.
To use WLST online, start a WebLogic Server instance (see
Starting and Stopping Servers) and connect WLST to the server using the connect
command.
wls:/(offline)> connect('
username
','
password
','
t3s://localhost:7002
')
Connecting to weblogic server instance running at t3s://localhost:7002 as username weblogic ...
Successfully connected to Admin Server 'myserver' that belongs to domain 'mydomain'.
Note: | BEA Systems strongly recommends that you connect WLST to the server through an SSL port or the administration port. If you do not, the following warning message is displayed: |
Note: | Warning: An insecure protocol was used to connect to the server. |
For detailed information about the connect
command, see connect.
Follow these rules when entering WLST commands. Also see WLST Command and Variable Reference and WLST Online and Offline Command Summary.
'newServer'
or "newServer"
.\
) in a string, for example when specifying a file pathname, you should precede the quoted string by r to instruct WLST to interpret the string in its raw form and ensure that the backslash is taken literally. This format represents standard Jython syntax. For example:readTemplate(r'c:\mytemplate.jar')
.
), forward slash (/
), or backward slash (\
).
If you need to cd
to an object name that includes a forward slash (/
) in its name, include the configuration object name in parentheses. For example:
cd('JMSQueue/(jms/REGISTRATION_MDB_QUEUE)')
help
command. See Getting Help.The user names and passwords of WebLogic Server users, security groups, and security roles are not stored in a domain’s XML configuration documents. Instead, a domain uses a separate software component called an Authentication provider to store, transport, and provide access to security data. Authentication providers can use different types of systems to store security data. The Authentication provider that WebLogic Server installs uses an embedded LDAP server.
When you use WLST offline to create a domain template, WLST packages the Authentication provider’s data store along with the rest of the domain documents. If you create a domain from the domain template, the new domain has an exact copy of the Authentication provider’s data store from the domain template.
You cannot use WLST offline to modify the data in an Authentication provider’s data store.
You can, however, use WLST online to interact with an Authentication provider and add, remove, or modify users, groups, and roles. For more information, see Managing Security.
WLST incorporates two Jython functions that support running scripts:
java weblogic.WLST
filePath
.py
This command invokes WLST and executes a script file in a single command. See Invoke WLST and Run a Script.
execfile(
filePath
.py)
This command executes a script file after you invoke WLST. See Run a Script From WLST.
To run the script examples in this guide, copy and save the commands in a text file with a .py
file extension, for example, filename
.py
. Use the text file with the commands for running scripts that are listed below. There are sample scripts that you can use as a template when creating a script
.py
file from scratch. For more information, see WLST Sample Scripts.
If the script will connect WLST to a running server instance, start WebLogic Server before running the script.
The following command invokes WLST, executes the specified script, and exits the WLST scripting shell. To prevent exiting WLST, use the -i
flag.
java weblogic.WLST
filePath
.py
java weblogic.WLST -i filePath
.py
Note: | If a WLST script named wlstProfile.py exists in the directory from which you invoke WLST or in user.home (the home directory of the operating system user account as determined by the JVM), the commands will be executed automatically once WLST is invoked. In this case, you do not need to specify the name of the WLST script file on the command-line. |
c:\>
java weblogic.WLST c:/temp/example.py
Initializing WebLogic Scripting Tool (WLST) ...
starting the script ...
...
Use the following command to execute the specified script after invoking WLST.
execfile(filePath
)
c:\>
java weblogic.WLST
Initializing WebLogic Scripting Tool (WLST) ...
...
...
wls:/(offline)>execfile('c:/temp/example.py')
starting the script ...
...
Advanced users can import WLST from WebLogic Server as a Jython module. After importing WLST, you can use it with your other Jython modules and invoke Jython commands directly using Jython syntax.
The main steps include converting WLST definitions and method declarations to a .py
file, importing the WLST file into your Jython modules, and referencing WLST from the imported file.
To import WLST as a Jython module:
c:\>
java weblogic.WLST
wls:/(offline)>
writeIniFile
command to convert WLST definitions and method declarations to a .py
file.
wls:/(offline)>
writeIniFile("wl.py")
The Ini file is successfully written to wl.py
wls:/(offline)>
c:\>
java org.python.util.jython
The Jython package manager processes the JAR files in your classpath. The Jython prompt appears:
import
command.
wl.connect('username','password')
....
Note: | When using WLST as a Jython module, in all WLST commands that have a block argument, block is always set to true, specifying that WLST will block user interaction until the command completes. See WLST Command and Variable Reference. |
wls:/mydomain/serverConfig>exit()
Exiting WebLogic Scripting Tool ...
c:\>
The wlst
Ant task is predefined in the version of Ant shipped with WebLogic Server and enables you to run WLST scripts from within your Ant build file.
Note: | If you want to use the task with your own Ant installation, add the following task definition in your build file: |
Note: | <taskdef name="wlst" classname="weblogic.ant.taskdefs.management.WLSTTask" /> |
To run WLST from an Ant script:
setWLSEnv.cmd
command, located in the directory WL_HOME
\server\bin
, where WL_HOME
is the top-level directory of your WebLogic Server installation.setWLSEnv.sh
command, located in the directory WL_HOME
/server/bin
, where WL_HOME
is the top-level directory of your WebLogic Server installation.wlst
Ant task to execute WLST commands. For example:<target name="runwlst">
<wlst fileName="./myscript.py" executeScriptBeforeFile="true"
debug="false" failOnError="false">
<script>
connect('weblogic','weblogic','t3://localhost:7001')
</script>
</wlst>
</target>
Using the wlst
Ant task, you can specify WLST commands within a WLST script, using the fileName
attribute, or embed WLST script commands inside the build file, within the <script>
tags. For more information about the Ant task command syntax, see wlst Ant Task Syntax.
build.xml
file by typing ant
in the staging directory, optionally passing the command a target argument: prompt> ant runwlst
Note: | Use ant -verbose to obtain more detailed messages from the wlst task. |
The syntax of the wlst
Ant task is as follows:
<wlst properties="propsFile
" fileName="fileName
" arguments="arglist
" failOnError="value
" executeScriptBeforeFile="value
" debug="value
">
<script>wlst-commands
</script>
You can specify WLST commands within a WLST script (.py
) file and specify that file using fileName
attribute, or embed WLST script commands inside the build file, enclosing them within the <script>
tags.
The following table defines the Ant task attributes that you can specify as part of the wlst
Ant task.
In the following example, the createServer
target:
t3://localhost():7001
, edits the configuration to create a new server, and saves and activates the configuration changes. (Note that executeScriptBeforeFile
is set to true
, so the embedded script is executed first, before the specified WLST script file.)myscript.py
that is located in the current directory.sys.argv
variable.wlst
Ant task fails to execute.<target name="configServer">
<wlst debug="false" failOnError="false" executeScriptBeforeFile="true"
fileName="./myscript.py">
<script>
connect('weblogic','weblogic','t3://localhost:7001')
</script>
</wlst>
</target>
In the following example, the loop
target:
myscript.py
in the current directory. (Note that executeScriptBeforeFile
is set to false
, so the WLST script file is executed first, before the embedded script.)t3://localhost():7001
and access and print the list of servers in the domain.wlst
task fails to execute, as per the failOnError="true
" setting.<target name="loop">
<wlst debug="true" executeScriptBeforeFile="false"
fileName="./myscript.py" failOnError="true">
<script>
print 'In the target loop'
connect('weblogic','weblogic','t3://localhost:7001')
svrs = cmo.getServers()
print 'Servers in the domain are'
for x in svrs: print x.getName()
</script>
</wlst>
</target>
In the following example, the error
target:
thisWillCauseNameError
.false
" setting, even if the thisWillCauseNameError
variable does not exist and the wlst
Ant task fails to execute.<target name="error">
<wlst debug="true" failOnError="false">
<script>print thisWillCauseNameError</script>
</wlst>
</target>
To display information about WLST commands and variables, enter the help
command.
If you specify the help
command without arguments, WLST summarizes the command categories. To display information about a particular command, variable, or command category, specify its name as an argument to the help
command. To list a summary of all online or offline commands from the command line using the following commands, respectively:
help('online')
help('offline')
The help
command will support a query; for example, help('get*')
displays the syntax and usage information for all commands that begin with get
.
For example, to display information about the disconnect
command, enter the following command:
wls:/mydomain/serverConfig>
help('disconnect')
The command returns the following:
Description:
Disconnect from a weblogic server instance.
Example:
wls:/mydomain/serverConfig> disconnect()
To start and stop the recording of all WLST command input, enter:
startRecording(
recordFilePath
,[recordAll])
stopRecording()
You must specify the file pathname for storing WLST commands when you enter the startRecording
command. You can also optionally specify whether or not you want to capture all user interactions, or just the WLST commands; the recordAll
argument defaults to false.
For example, to record WLST commands in the record.py
file, enter the following command:
wls:/mydomain/serverConfig>
startRecording('c:/myScripts/record.py')
For more information, see startRecording and stopRecording.
To start and stop redirecting WLST output to a file, enter:
redirect(
outputFile
,[toStdOut])
stopRedirect()
You must specify the pathname of the file to which you want to redirect WLST output. You can also optionally specify whether you want WLST output to be sent to stdout
; the toStdOut
argument defaults to true.
For example, to redirect WLST output to the logs/wlst.log
file in the current directory and disable output from being sent to stdout
, enter the following command:
wls:/mydomain/serverConfig> redirect('./logs/wlst.log', 'false')
Note: | There are some operations that are not redirected by WLST. For example, WLST does not redirect messages output from the Jython layer. |
For more information, see redirect and stopRedirect.
To convert an existing server configuration (config
directory) to an executable WLST script, enter:
configToScript([domainDir
], [scriptPath
], [overwrite
], [propertiesFile
], [deploymentScript
])
./config
)./config/config.py
)true
)scriptPath
)false
)Note: | configToScript() creates ancillary user-config and user-key files to hold encrypted attributes. |
You can use the resulting script to re-create the resources on other servers. Before running the generated script, you should update the properties file to specify values that are appropriate for your environments. When you run the generated script:
For example, the following command creates a WLST script from the domain located at c:/bea/user_projects/domains/mydomain
, and saves it to c:/bea/myscripts
.
wls:/(offline)>
configToScript('c:/bea/user_projects/domains/mydomain',
'c:/bea/myscripts')
For more information, see configToScript.
You can customize WLST using the WLST home directory, which is located at WL_HOME
/common/wlst
, by default, where WL_HOME
refers to the top-level installation directory for WebLogic Server. All Python scripts that are defined within the WLST home directory are imported at WLST startup.
Note: | You can customize the default WLST home directory by passing the following argument on the command line: -Dweblogic.wlstHome=< another-directory > |
The following table describes ways to customize WLST.
This script can be imported into other Jython modules, as described in Importing WLST as a Jython Module.
|