WebLogic 11g start and stop automation

There are many ways of starting and stopping your Oracle WebLogic 11g  environments, You can stop your Admin and Managed Server Instances through the Adminsitration console, use the the start and stop scripts shipped with the Oracle WebLogic software and domain creation, or use a tool like WLST to manipulate your entire environment.

In this blog I will  use the different kinds of techniques to stop and start your Oracle WebLogic Server environment, even in case of a physical host reboot (planned or unplanned)

For this I used the common UNIX shell scripting in combination with WLST

The bundle consists of the following components:

  • weblogic_rc.sh start|stop|status –> Overall shellscript which calls the different scripts for stopping and starting. This can be added to the bootsequence of the physical host, which varies per O/S ( Linux-init.d, AIX- rc) Ask you O/S admin how to implement it). Your OS profile needs to be set as well, so set some variables like MW_HOME. WL_DOMAIN and WL_DOMAIN_DIR, and ORACLE_HOME
  • nodemgrstart and nodemgrstop –> python/WLST scripts for starting the Node Manager. Can be invoked with or without the overall script. First set the setWLSEnv.sh or the setDomainEnv.sh to issue the correct environmentsettings. Execute:

java weblogic.WLST nodemanagerstart / nodemanagerstop

  • wl11gstart and wl11gstop > python/WLST scripts for starting the WebLogic Server Instances. Can be invoked with or without the overall script. First set the setWLSEnv.sh or the setDomainEnv.sh to issue the correct environmentsettings. Execute:

java weblogic.WLST wl11gstart / wl11gstop

See the scripts below:

  • weblogic_rc.sh:

#!/bin/sh
#
# Start and stop script for an entire Oracle FMW Forms 11g environment
# Tobe added to the rebootsequence of the AIX LPAR.
#
#

#
#
PWD=`pwd`
if [ "$USER" != 'root' -a "$USER" != 'orawl' -a "$USER" != '' ]; then echo $BAD_USER && exit 1;fi
if [ "$USER" == 'root' -o "$USER" == '' ]; then WL_DOMAIN_DIR=`su - orawl -c 'echo $WL_DOMAIN_DIR'`;fi
if [ "$USER" == 'root' -o "$USER" == '' ]; then WL_NM_PORT=`su - orawl -c 'echo $WL_NM_PORT'`;fi
if [ "$USER" == 'root' -o "$USER" == '' ]; then WL_HOME=`su - orawl -c 'echo $WL_HOME'`;fi
. ~/.profile
case "$1" in
start)
echo Starting the Nodemanager
java weblogic.WLST $PWD/nodemgrstart
sleep 20
echo  Starting AdminServer on WebLogic Domain $DOMAIN
nohup $WL_DOMAIN_DIR/startWebLogic.sh & > /dev/null 2>&1 &
sleep 120
#
echo Starting the the Managed Server Instances on WebLogic Domain $DOMAIN
java weblogic.WLST $PWD/wl11gstart
;;
stop)
echo WebLogic Server instances
java weblogic.WLST $PWD/wl11gstop
sleep 60
echo  Stopping AdminServer on WebLogic Domain $DOMAIN
$WL_DOMAIN_DIR/bin/stopWebLogic.sh
echo Stopping the Nodemanager
java weblogic.WLST $PWD/nodemgrstop
;;
status)
echo checking runtime status
java weblogic.WLST $PWD/chkwlsrvr
;;
* )
echo "Usage: $0 (start | stop | status)"
exit 1
esac
  • nodemanager start
