wlst script example to manage weblogic server

Oracle Weblogic Server

While managing multiple domains with huge number of managed servers becomes very hard if you don’t have the scripts to manage the server life cycle. Sometimes we need just one server to restart instead of restarting the whole domain post patching a jar or artifact and sometimes you need all the managed servers to be restarted, etc. Same, I had a issue that I needed to check the status of the managed servers in realtime while they were getting started, so I looked through Google and found some scripts in wlst but all of them were not fulfilling my purpose of realtime monitoring of the status of servers while they get started/stopped. I also wanted colored output and progress bar also, so that i can see that which server came up online. I had also requirement of a rolling restart of the servers, so needed to check one server after one server. So for this I wrote below wlst script example to do start, stop, monitor, status check etc of weblogic server.

To fulfill the purpose we need two scripts 1. wlst script(manageServers.py) and 2. Bash script(manageServers.sh) as a wrapper script to wlst script

WLST script manageServers.py

Purpose: start/stop/status check and monitor manage servers life cycle with colored output and progress bar of the lifecycle event

Raw Usage :

java weblogic.WLST manageServers.py -u username -p password -a adminUrl [<hostname>:<port>] -n ServerName -c [stop:start:restart:status:stopall:startall:statusall]

Script :

import sys
import os
from java.lang import System
import sys
import os
from java.lang import System
#Python Script to manage Servers in weblogic server.
#This script takes input from command line and executes it.
#It can be used to check status,stop,start of applications in weblogic server using weblogic wlst tool.
#Company: TechPaste Solutions
import getopt
#========================
#Usage Section
#========================
def usage():

    print "Usage:"
    print "java weblogic.WLST manageServers.py -u username -p password -a adminUrl [:] -n ServerName -c [stop:start:restart:status:stopall:startall:statusall]\n"
    sys.exit(2)
#========================
#Connect To Domain
#========================

def connectToDomain():
    try:
        if username != "":
            connect(username, password, adminUrl)
            print 'Successfully connected to the domain\n'
 #       else:
 #           connect(userConfigFile=UCF, userKeyFile=UKF, url=admurl)
 #           print 'Successfully connected to the domain\n'

    except:
        print 'The domain is unreacheable. Please try again\n'
        exit()

#==============================================
#Checking Server Status
#==============================================
def _serverstatus(ServerName):
    try:
#        print 'Server reached:'+ServerName
        cd('domainRuntime:/ServerLifeCycleRuntimes/'+ServerName);
#        print 'Cd successful';
#        ls();
        serverState = cmo.getState()
#        print 'Server State'+serverState;
        if serverState == "RUNNING":
            print 'Server ' + ServerName + ' is :\033[1;32m' + serverState + '\033[0m';
        elif serverState == "STARTING":
            print 'Server ' + ServerName + ' is :\033[1;33m' + serverState + '\033[0m';
        elif serverState == "UNKNOWN":
            print 'Server ' + ServerName + ' is :\033[1;34m' + serverState + '\033[0m';
        else:
            print 'Server ' + ServerName + ' is :\033[1;31m' + serverState + '\033[0m';
        return serverState
    except:
        print 'Not able to get the' + serverState +'server status. Please try again\n';
        print 'Please check logged in user has full access to complete the requested operation on ' +ServerName+ '\n';
        exit()

#==============================================
#Start Server Block
#==============================================

def _startServer(ServerName):

    try:
        cd('domainRuntime:/ServerLifeCycleRuntimes/'+ServerName);
        cmo.start();
        state=_serverstatus(ServerName);
        while (state!='RUNNING'):
            state=_serverstatus(ServerName);
            java.lang.Thread.sleep(5000);
    except:
        print 'Error in getting current status of ' +ServerName+ '\n';
        print 'Please check logged in user has full access to complete the start operation on ' +ServerName+ '\n';
        exit()
#==============================================
#Stop Server Block
#==============================================

def _stopServer(ServerName):

    try:
        cd('domainRuntime:/ServerLifeCycleRuntimes/'+ServerName);
        cmo.forceShutdown();
        state=_serverstatus(ServerName);
        while (state!='SHUTDOWN'):
            state=_serverstatus(ServerName);
            java.lang.Thread.sleep(5000);
    except:
        print 'Error in getting current status of ' +ServerName+ '\n';
        print 'Please check logged in user has full access to complete the stop operation on ' +ServerName+ '\n';
        exit()

#===============================
#Input Values Validation Section
#===============================

