When configured, there are scripts to start and stop the system components in the bin folder of the domain: startComponent.sh and stopComponent.sh.
These scripts first do a readDomain() to read the domain before actually starting or stopping the component. An OHS Standalone Domain is not that large, but does take a few seconds. With an embedded OHS it can actually a quite expensive operation. And is done twice when you need to stop and start a component. And that per component.
So, this can be smarter. Yesterday, I created a script that first looks for a property in the property file, that lists the possible components as a comma seperated list. It only does a readDomain() when that property is not defined.
The property file ohs.properties contains:
############################################################################# # Set OHS SA Domain properties # # @author Martien van den Akker, Darwin-IT Professionals # @version 1.0, 2017-02-20 # ############################################################################# # #Per domain nodemanager... nmHome=/u01/data/oracle/config/domains/ohs_domain/nodemanager nmHost=localhost nmPort=5555 nmType=plain # #Domain wlsDomainName=ohs_domain wlsDomainsHome=/u01/data/oracle/config/domains # #AdminServer adminUser=weblogic adminPwd=welcome1 #usrCfgFile=wlsCfgFile #usrKeyFile=wlsKeyFile # # OHS Component List ohsComponents=ohs1
The wlst script startStopOhs.py is:
############################################################################# # Start OHS via NodeManager. # # @author Martien van den Akker, Darwin-IT Professionals # @version 1.0, 2017-03-01 # ############################################################################# # Modify these values as necessary import sys, traceback scriptName = sys.argv[0] # # lineSeperator='__________________________________________________________________________________' # # def usage(): print 'Call script as: ' print 'Windows: wlst.cmd '+scriptName+' -loadProperties localhost.properties' print 'Linux: wlst.sh '+scriptName+' -loadProperties environment.properties' print 'Property file should contain the following properties: ' print "adminUrl=localhost:7101" print "adminUser=weblogic" print "adminPwd=welcome1" # # def connectToNM(nmHost, nmPort, nmHome, wlsDomainName, wlsDomainHome, nmType): try: print(lineSeperator) print('Try to connect to the Node Manager') nmConnect(username=adminUser, password=adminPwd, host=nmHost, port=nmPort, domainName=wlsDomainName, domainDir=wlsDomainHome, nmType=nmType) print('Connected to the Node Mananger') except WLSTException: message='Apparently NodeManager not Started!' print (message) raise Exception(message) # # def getSystemComponents(wlsDomainHome): try: print(lineSeperator) print('Get SystemComponents') try: sysComps=ohsComponents.split(',') except NameError, e: print 'Property ohsComponents not set, read from Domain' print('Read domain from : '+wlsDomainHome) readDomain(wlsDomainHome) cd('/SystemComponent') sysComps=ls(returnMap='true') return sysComps except WLSTException: message='Exception getting SystemComponents' print (message) raise Exception(message) # # Start a System Component def startSystemComponent(sysComp): try: print(lineSeperator) print('StartSystemComponent '+sysComp) nmStart(serverName=sysComp, serverType='OHS') except WLSTException: message='Exception starting SystemComponent: '+sysComp print (message) raise Exception(message) # # Stop a System Component def stopSystemComponent(sysComp): try: print(lineSeperator) print('StartSystemComponent '+sysComp) nmKill(serverName=sysComp, serverType='OHS') except WLSTException: message='Exception stopping SystemComponent: '+sysComp print (message) raise Exception(message) # # Start, restart or stop System Components, based on startStopOption. def startStopSystemComponents(startStopOption, sysComps): try: print(lineSeperator) print('StartSystemComponents') if startStopOption=="stop" or startStopOption=="restart": for sysComp in sysComps: stopSystemComponent(sysComp) if startStopOption=="start" or startStopOption=="restart": for sysComp in sysComps: startSystemComponent(sysComp) except WLSTException: message='Exception starting or stopping SystemComponents, startStopOption:'+startStopOption print (message) raise Exception(message) # # def main(): try: startStopOption=sys.argv[1] wlsDomainHome = wlsDomainsHome+'/'+wlsDomainName print(lineSeperator) if startStopOption=="start" or startStopOption=="restart": print('(Re)Start OHS for domain in : '+wlsDomainHome+', with option '+startStopOption) else: print('Stop OHS for domain in : '+wlsDomainHome+', with option '+startStopOption) print(lineSeperator) print ('Connect to the Node Manager') connectToNM(nmHost, nmPort, nmHome, wlsDomainName, wlsDomainHome, nmType) # systemComponents=getSystemComponents(wlsDomainHome) # startStopSystemComponents(startStopOption, systemComponents) except NameError, e: print('Apparently properties not set.') print "Please check the property: ", sys.exc_info()[0], sys.exc_info()[1] usage() except: apply(traceback.print_exception, sys.exc_info()) exit(exitcode=1) # main();
It uses a startStopOption that can have the values:
- start
- restart
- stop
So, this time I only have one wlst script. I could make my weblogic server start scripts smarter the same way...
To start the ohs you can use startOhs.sh:
#!/bin/bash . ./ohs12c_env.sh echo echo Start OHS wlst.sh ./startStopOhs.py start -loadProperties ohs.properties
To restart the ohs you can use restartOhs.sh:
#!/bin/bash . ./ohs12c_env.sh echo echo Restart OHS wlst.sh ./startStopOhs.py restart -loadProperties ohs.properties
And to stop the ohs you can use stopOhs.sh:
#!/bin/bash . ./ohs12c_env.sh echo echo Stop OHS wlst.sh ./startStopOhs.py stop -loadProperties ohs.properties
With a OHS Standalone domain, you probably have stored the nodemanager credentials once with the storeConfig option. In that case you can remove the credentials in the nmConnnect line:
#nmConnect(username=adminUser, password=adminPwd, host=nmHost, port=nmPort, domainName=wlsDomainName, domainDir=wlsDomainHome, nmType=nmType) nmConnect(host=nmHost, port=nmPort, domainName=wlsDomainName, domainDir=wlsDomainHome, nmType=nmType)
For a standalone OHS the ohs12c_env.sh script contains:
#!/bin/bash echo set OHS StandAlone 12cR2 environment #export JAVA_HOME=/usr/java/jdk1.8.0_101 #export ORACLE_BASE=/app/oracle export ORACLE_BASE=/u01/app/oracle export OHS_HOME=$ORACLE_BASE/product/middleware/OHS12212 export WL_HOME=${OHS_HOME}/wlserver export SHARED_CONFIG_DIR=/u01/data/oracle/config export OHS_DOMAIN_NAME=ohs_domain export OHS_DOMAIN_HOME=$SHARED_CONFIG_DIR/domains/$OHS_DOMAIN_NAME export NODEMGR_HOME=$OHS_DOMAIN_HOME/nodemanager # echo Set Weblogic Common Env. . $OHS_HOME/oracle_common/common/bin/commEnv.sh # export PATH=$OHS_HOME/oracle_common/common/bin:$PATH
No comments :
Post a Comment