Thursday, April 4, 2013

Sample WLST Script To Start WebLogic Servers

Version: WebLogic 10.3.5
Description:
Given here is a sample python script that starts up Node Manager, OIM managed server, SOA managed server, and  Administration server.
This python script uses WLST commands and requires WLST to invoke it.

To execute this script through WLST, execute the [WL_HOME]/common/bin/wlst.sh [pathToScript].
cd /home/oracle/Oracle/Middleware/wlserver_10.3/common/bin/
./wlst.sh /home/oracle/Desktop/startServers.py

Sample Python script which contains WLST commands.
# A WLST script to start the Node Manager, AdminServer, oim_server1, and soa_server1.
# This assumes the servers are all the same machine.
# The node manager key and configuration files were generated by WLST storeUserConfig() command.

#Name of servers
adminServerValue = 'AdminServer';
oimServerValue='oim_server1';
soaServerValue='soa_server1';

#Info for startNodeManager()
nmHome='/home/oracle/Oracle/Middleware/wlserver_10.3/common/nodemanager';
nmPort='5556';
nmListenAddress='localhost';
nmVerboseMode='false';

#Info for nmConnect()
userConfigFileValue='/home/oracle/nodeManagerConfig/oracle-WebLogicConfig.properties'; #Path to configuration file 
userKeyFileValue='/home/oracle/nodeManagerConfig/oracle-WebLogicKey.properties';#Path to key file 
hostValue='localhost'; #Host name (Listen Address) of the Node Manager
portValue='5556'; #Port number of Node Manager
domainNameValue='oim_domain'; #Name of the WebLogic domain that you want to manage
domainDirValue='/home/oracle/Oracle/Middleware/user_projects/domains/oim_domain'; #Path of the domain directory 
nmTypeValue='ssl'; #The Node Manager type
verboseModeValue = 'false'; #Verbose mode

print 'Invoking startServers.py script';

try:

   #Attempt to connect to Node Manager. If fail to connect, start Node Manager. 
   try:
      print 'Connecting to Node Manager.';
      nmConnect(userConfigFile=userConfigFileValue, userKeyFile=userKeyFileValue, host=hostValue, port=portValue, domainName=domainNameValue, domainDir=domainDirValue, mType=nmTypeValue, verbose=verboseModeValue);

   except:
      print 'Starting Node Manager.';
      #Start Node Manager (Do not use this command in a production environment)
      startNodeManager(verbose=nmVerboseMode, NodeManagerHome=nmHome, ListenPort=nmPort, ListenAddress=nmListenAddress);
      print 'Attempting to connect to Node Manager.';
      nmConnect(userConfigFile=userConfigFileValue, userKeyFile=userKeyFileValue, host=hostValue, port=portValue, domainName=domainNameValue, domainDir=domainDirValue, mType=nmTypeValue, verbose=verboseModeValue);

   #Determine if WLST is currently connected to Node Manager on machine
   if nm():    
      print 'Current Admin Server Status:';
      adminServerStatus = nmServerStatus(adminServerValue);
      print 'Current SOA Server Status:';
      soaServerStatus = nmServerStatus(soaServerValue); 
      print 'Current OIM Server Status:';
      oimServerStatus = nmServerStatus(oimServerValue);

      if not adminServerStatus == 'RUNNING':
         #Start WebLogic Administrator Server
         nmStart(adminServerValue);
         print 'New Adminstrator Status:';
         nmServerStatus(adminServerValue);

      if not soaServerStatus == 'RUNNING':
         #Start SOA Managed Server
         nmStart(soaServerValue);
         print 'New SOA Server Status:';
         nmServerStatus(soaServerValue);

      if not oimServerStatus == 'RUNNING':
         #Start OIM Managed Server
         nmStart(oimServerValue);
         print 'New OIM Server Status:';
         nmServerStatus(oimServerValue);

   else:
      print 'Fail to connect Node Manager.';

finally:
     #Disconnect from Node Manager on OIM machine
     nmDisconnect();
     exit();

print 'End startServers.py script';

No comments:

Post a Comment