if __name__=='__main__' or __name__== 'main':

    try:
        opts, args = getopt.getopt(sys.argv[1:], "u:p:a:n:c:", ["username=", "password=", "adminUrl=", "ServerName=", "command="])

    except getopt.GetoptError, err:
        print str(err)
        usage()

    username = ''
    password = ''
    adminUrl = ''
    ServerName = ''
    command = ''

    for opt, arg in opts:
        if opt == "-u":
            username = arg
        elif opt == "-p":
            password = arg
        elif opt == "-a":
            adminUrl = arg
        elif opt == "-n":
            ServerName = arg
        elif opt == "-c":
            command = arg

    if username == "":
        print "Missing \"-u username\" parameter.\n"
        usage()
    elif password == "":
        print "Missing \"-p password\" parameter.\n"
        usage()
    elif adminUrl == "":
        print "Missing \"-a adminUrl\" parameter.\n"
        usage()
    elif ServerName == "":
        print "Missing \"-n ServerName\" parameter.\n"
        usage()
    elif command == "":
        print "Missing \"-c command\" parameter.\n"
        usage()
#========================
#Main Control Block For Operations
#========================

def lifecycleMain():
    try:
        if command =='status' :
            _serverstatus(ServerName);
        elif command =='stop':
            state=_serverstatus(ServerName);
            if state!='SHUTDOWN' :
                print 'Trying To Shutdown Server:' + ServerName + '...';
                _stopServer(ServerName);
        elif command =='start':
            state=_serverstatus(ServerName);
            if state!='RUNNING' :
                print 'Trying To Start Server:' + ServerName + '...';
                _startServer(ServerName);
        elif command =='restart':
            state=_serverstatus(ServerName);
            if state!='SHUTDOWN' :
                print 'Trying To Shutdown Server:' + ServerName + '...';
                _stopServer(ServerName);
            state=_serverstatus(ServerName);
            if state!='RUNNING' :
                print 'Trying To Start Server:' + ServerName + '...';
                _startServer(ServerName);
        elif command == "stopall":
            try:
                cd('/Servers')
                allServers=ls('/Servers', returnMap='true')
                for p_server in allServers:
                    if p_server == 'AdminServer':
                        continue
                    else:
                        _stopServer(p_server);
            except Exception, e:
                print "Error Occured"
        elif command == "startall":
            try:
                cd('/Servers')
                allServers=ls('/Servers', returnMap='true')
                for p_server in allServers:
                    if p_server == 'AdminServer':
                        continue
                    else:
                        _startServer(p_server);
            except Exception, e:
                print "Error Occured"
        elif command == "statusall":
            try:
                cd('/Servers')
                allServers=ls('/Servers', returnMap='true')
                for p_server in allServers:
                    _serverstatus(p_server);
            except Exception, e:
                print "Error Occured"
        else:
           print 'Not able to understand the command supplied.'
           usage();
    except:
        print 'Error during lifecycle operation of ' +ServerName+ '\n'
        exit();
#========================
#Execute Block
#========================

connectToDomain();
lifecycleMain();
disconnect();
exit();

 

2. Wrapper Bash script:

create a bash script named manageServers.sh in the same directory where you have saved the wlst python script manageServers.py with below content.

#!/bin/bash
/slot/oracle/weblogic/myDomain/bin/setDomainEnv.sh 2>&1 >/dev/null
java -cp /slot/oracle/weblogic/wlserver_10.3/server/lib/weblogic.jar weblogic.WLST ms.py -u weblogic -pwelcome -a localhost:7001 -n $1 -c $2

Execution:

You can run the scripts in any manner, directly via wlst or using the bash wrapper script with prefed username and passwords.

1. Direct Run Using WLST tool

Starting a Server:

java -cp /slot/oracle/wlserver_10.3/server/lib/weblogic.jar weblogic.WLST ms.py -u weblogic -p weblogic1 -a localhost:7001 -n ess_server1 -c start

Output:

Initializing WebLogic Scripting Tool (WLST) …

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 ‘MyDomain’.

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.

Successfully connected to the domain

Location changed to domainRuntime tree. This is a read-only tree with DomainMBean.

For more help, use help(domainRuntime)
Server ess_server1 is :SHUTDOWN
Trying To Start Server:ess_server1…
Server ess_server1 is :SHUTDOWN
Server ess_server1 is :STARTING
Server ess_server1 is :STARTING
Server ess_server1 is :STARTING
Server ess_server1 is :RESUMING
Server ess_server1 is :RESUMING
Server ess_server1 is :RESUMING
Server ess_server1 is :RESUMING
Server ess_server1 is :RUNNING
Disconnected from weblogic server: AdminServer

Exiting WebLogic Scripting Tool.

Output On SSH Terminal(Putty):

WLS server Start colored Output

 

Restart A Server:

java -cp /slot/oracle/wlserver_10.3/server/lib/weblogic.jar weblogic.WLST ms.py -u weblogic -p weblogic1 -a localhost:7001 -n ess_server1 -c restart

WLS Server Restart Output

 

Stopping A Server:

java -cp /slot/oracle/wlserver_10.3/server/lib/weblogic.jar weblogic.WLST ms.py -u weblogic -p weblogic1 -a localhost:7001 -n ess_server1 -c stop

Successfully connected to the domain