#### Created by Michel Schildmeijer
# Credentials and constants
username = 'weblogic'
password = '<passwd>'
import socket
localhost = socket.getaddrinfo(socket.gethostname(), None)[0][4][0]
import os
domain = os.getenv('WL_DOMAIN')
mwHome = os.getenv('MW_HOME')
print mwHome
#
# Derived constants
url = 't3://' + localhost + ':7001'
domain_dir = mwHome + '/user_projects/domains/' + domain
nmhome = mwHome + '/wlserver_10.3/common/nodemanager'
nmpfile = mwHome + '/wlserver_10.3/common/nodemanager/nodemanager.properties'
nmPort='5556'
# Loop through the managed servers and stop all servers running on localhost
print '-- CONNECT TO NODE MANAGER AND START IT --';
nmConnect(username, password, localhost, nmPort, domain, domain_dir)
#Start the nodemanager
startNodeManager(NodeManagerHome=nmhome,PropertiesFile=nmpfile)
  • nodemanager stop
<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;"><span style="line-height: 19px;">
</span></span>#### Created by Michel Schildmeijer
# Function to get server state
def serverStatus(server):
  cd('/ServerLifeCycleRuntimes/' + server.getName() )
  return cmo.getState()
#
def stopAdminserver():
  nmConnect(username, password, 'localhost', 5556, domain, domain_dir)
  nmStop('AdminServer')
  nmDisconnect()
# End of functions
# Credentials and constants
username = 'weblogic'
password = '&lt;passwd&gt;'
import socket
localhost = socket.getaddrinfo(socket.gethostname(), None)[0][4][0]
import os
domain = os.getenv('WL_DOMAIN')
mwHome = os.getenv('MW_HOME')
print mwHome
#
# Derived constants
url = 't3://' + localhost + ':7001'
domain_dir = mwHome + '/user_projects/domains/' + domain
nmhome = mwHome + '/wlserver_10.3/common/nodemanager'
nmpfile = mwHome + '/wlserver_10.3/common/nodemanager/nodemanager.properties'
nmPort='5556'
# Loop through the managed servers and stop all servers running on localhost
print '-- CONNECT TO NODE MANAGER AND STOP IT --';
nmConnect(username, password, localhost, nmPort, domain, domain_dir)
#stop the nodemanager if running
stopNodeManager()
  • wl11gstart
#### Generic Oracle WebLogic 11g Start Script
#### Created by Michel Schildmeijer
# Credentials and constants
username='weblogic'
password='&lt;passwd&gt;'
import socket
localhost = socket.getaddrinfo(socket.gethostname(), None)[0][4][0]
import os
domain = os.getenv('WL_DOMAIN')
domaindir= os.getenv('WL_DOMAIN_DIR')
mwHome = os.getenv('MW_HOME')
url = 't3://' + localhost + ':7001'
domain_dir = mwHome + '/user_projects/domains/' + domain
nmhome = mwHome + '/wlserver_10.3/common/nodemanager'
nmpfile = mwHome + '/wlserver_10.3/common/nodemanager/nodemanager.properties'
# Function to get server state
def serverStatus(server):
cd('/ServerLifeCycleRuntimes/' + server.getName() )
return cmo.getState()
#
def startAdminserver():
nmConnect(username, password, localhost, 5556, domain, domain_dir)
nmStart('AdminServer')
nmDisconnect()
# End of functions
# Connect to the AdminServer
try:
connect(username, password, url)
except:
# AdminServer is not running. Start it now and retry
startAdminserver()
connect(username, password, url)
# Loop through the managed servers and start all servers running on localhost
svrs = cmo.getServers()
domainRuntime()
for server in svrs:
# Do not start the adminserver, it's already running
if server.getName() != 'AdminServer':
# Get state and machine
serverState = serverStatus(server)
machine = server.getListenAddress()
print server.getName() + " has now the status " + serverState + " on " + machine
#
# startup if needed
if serverState == "SHUTDOWN":
if machine == localhost:
start(server.getName(),'Server')
serverState = serverStatus(server)
print "Now " + server.getName() + " is " + serverState + " on " + machine
disconnect()
exit()
  • wl11gstop
#### Created by Michel Schildmeijer

# Function to get server state

def serverStatus(server):

  cd('/ServerLifeCycleRuntimes/' + server.getName() )
  return cmo.getState()
