Comments on: WebLogic 11g start and stop automation https://technology.amis.nl/2011/09/27/weblogic-11g-start-and-stop-automation/ Friends of Oracle and Java Sat, 25 Apr 2015 11:36:47 +0000 hourly 1 http://wordpress.org/?v=4.2 By: Narayana https://technology.amis.nl/2011/09/27/weblogic-11g-start-and-stop-automation/#comment-7070 Tue, 13 Mar 2012 09:03:14 +0000 http://technology.amis.nl/blog/?p=13423#comment-7070 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

]]>
By: Michel Schildmeijer https://technology.amis.nl/2011/09/27/weblogic-11g-start-and-stop-automation/#comment-6883 Sat, 04 Feb 2012 10:48:59 +0000 http://technology.amis.nl/blog/?p=13423#comment-6883 #4
I will provide it soon to you

]]>
By: Michel Schildmeijer https://technology.amis.nl/2011/09/27/weblogic-11g-start-and-stop-automation/#comment-6882 Sat, 04 Feb 2012 10:48:25 +0000 http://technology.amis.nl/blog/?p=13423#comment-6882 #9 see comment #4
pwd should be the current diryou also could make a variable like:scriptdir=<path to your scripts>

]]>
By: TechUpdates https://technology.amis.nl/2011/09/27/weblogic-11g-start-and-stop-automation/#comment-6881 Thu, 02 Feb 2012 12:33:05 +0000 http://technology.amis.nl/blog/?p=13423#comment-6881 Should pwd be the home directory?

]]>
By: Helen https://technology.amis.nl/2011/09/27/weblogic-11g-start-and-stop-automation/#comment-6880 Mon, 30 Jan 2012 18:39:23 +0000 http://technology.amis.nl/blog/?p=13423#comment-6880 Can you share the code for chkwlsrvr

]]>
By: balu https://technology.amis.nl/2011/09/27/weblogic-11g-start-and-stop-automation/#comment-6879 Wed, 11 Jan 2012 23:40:43 +0000 http://technology.amis.nl/blog/?p=13423#comment-6879 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
 

]]>
By: Michel Schildmeijer https://technology.amis.nl/2011/09/27/weblogic-11g-start-and-stop-automation/#comment-6878 Sun, 30 Oct 2011 13:14:17 +0000 http://technology.amis.nl/blog/?p=13423#comment-6878 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

]]>
By: Ismail Lalji https://technology.amis.nl/2011/09/27/weblogic-11g-start-and-stop-automation/#comment-6877 Thu, 27 Oct 2011 03:32:20 +0000 http://technology.amis.nl/blog/?p=13423#comment-6877 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.

]]>
By: Michel Schildmeijer https://technology.amis.nl/2011/09/27/weblogic-11g-start-and-stop-automation/#comment-6876 Wed, 19 Oct 2011 13:45:07 +0000 http://technology.amis.nl/blog/?p=13423#comment-6876 pwd should be the current dir
you also could make a variable like:
scriptdir=<path to your scripts>
 
 

]]>
By: Loukas https://technology.amis.nl/2011/09/27/weblogic-11g-start-and-stop-automation/#comment-6875 Thu, 13 Oct 2011 12:31:40 +0000 http://technology.amis.nl/blog/?p=13423#comment-6875 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

]]>
By: Loukas https://technology.amis.nl/2011/09/27/weblogic-11g-start-and-stop-automation/#comment-6874 Thu, 13 Oct 2011 12:09:46 +0000 http://technology.amis.nl/blog/?p=13423#comment-6874 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

]]>
By: Loukas https://technology.amis.nl/2011/09/27/weblogic-11g-start-and-stop-automation/#comment-6873 Thu, 13 Oct 2011 08:54:44 +0000 http://technology.amis.nl/blog/?p=13423#comment-6873 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

]]>