Location changed to domainRuntime tree. This is a read-only tree with DomainMBean as the root.
For more help, use help(domainRuntime)
Server ess_server1 is :RUNNING
Trying To Shutdown Server:ess_server1…
Server ess_server1 is :FORCE_SUSPENDING
Server ess_server1 is :FORCE_SUSPENDING
Server ess_server1 is :SHUTDOWN
Disconnected from weblogic server: AdminServer

Output On SSH Terminal(Putty):

WLS Server Stop Colored Output

 

Status Check Of Server:

java -cp /slot/oracle/wlserver_10.3/server/lib/weblogic.jar weblogic.WLST ms.py -u weblogic -p weblogic1 -a localhost:7001 -n ess_server1 -c status

Successfully connected to the domain

Location changed to domainRuntime tree. This is a read-only tree with DomainMBean as the root.
For more help, use help(domainRuntime)
Server ess_server1 is :SHUTDOWN
Disconnected from weblogic server: AdminServer

Output On SSH Terminal(Putty):

WLS Server Status Colored output

 

Status Check Of All Servers:

java -cp /slot/oracle/wlserver_10.3/server/lib/weblogic.jar weblogic.WLST ms.py -u weblogic -p weblogic1 -a localhost:7001 -n all -c statusall

WLS All Server Status Output

 

Similar commands:

You can use below command to stopall/startall servers in a domain

java -cp /slot/oracle/wlserver_10.3/server/lib/weblogic.jar weblogic.WLST ms.py -u weblogic -p weblogic1 -a localhost:7001 -n all -c stopall/startall/statusall

Start/stop/status using bash script(manageServers.sh):

-bash-3.2$ ./manageServers.sh all statusall/stopall/statusall

-bash-3.2$ ./manageServers.sh ess_server1 status/stop/start

Output will be similar to above output.

Script To Show Progress Bar in Status:

We can modify the above mentioned manageServers.py script to show a progress bar instead of showing servers current runtime state while starting/stopping for better stylish view

Modify the existing  functions like below to show progress bar:

 

def _serverstatus(ServerName):
    try:
        cd('domainRuntime:/ServerLifeCycleRuntimes/'+ServerName);
        serverState = cmo.getState()
        return serverState
    except:
        print 'Not able to get the' + serverState +'server status. Please try again\n';
        print 'Please check logged in user has full access to complete the requested operation on ' +ServerName+ '\n';
        exit()

#==============================================
#Start Server Block
#==============================================

def _startServer(ServerName):

    try:
        cd('domainRuntime:/ServerLifeCycleRuntimes/'+ServerName);
        cmo.start();
        state=_serverstatus(ServerName);
        toolbar_width = 40

# setup toolbar
        sys.stdout.write("\033[1;34m[%s]\033[0m" % (" " * toolbar_width))
        sys.stdout.flush()
        sys.stdout.write("\b" * (toolbar_width+1)) # return to start of line, after '['

        for i in xrange(toolbar_width):
            while (state!='RUNNING'):
                state=_serverstatus(ServerName);
                java.lang.Thread.sleep(4000);
                # update the bar
                sys.stdout.write("\033[1;32m#\033[0m")
                sys.stdout.flush()
        sys.stdout.write("\n")

    except:
        print 'Error in getting current status of ' +ServerName+ '\n';
        print 'Please check logged in user has full access to complete the start operation on ' +ServerName+ '\n';
        exit()
#==============================================
#Stop Server Block
#==============================================
def _stopServer(ServerName):

    try:
        cd('domainRuntime:/ServerLifeCycleRuntimes/'+ServerName);
        cmo.forceShutdown();
        state=_serverstatus(ServerName);
        toolbar_width = 40
# setup toolbar
        sys.stdout.write("\033[1;34m[%s]\033[0m" % (" " * toolbar_width))
        sys.stdout.flush()
        sys.stdout.write("\b" * (toolbar_width+1)) # return to start of line, after '['

        for i in xrange(toolbar_width):
#            time.sleep(0.1) # do real work here
            while (state!='SHUTDOWN'):
                state=_serverstatus(ServerName);
                java.lang.Thread.sleep(4000);
                # update the bar
                sys.stdout.write("\033[1;32m#\033[0m")
                sys.stdout.flush()
        sys.stdout.write("\n")
    except:
        print 'Error in getting current status of ' +ServerName+ '\n';
        print 'Please check logged in user has full access to complete the stop operation on ' +ServerName+ '\n';
        exit()

 

The commands to operate remains same but the Output will look like below, Stylish good to impress your manager 🙂

Restart of ess_server1

Restart Of managed Server with progress bar

 

If you find this article useful please share!!

In case of any ©Copyright or missing credits issue please check CopyRights page for faster resolutions.

