WebLogic 11g start and stop automation

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()

你可能感兴趣的:(automation)