#
def stopAdminserver():
  nmConnect(username, password, 'localhost', 5556, domain, domain_dir)
  nmStop('AdminServer')
  nmDisconnect()
# End of functions
#

# credentials and constants

username = 'weblogic'
password = '&lt;passwd&gt;'
import socket
localhost = socket.getaddrinfo(socket.gethostname(), None)[0][4][0]
import os
domain = os.getenv('WL_DOMAIN')
mwHome = os.getenv('MW_HOME')
print mwHome

#

# Derived constants
url = 't3://' + localhost + ':7001'
domain_dir = mwHome + '/user_projects/domains/' + domain
nmhome = mwHome + '/wlserver_10.3/common/nodemanager'
nmpfile = mwHome + '/wlserver_10.3/common/nodemanager/nodemanager.properties'
nmPort='5556'

## Connect to the AdminServer

try:
  connect(username, password,url)
except:
  # AdminServer is not running. Start it now and retry
  #stopAdminserver()
  connect(username, password,url)
# Loop through the managed servers and stop all servers running on localhost
print '-- CONNECT TO NODE MANAGER AND ADMINSERVER --';
nmConnect(username, password, localhost, nmPort, domain, domain_dir)
domainRuntime()
serverLifeCycles = cmo.getServerLifeCycleRuntimes()
for serverLifeCycle in serverLifeCycles:
        if (serverLifeCycle.getState() == 'RUNNING') and (serverLifeCycle.getName() != 'AdminServer' ):
                print 'Stopping Server: ' + serverLifeCycle.getName()
                shutdown  (serverLifeCycle.getName())
disconnect()

exit()


							