60 Responses

  1. Mahesh says:

    Thank you for the script.It addresses all the questions I had with managing start/stop from command line

  2. siva says:

    Hi,

    I am new one for Web logic server. Will you please help me how to do the above process step by step in Local server using Putty Software

  3. siva says:

    will you please guide me How to install web logic 10.3

  4. Poul says:

    I’m running a command java weblogic.WLST pythonscript.py from some bash script examplebash.sh

    I have problem to execute Command raw_input or sys.stdin.readline(), which I try use in pythonscript.py file.

    When I use raw_input I get error EOFError: raw_input(), when I use sys.stdin.readline() it’s nothing happened.

    It’s looks that, because I start pythonscript.py from bash script examplebash.sh the standard input doesn’t work?

    Can You help me with this problem?

    • TechPaste.Com says:

      message = sys.stdin.read()
      sys.stdin = open(‘/dev/tty’)
      selected_index = raw_input(‘Which URL to open?’)

  5. Varsity0974 says:

    Instead of passing the server name as command line parameter, I am looking at displaying all servers of the domain as a list and then type in the number to pickup the server for startup/shutdown. I will appreciate if you can direct me to anything similar.

    • TechPaste.Com says:

      You can do something like list the servers/applications and add them to variables and read the input to execute the command on them.

      E.g adding to variable

      ArrayList appList = new ArrayList();
      Writer out = new StringWriter();
      interpreter.setOut(out);
      interpreter.exec(“print listApplications()”);

      StringBuffer results = new StringBuffer();
      results.append(out.toString());

      Scanner scanner = new Scanner(results.toString());
      while(scanner.hasNextLine()){
      String line = scanner.nextLine();
      line = line.trim();
      if(line.equals(“None”))
      continue;
      appList.add(line);
      }

      once the servers are listed and numbered For reading inputs do something like

      import os;
      serverName=raw_input(‘Enter the server number you want to operate: ‘)
      lifecycleoperation=raw_inpu(‘Enter what you want to do stop(1)/start(2)/restart(3)/shutdown(4):’)

  6. Shashi Kant Singh says:

    I appreciate your effort.
    Just wanted to know if their is any performance issue while running this script.

    Thanks

    • TechPaste.Com says:

      Hi Shashi,

      It’s using the Oracle recommended inbuilt WLST for these life-cycle operations, so it should not have any performance issues while running them. You can go ahead and use it without worries.

  7. wls_novice says:

    Does this script include bouncing of coherence server?

    • Ramakanta says:

      It is not particular about a server. You can mention any server name in weblogic domain and it shall work fine with that. you need to mention something like below:

      java -cp /slot/oracle/wlserver_10.3/server/lib/weblogic.jar weblogic.WLST ms.py -u weblogic -p weblogic1 -a localhost:7001 -n -c stop/start/restart

      • Bharat says:

        Hi Ramakanta. This is a very useful script. Thank you. We have the following requirement. We have multiple domains in a environment for different weblogic products like portal sever domain,. soa domain, osb domain etc. Every domain has its managed servers. How do we start all the servers from all the domains with a single WLST script? Please advise.

        Thanks,
        Bharat

        • Ramakanta says:

          What you can do is create a shell script containing commands for individual domains.Like below

          #!/bin/bash
          /slot/oracle/weblogic/myDomain/bin/setDomainEnv.sh 2>&1 >/dev/null
          java -cp /slot/oracle/weblogic/wlserver_10.3/server/lib/weblogic.jar weblogic.WLST ms.py -u weblogic -pwelcome -a localhost:7001 -n $1 -c $2
          /slot/oracle/weblogic/myDomain_1/bin/setDomainEnv.sh 2>&1 >/dev/null
          java -cp /slot/oracle/weblogic/wlserver_10.3/server/lib/weblogic.jar weblogic.WLST ms.py -u weblogic -pwelcome -a localhost:7001 -n $1 -c $2
          /slot/oracle/weblogic/myDomain_2/bin/setDomainEnv.sh 2>&1 >/dev/null
          java -cp /slot/oracle/weblogic/wlserver_10.3/server/lib/weblogic.jar weblogic.WLST ms.py -u weblogic -pwelcome -a localhost:7001 -n $1 -c $2

          • Bharat says:

            Thanks again. We have multiple domains on separate vm’s. Please advise how we can ssh or connect to the other domains on separate vm’s and perform a restart for all these domains at once using WLST.

            Thanks,
            Bharat

  8. Bharat says:

    Please let me know if there is a way we can perform the above task.

    Thanks,
    Bharat

  9. Bharat says:

    Nevermind. I was able to figure it out. We established a route and was able to connect to other servers on separate vm’s using the same commands inside the script with different host name and ports.

    Thanks,
    Bharat

  10. emad says:

    hi,
    actually the managed server has been stopped successfully but i couldnt start it again by the script, beside please i need to stop/start all the managed servers my domain all at the same time by the script.

    • Ramakanta says:

      Can you please post the error you are seeing while starting.
      If you want all servers to be started at the same time you can create a shell script and put all the server names individually for starting and stopping

      java -cp /slot/oracle/wlserver_10.3/server/lib/weblogic.jar weblogic.WLST ms.py -u weblogic -p weblogic1 -a localhost:7001 -n ess_server1 -c start &
      java -cp /slot/oracle/wlserver_10.3/server/lib/weblogic.jar weblogic.WLST ms.py -u weblogic -p weblogic1 -a localhost:7001 -n ess_server2 -c start &

  11. Rajesh says:

    i want to use encrypted username and password of weblogic. Could you please help.

    • Ramakanta says:

      Hi Rajesh,

      You can modify the script to use encrypted passwords from file.

      in the connect to domain section of the script you can enable the code (remove the #) and can use the encrypted passwords from file

      def connectToDomain():
      try:
      if username != “”:
      connect(username, password, adminUrl)
      print ‘Successfully connected to the domain\n’
      # else:
      # connect(userConfigFile=UCF, userKeyFile=UKF, url=admurl)
      # print ‘Successfully connected to the domain\n’

      except:
      print ‘The domain is unreacheable. Please try again\n’
      exit()

      Example Connect:

      connect(userConfigFile=’/someDirectory/MyUserConfigFile’,userKeyFile=’/someDirectory/MyUserKeyFile’,url=’t3://localhost:7001′)

      Follow the below steps to store you password and keys into a file

      https://blogs.oracle.com/bala/entry/encrypt_the_credentials_when_r

      Thanks.

  12. Sumit says:

    hi,
    the managed server has been stopped successfully but i couldn’t start it again by the script. below is the command i am using and the output for the same.

    java -cp weblogic.jar weblogic.WLST manageServers.py -u weblogic -p abcd1234 -a localhost:9004 -n ess_server2 -c restart

    Initializing WebLogic Scripting Tool (WLST) …

    Welcome to WebLogic Server Administration Scripting Shell

    Type help() for help on available commands

    Connecting to t3://localhost:9004 with userid weblogic …
    Successfully connected to Admin Server ‘AdminServer’ that belongs to 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.

    Successfully connected to the domain

    Location changed to domainRuntime tree. This is a read-only tree with DomainMBean as the root.
    For more help, use help(domainRuntime)
    Server ess_server2 is :RUNNING
    Trying To Shutdown Server:ess_server2 …
    Server ess_server2 is :RUNNING
    Server ess_server2 is :FORCE_SUSPENDING
    Server ess_server2 is :SHUTDOWN
    Server ess_server2 is :SHUTDOWN
    Trying To Start Server:ess_server2 …
    Server ess_server2 is :SHUTDOWN
    Server ess_server2 is :SHUTDOWN
    Server ess_server2 is :SHUTDOWN
    Server ess_server2 is :SHUTDOWN
    Server ess_server2 is :SHUTDOWN
    Server ess_server2 is :SHUTDOWN
    Server ess_server2 is :SHUTDOWN
    Server ess_server2 is :SHUTDOWN
    Server ess_server2 is :SHUTDOWN
    Server ess_server2 is :SHUTDOWN
    Server ess_server2 is :SHUTDOWN
    Server ess_server2 is :SHUTDOWN
    Server ess_server2 is :SHUTDOWN
    Server ess_server2 is :SHUTDOWN

    • Ramakanta says:

      See if manually via console you are able to start or not and see incase the script is getting the status from the admin server or not?

      • Sumit says:

        The script is able to get the status from the admin server. I think the method used in the script requires node manager to start the managed server. is there any way i can start server without node manager?

        • Ramakanta says:

          Using the WLST startServer command, the administration server can be started without using a NodeManager. The server runs in a separate process from WLST, which means that exiting WLST does not shutdown the server.

          startServer([adminServerName], [domainName], [url], [username], [password],[domainDir], [block], [timeout], [serverLog], [systemProperties], [jvmArgs])

          Example:

          wls:/offline> startServer(‘AdminServer’,’TestDomain’,’t3://myTestServer:12345′,
          ‘admin’,’‘,’/application/domains/TestDomain’,’false’, 60000, jvmArgs=’-XX:MaxPermSize=125m, -Xmx512m, -XX:+UseParallelGC’)
          wls:/offline>

  13. Arun says:

    The script is very well written. Thanks a lot for sharing the scripts.

    • Ramakanta says:

      Glad It Helped! 🙂

      • Arun says:

        Hi Ramakanta,

        Note: I want to start manage server with node manager.

        The manage server is working for stopping the server, but the script is not starting the manage server. Below are the script log.

        I tried directly traversing into the wlst directory and starting the manage server but from there also stopping works but starting the server command is not working. Any idea how can I resolve this issue.

        wls:/offline> connect(‘weblogic’,’welcome2341′,’t3://abc.mdc.ncvnet:7001′)
        Connecting to t3://abc.mdc.ncvnet:7001 with userid weblogic …
        Successfully connected to Admin Server ‘AdminServer’ that belongs to domain ‘ecmdev_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.

        wls:/ecmdev_domain/serverConfig> cd(‘domainRuntime:/ServerLifeCycleRuntimes/capture_server1’)
        wls:/ecmdev_domain/domainRuntime/ServerLifeCycleRuntimes/capture_server1> ls()
        dr– Tasks

        -r– MiddlewareHome /usr/oracle/fmw11g
        -r– Name capture_server1
        -r– NodeManagerRestartCount 0
        -r– State RUNNING
        -r– Type ServerLifeCycleRuntime
        -r– WeblogicHome /usr/oracle/fmw11g/wlserver_10.3

        -r-x forceShutdown WebLogicMBean :
        -r-x forceSuspend WebLogicMBean :
        -r-x getIPv4URL String : String(protocol)
        -r-x getIPv6URL String : String(protocol)
        -r-x preDeregister Void :
        -r-x resume WebLogicMBean :
        -r-x shutdown WebLogicMBean :
        -r-x shutdown WebLogicMBean : Integer(timeout),Boolean(ignoreSessions)
        -r-x start WebLogicMBean :
        -r-x suspend WebLogicMBean :
        -r-x suspend WebLogicMBean : Integer(timeout),Boolean(ignoreSessions)

        wls:/ecmdev_domain/domainRuntime/ServerLifeCycleRuntimes/capture_server1> cmo.forceshutdown
        Traceback (innermost last):
        File “”, line 1, in ?
        AttributeError: ‘javainstance’ object has no attribute ‘forceshutdown’
        wls:/ecmdev_domain/domainRuntime/ServerLifeCycleRuntimes/capture_server1> cmo.forceShutdown()
        [MBeanServerInvocationHandler]com.bea:Name=_0_forceShutdown,Type=ServerLifeCycleTaskRuntime,ServerLifeCycleRuntime=capture_server1
        wls:/ecmdev_domain/domainRuntime/ServerLifeCycleRuntimes/capture_server1> ls()
        dr– Tasks

        -r– MiddlewareHome /usr/oracle/fmw11g
        -r– Name capture_server1
        -r– NodeManagerRestartCount 0
        -r– State FORCE_SHUTTING_DOWN
        -r– Type ServerLifeCycleRuntime
        -r– WeblogicHome /usr/oracle/fmw11g/wlserver_10.3

        -r-x forceShutdown WebLogicMBean :
        -r-x forceSuspend WebLogicMBean :
        -r-x getIPv4URL String : String(protocol)
        -r-x getIPv6URL String : String(protocol)
        -r-x preDeregister Void :
        -r-x resume WebLogicMBean :
        -r-x shutdown WebLogicMBean :
        -r-x shutdown WebLogicMBean : Integer(timeout),Boolean(ignoreSessions)
        -r-x start WebLogicMBean :
        -r-x suspend WebLogicMBean :
        -r-x suspend WebLogicMBean : Integer(timeout),Boolean(ignoreSessions)

        wls:/ecmdev_domain/domainRuntime/ServerLifeCycleRuntimes/capture_server1> ls()
        dr– Tasks

        -r– MiddlewareHome /usr/oracle/fmw11g
        -r– Name capture_server1
        -r– NodeManagerRestartCount 0
        -r– State SHUTDOWN
        -r– Type ServerLifeCycleRuntime
        -r– WeblogicHome /usr/oracle/fmw11g/wlserver_10.3

        -r-x forceShutdown WebLogicMBean :
        -r-x forceSuspend WebLogicMBean :
        -r-x getIPv4URL String : String(protocol)
        -r-x getIPv6URL String : String(protocol)
        -r-x preDeregister Void :
        -r-x resume WebLogicMBean :
        -r-x shutdown WebLogicMBean :
        -r-x shutdown WebLogicMBean : Integer(timeout),Boolean(ignoreSessions)
        -r-x start WebLogicMBean :
        -r-x suspend WebLogicMBean :
        -r-x suspend WebLogicMBean : Integer(timeout),Boolean(ignoreSessions)

        wls:/ecmdev_domain/domainRuntime/ServerLifeCycleRuntimes/capture_server1> cmo.start()
        [MBeanServerInvocationHandler]com.bea:Name=_1_start,Type=ServerLifeCycleTaskRuntime,ServerLifeCycleRuntime=capture_server1

        wls:/ecmdev_domain/domainRuntime/ServerLifeCycleRuntimes/capture_server1> ls()
        dr– Tasks

        -r– MiddlewareHome /usr/oracle/fmw11g
        -r– Name capture_server1
        -r– NodeManagerRestartCount 0
        -r– State SHUTDOWN
        -r– Type ServerLifeCycleRuntime
        -r– WeblogicHome /usr/oracle/fmw11g/wlserver_10.3

        -r-x forceShutdown WebLogicMBean :
        -r-x forceSuspend WebLogicMBean :
        -r-x getIPv4URL String : String(protocol)
        -r-x getIPv6URL String : String(protocol)
        -r-x preDeregister Void :
        -r-x resume WebLogicMBean :
        -r-x shutdown WebLogicMBean :
        -r-x shutdown WebLogicMBean : Integer(timeout),Boolean(ignoreSessions)
        -r-x start WebLogicMBean :
        -r-x suspend WebLogicMBean :
        -r-x suspend WebLogicMBean : Integer(timeout),Boolean(ignoreSessions)

        wls:/ecmdev_domain/domainRuntime/ServerLifeCycleRuntimes/capture_server1>

        Appreciate all your help.

        Script Logs :

        java -cp /usr/oracle/fmw11g/wlserver_10.3/server/lib/weblogic.jar weblogic.WLST ManageStartStop1.py -u weblogic -p welcome1 -a ecmhostdev.mdc.cginet:7001 -n capture_server1 -c stop

        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.

        Successfully connected to the domain

        Location changed to domainRuntime tree. This is a read-only tree with DomainMBean as the root.
        For more help, use help(domainRuntime)
        Server capture_server1 is :RUNNING
        [Server capture_server1 is :FORCE_SUSPENDING
        #Server capture_server1 is :FORCE_SHUTTING_DOWN
        #Server capture_server1 is :FORCE_SHUTTING_DOWN
        #Server capture_server1 is :SHUTDOWN
        #
        Trying To Shutdown Server:capture_server1…
        Error in getting current status of capture_server1

        Please check logged in user has full access to complete the stop operation on capture_server1

        Exiting WebLogic Scripting Tool.

        java -cp /usr/oracle/fmw11g/wlserver_10.3/server/lib/weblogic.jar weblogic.WLST ManageStartStop1.py -u weblogic -p welcome1 -a ecmhostdev.mdc.cginet:7001 -n capture_server1 -c start

        Connecting to t3://abc.mdc.ncvnet:7001 with userid weblogic …
        Successfully connected to Admin Server ‘AdminServer’ that belongs to domain ‘ecmdev_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.

        Successfully connected to the domain

        Location changed to domainRuntime tree. This is a read-only tree with DomainMBean as the root.
        For more help, use help(domainRuntime)
        Server capture_server1 is :SHUTDOWN
        Trying To Start Server:capture_server1…
        Server capture_server1 is :SHUTDOWN
        [Server capture_server1 is :SHUTDOWN ]
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN
        #Server capture_server1 is :SHUTDOWN

  14. prasanth says:

    i want to grab the admin URL of domain when i connect wlst through manage server, is that possible to get this ?i knew domain runtime mbean not available on manage server. but is there alternate way to grab those details

  15. George says:

    i am new to this wlst script. my requirement is to monitor weblogic server status say admin server,oacore_server1 and oaea_server1. if any of the server status gone to shutdown or unknown, we needs to get the alert. could you please provide me the script to do this.

    • Ramakanta says:

      You can create a small shell script to probe for the status of the managed servers and when status is not equal to RUNNING just send an email to some group id. Like below

      /opt/jdk1.5.0_22/bin/java -cp /opt/weblogic/server/lib/weblogic.jar weblogic.Admin -url t3://HOST:7001 GETSTATE oacore_server1

  16. Anastasiia says:

    Hi, Thanks for sharing this script. I was wondering if you could advise on the following
    In my case I have different java parameters per server that have to be loaded before its startup, e.g. :

    . //setwlenv

    I would like to run script with startall command and load specific file per managed server.
    What would be the best way to achieve that?

  17. Suman Kant says:

    Great Script. But i have a difficulty to get an information for Adminserver. Its working fine for managed servers.
    This is the error i am getting while i am trying to pull a status of admin server.

    Connecting to t3://url:port with userid user …
    Successfully connected to Admin Server ‘AdminServer’ that belongs to domain ‘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.

    Successfully connected to the domain

    Location changed to domainRuntime tree. This is a read-only tree with DomainMBean as the root.
    For more help, use help(domainRuntime)
    No stack trace available.
    Error during lifecycle operation of all

    Exiting WebLogic Scripting Tool.

    Please help/guide.

    Regards,
    Suman

    • Ramakanta says:

      Can you elaborate what your code change is, which is showing error?
      Default article code is for managed servers only.

      • Suman Kant says:

        Hi Rama,

        Thank you
        I fixed that issue. How can i add my Adminserver in the list. I want to start/stop/restart my Adminserver with managed servers.

        Regards,
        Suman

        • Ramakanta says:

          For AdminServer you dont need this script… you can just use the startWeblogic.sh and stopWeblogic.sh scripts

          • anil patel says:

            Hi Sir,
            I want to do stoping and starting the Admin server in one script, once i execute the script , it will first stop the admin server if running, then delete the logs and start the server. above script is only for MS.

  18. Sagar says:

    Hi,

    I have the same issue faced by other folks.

    everything is working properly except startup of managed servers. Is it mandatory to start node manager before starting admin and other managed servers?

    Location changed to domainRuntime tree. This is a read-only tree with DomainMBean as the root.
    For more help, use help(‘domainRuntime’)
    Server server1 is :SHUTDOWN
    Trying To Start Server:server1…
    Server server1 is :SHUTDOWN
    Server server1 is :SHUTDOWN
    Server server1 is :SHUTDOWN
    Server server1 is :SHUTDOWN
    Server server1 is :SHUTDOWN
    Server server1 is :SHUTDOWN
    Server server1 is :SHUTDOWN
    ^C

  19. Shazia Aiman says:

    superb script.Great job..:-) .it was very helpful… thank you sir. but it would be pleasure if you help me to solve this issue,,, i’m new to wlst,, i’m a java developer…actually my weblogic server is in another system and i’m running this script in mine using putty, my doubt is without logging into admin server in that system where weblogic server is installed,,, can i start it here using putty ????????? cause when i tried running this script before to check the status of server,, it showed me no stack trace under domain tree and exiting the wlst. and when admin logged into admin server using his credentials ,,then it showed me the status of server. why is it so??? can’t i run this script and get the status of the server ,,even when admin server was not logged in ,,status as its in shutdown state, why?

  20. Shazia Aiman says:

    thank you for the help.
    i have an another doubt.
    while i run this script directly from lib folder where ms.py file is present, it runs successfully and retreive the status of server,, but when i get into wlst scrpting tool and try to execute the same file using the command execfile(‘path of ms.py’)
    it shows error like this ‘missing -u username’
    and prints the usage line nd comes out of wlst

  21. anil patel says:

    Hi Sir,
    I want to do stoping and starting the Admin server in one script, once i execute the script , it will first stop the admin server if running, then delete the logs and start the server. above script is only for MS.

  22. Avi says:

    How or where can I write/find a script to stop and start Managed servers via Admin / Server ? please help

  23. Avi says:

    How or where can I write/find a script to stop and start Managed servers via Admin / Server on windows machine ? please help

  24. Dhanapal Arunodayam says:

    Hi,

    I am testing your script and i get the below error. The java version seems to be ok, I am currently running Weblogic 10.3.

    ./WrapperScript.sh

    Initializing WebLogic Scripting Tool (WLST) …

    Problem invoking WLST – java.lang.UnsupportedClassVersionError: Bad version number in .class file

    java -version
    java version “1.5.0_23”
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_23-b01)
    Java HotSpot(TM) Server VM (build 1.5.0_23-b01, mixed mode)

    Can you please advise a solution?

    • Not sure what you are doing wrong here. UnsupportedClassVersionError means that the Java runtime environment you are using doesn’t recognise the version of a class file that you are trying to execute. The most common cause for this error is trying to use a class file compiled for a newer Java version on an older Java version – for example, you are trying to use a class compiled for Java 6 on a Java 5 runtime environment.

      Can you post the content of WrapperScript.sh file?

  25. Raj says:

    I can invoke the script in my Development environment. In UAT, I am getting authentication issue. Could you please help me?

  26. Jim says:

    Ramakanta – Super awesome script!!!! Thanks so much!!! – I hope you can still answer my question. My current production requirement requires me to always first shutdown the managed servers then the admin server last. Say we have MS1, MS2, MS3 & MS4 – How can I pass multiple servers to the flag -n so I can shutdown all managed servers first as required?

    Thanks so much for your time!

    • You can create a shell script like below:

      export WL_HOME=/shared/oracle/FMW_Home/wlserver_12.1/server/bin
      echo Starting Weblogic 12c – FMW_XPS Domain
      . $WL_HOME/setWLSEnv.sh > /dev/null 2>&1
      java weblogic.WLST manageServers.py -u username -p password -a adminUrl [:] -n ServerName -c [stopall]
      nmConnect(‘NM_user’,’NM_pass’,’NM_host’,’NM_port’,’Domain_Name,’Domain_Directory’,’Connection_type’);
      nmKill(‘Administration Server Name’);
      nmDisconnect();
      exit();
      nmConnect(‘weblogic’,’welcome1′,’localhost’,’5556′,’FMW_XPS’,’/shared/oracle/FMW_Home/user_projects/domains/FMW_XPS’,’plain’);
      nmStart(‘AdminServer’);
      nmDisconnect();
      exit();
      java weblogic.WLST manageServers.py -u username -p password -a adminUrl [:] -n ServerName -c [startall]

  27. John A says:

    Hi thanks again! – How can I execute this script without having to show my credentials? specially I’m interested in hiding the password used to manage. Thanks!

Leave a Reply