Leave a Reply

  1. Very useful blog. I too got almost similar script.

    Look at my script. May be useful.

    Note: The domain should have been enabled with NM including Admin Server.
    Domain Start script: StartWlsDomains.py

    import sys
    import os
    import time

    def wlsDomainStart(userconfigFile,userkeyFile,adminUrl,nmHost,nmPort,DomainName,DomainDir):
    try:
    print ‘ ##### Connecting to Nodemanager:: ‘+ nmHost +':’+ nmPort+’ ####’
    nmConnect(userConfigFile=userconfigFile,userKeyFile=userkeyFile,host=nmHost,port=nmPort,domainName=DomainName,domainDir=DomainDir,nmType=’ssl’)
    nmStatus=nm()
    if (nmStatus == true):
    serverStatus=nmServerStatus(‘AdminServer’)
    if (serverStatus == ‘RUNNING’):
    print ‘ ##### The AdminServer is already running #####’
    elif (serverStatus == ‘STARTING’):
    java.lang.Thread.sleep(20000)
    else:
    print ‘ ##### The AdminServer is not running. About to start now. Wait… #####’
    nmStart(‘AdminServer’)

    serverStatus=nmServerStatus(‘AdminServer’)
    if (serverStatus == ‘RUNNING’):
    #print ‘ ##### The AdminServer is up and running now #####’
    connect(userConfigFile=userconfigFile,userKeyFile=userkeyFile,url=adminUrl)

    domainConfig()
    serverNames = cmo.getServers()
    domainRuntime()
    for name in serverNames:
    try:
    cd(‘/’)
    server=str(name.getName())
    slrBean = cmo.lookupServerLifeCycleRuntime(server)
    serverStatus = slrBean.getState()
    #print ‘Server State is ‘+ serverStatus
    if (server != ‘AdminServer’):
    if (serverStatus == ‘RUNNING’):
    print ‘ ##### The ‘+ server + ‘ is already running #####’
    elif (serverStatus == ‘STARTING’):
    print ‘ ##### The ‘+ server + ‘ is in ‘+serverStatus+’ state’
    else:
    print ‘ ##### The ‘+ server + ‘ is about to Start’
    start(server,’Server’, block=’false’)
    except:
    print “Skipping “+server
    continue

    print ‘Please wait for 2 mins to re-check the state of the servers and give a restart if its not started properly in the above step’
    java.lang.Thread.sleep(200000)

    for name in serverNames:
    try:
    cd(‘/’)
    server=str(name.getName())
    slrBean = cmo.lookupServerLifeCycleRuntime(server)
    serverStatus = slrBean.getState()
    if (server != ‘AdminServer’):
    if (serverStatus == ‘RUNNING’):
    print ‘ ##### The ‘+ server + ‘ is started properly #####’
    elif (serverStatus == ‘STARTING’):
    print ‘ ##### The ‘+ server + ‘ is in ‘+serverStatus+’ state and Leaving it to come up’
    elif (serverStatus == ‘ADMIN’):
    print ‘ ##### The ‘+ server + ‘ is in ‘+serverStatus+’ state and about to resume’
    resume(server, block=’false’)
    elif (serverStatus == ‘RESUMING’):
    print ‘ ##### The ‘+ server + ‘ is in ‘+serverStatus+’ state and aLeaving it to come up’
    elif (serverStatus == ‘SHUTDOWN’):
    print ‘ ##### The ‘+ server + ‘ is in ‘+serverStatus+’ state and not properly started. Its about to restart’
    start(server,’Server’, block=’false’)
    else:
    print ‘ ##### The ‘+ server + ‘ is not started properly and about to start again’
    shutdown(server,’Server’, force=’true’, block=’true’)
    start(server,’Server’, block=’false’)
    except:
    print “Skipping “+server
    continue
    disconnect() # Disconnect from AdminServer
    nmDisconnect() # Disconnect from NM
    else:
    print ‘ ##### Not Connecting to NodeManager. Please check whether its running at ‘+ nmHost +':’+ nmPort+’ #####’
    exit()
    except:
    print “Unexpected error:”, sys.exc_info()[0]
    raise

    try:
    # Start Weblogic Server Through NM
    # arguments: userconfigfile userkeyfile adminUrl
    wlsDomainStart(sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4],sys.argv[5],sys.argv[6],sys.argv[7])

    except:
    print “Unexpected error: “, sys.exc_info()[0]
    dumpStack()
    raise

    Domain stop script: StopWlsDomains.py

    import sys
    import os
    import time

    def wlsDomainStop(userconfigFile,userkeyFile,adminUrl,nmHost,nmPort,DomainName,DomainDir):
    try:
    print ‘ ##### Connecting to Nodemanager:: ‘+ nmHost +':’+ nmPort+’ ####’
    nmConnect(userConfigFile=userconfigFile,userKeyFile=userkeyFile,host=nmHost,port=nmPort,domainName=DomainName,domainDir=DomainDir,nmType=’ssl’)
    nmStatus=nm()
    if (nmStatus == true):
    serverStatus=nmServerStatus(‘AdminServer’)
    if (serverStatus == ‘RUNNING’):
    print ‘ ##### The AdminServer is already running #####’
    elif (serverStatus == ‘STARTING’):
    java.lang.Thread.sleep(20000)
    else:
    print ‘ ##### The AdminServer is not running. About to start now. Wait… #####’
    nmStart(‘AdminServer’)

    serverStatus=nmServerStatus(‘AdminServer’)
    if (serverStatus == ‘RUNNING’):
    #print ‘ ##### The AdminServer is up and running now #####’
    connect(userConfigFile=userconfigFile,userKeyFile=userkeyFile,url=adminUrl)

    domainConfig()
    serverNames = cmo.getServers()
    domainRuntime()
    for name in serverNames:
    try:
    cd(‘/’)
    server=str(name.getName())
    slrBean = cmo.lookupServerLifeCycleRuntime(server)
    serverStatus = slrBean.getState()
    if (server != ‘AdminServer’):
    if (serverStatus == ‘RUNNING’):
    print ‘ ##### The ‘+ server + ‘ is about to stop #####’
    shutdown(server,’Server’, force=’true’, block=’true’)
    elif (serverStatus == ‘STARTING’):
    print ‘ ##### The ‘+ server + ‘ is in ‘+serverStatus+’ state. anf is about to stop now’
    shutdown(server,’Server’, force=’true’, block=’true’)
    else:
    print ‘ ##### The ‘+ server + ‘ is not running and its state is ‘+serverStatus
    except:
    print “Skipping “+server
    continue

    print ‘ Please wait for 10 seconds to re-check the state of the servers and shutdown if its not shutdown properly above’
    java.lang.Thread.sleep(10000)

    for name in serverNames:
    try:
    cd(‘/’)
    server=str(name.getName())
    slrBean = cmo.lookupServerLifeCycleRuntime(server)
    serverStatus = slrBean.getState()
    if (server != ‘AdminServer’):
    if (serverStatus == ‘SHUTDOWN’):
    print ‘ ##### The ‘+ server + ‘ is stopped properly #####’
    elif (serverStatus == ‘SHUTTING_DOWN’):
    print ‘ ##### The ‘+ server + ‘ is in ‘+serverStatus+’ state and Leaving it to Shutdown’
    elif (serverStatus == ‘FORCE_SUSPENDING’):
    print ‘ ##### The ‘+ server + ‘ is in ‘+serverStatus+’ state and Leaving it to Shutdown’
    elif (serverStatus == ‘FORCE_SHUTTING_DOWN’):
    print ‘ ##### The ‘+ server + ‘ is in ‘+serverStatus+’ state and Leaving it to Shutdown’
    else:
    print ‘ ##### The ‘+ server + ‘ is not stopped properly and about to shutdown again’
    #nmKill(server)
    shutdown(server,’Server’, force=’true’, block=’true’)
    except:
    print “Skipping “+server
    continue

    #print ‘ Stopping AdminServer of the domain’
    shutdown(‘AdminServer’)
    disconnect() # Disconnect from AdminServer
    nmDisconnect()
    else:
    print ‘ ##### Not Connecting to NodeManager. Please check whether its running at ‘+ nmHost +':’+ nmPort+’ #####’
    exit()
    except:
    print “Unexpected error:”, sys.exc_info()[0]
    raise

    try:
    # Start Weblogic Server Through NM
    # arguments: userconfigfile userkeyfile adminUrl
    wlsDomainStop(sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4],sys.argv[5],sys.argv[6],sys.argv[7])

    except:
    print “Unexpected error: “, sys.exc_info()[0]
    dumpStack()
    raise

    Cheers
    Narayana

  2. #9 see comment #4
    pwd should be the current diryou also could make a variable like:scriptdir=<path to your scripts>

  3. Hi i shutdowned managed1, managed2 and normal shutdown of Weblogic 8.1 version, but now i can’t able to login in to server. pls help me how to start server
     

  4. Ismail
    Why does one want to workaround the nmConnect?
    Furthermore you do a count  on all the network interfaces; this not a quite the way to detect if a nodemanager is running or not

  5. One can “work around” the initial nmConnect  by using:
    if [[ `ifconfig -a |grep $localhost |wc -l ` -eq 0 ]]; then
    echo Node Manager not running
    exit 1
    fi
    Alternately substitute the:
    java weblogic.WLST $PWD/nodemgrstart
    in lieu of the exit 1 – depends on what you want to do.

  6. pwd should be the current dir
    you also could make a variable like:
    scriptdir=<path to your scripts>
     
     

  7. Sorry Michel..forget my comment about the passwd…I have got  the hint from a colleague to encrypt it. Many thanks in any case.
    Loukas

  8. Hello again Michel,
    I also tried individually your nodemanagerstart script and apparently you are trying a nmConnect before starting the Nodemanager. This will not work if the NM is down. It will trhow an error in the nmConnect command. I believe this command has to be taken out .
    brgds,
    Loukas

  9. Hi Michel,
    very nice script which I am trying to modify and adapt to our environment. 1 question: where the PWD is defined? I do not really get the PWD=`pwd`
    Brgds,
    Loukas