Oracle Forms and Reports 11g init startup script

After pulling my hair out searching the web and trying to cobble together shell commands to start and stop Oracle Forms 11g, I finally started playing with nodemanager to script the startup and shutdown. Nodemanager can start and stop all components, except the opmn stuff, and it blocks execution until the service is started. This way I don’t have to try to time stuff correctly using sleep commands and it just works a lot better.

Anyway, put this in a file /etc/init.d/forms and change the environment variables to match your environment.
Then run the following commands to install the script:

chmod 755 /etc/init.d/forms
chkconfig --add /etc/init.d/forms
#!/bin/bash
#
# oracle Init file for starting and stopping Oracle Forms and Reports 11g
#
# chkconfig: 35 95 30
# description: Oracle Forms and Reports 11g startup script

# Source function library
. /etc/rc.d/init.d/functions

# Set Environment
WLS_USER=weblogic
WLS_PW=SUPERSECRET
WLS_DOMAIN=MYDOMAIN
ORACLE_OWNER="oracle"
MIDDLEWARE_HOME="/opt/local/oracle/Middleware"
DOMAIN_HOME="${MIDDLEWARE_HOME}/user_projects/domains/${WLS_DOMAIN}"
WLS_HOME="${MIDDLEWARE_HOME}/wlserver_10.3"
OPMN_CMD="${MIDDLEWARE_HOME}/asinst_1/bin/opmnctl"

# Define and ensure boot.peroperties.
BOOT_PROPERTIES="username=${WLS_USER}\npassword=${WLS_PW}"
mkdir -p ${DOMAIN_HOME}/servers/AdminServer/data/nodemanager
mkdir -p ${DOMAIN_HOME}/servers/WLS_FORMS/data/nodemanager
mkdir -p ${DOMAIN_HOME}/servers/WLS_REPORTS/data/nodemanager
echo -e ${BOOT_PROPERTIES} > ${DOMAIN_HOME}/servers/AdminServer/data/nodemanager/boot.properties
echo -e ${BOOT_PROPERTIES} > ${DOMAIN_HOME}/servers/WLS_FORMS/data/nodemanager/boot.properties
echo -e ${BOOT_PROPERTIES} > ${DOMAIN_HOME}/servers/WLS_REPORTS/data/nodemanager/boot.properties
chown -R oracle.oinstall ${DOMAIN_HOME}/servers/AdminServer/data/nodemanager
chown -R oracle.oinstall ${DOMAIN_HOME}/servers/WLS_FORMS/data/nodemanager
chown -R oracle.oinstall ${DOMAIN_HOME}/servers/WLS_REPORTS/data/nodemanager

# Define NodeManager startup script
START_CMD=$(cat <<EOF
startNodeManager(verbose='true', NodeManagerHome='${WLS_HOME}/common/nodemanager')
nmConnect('${WLS_USER}','${WLS_PW}','localhost','5556','${WLS_DOMAIN}')
nmStart('AdminServer')
arg=\"Arguments=\\\\\" -Dweblogic.management.server=localhost:7001\\\\\"\"
prps=makePropertiesObject(arg)
nmStart('WLS_FORMS',props=prps)
nmStart('WLS_REPORTS',props=prps)
exit()
EOF
)

# Define NodeManager shutdown script
STOP_CMD=$(cat <<EOF
nmConnect('${WLS_USER}','${WLS_PW}','localhost','5556','${WLS_DOMAIN}')
nmKill('WLS_REPORTS')
nmKill('WLS_FORMS')
nmKill('AdminServer')
stopNodeManager()
exit()
EOF
)

start() {
  echo "Starting WLS:"
  su - $ORACLE_OWNER -c "echo \"${START_CMD}\" | ${WLS_HOME}/common/bin/wlst.sh | grep --line-buffered -i 'Error\|Success' | grep -v INFO"
  su - $ORACLE_OWNER -c "${OPMN_CMD} startall"
  echo "OK"
}

stop() {
  echo "Stopping WLS:"
  su - $ORACLE_OWNER -c "${OPMN_CMD} stopall"
  su - $ORACLE_OWNER -c "echo \"${STOP_CMD}\" | ${WLS_HOME}/common/bin/wlst.sh | grep --line-buffered -i 'Error\|Success' | grep -v INFO"
  echo "OK"
}

restart() {
  stop
  start
}


case "$1" in
  start)
    start
  ;;
  stop)
    stop
  ;;
  restart)
    restart
  ;;
  *)
    echo $"Usage: $0 {start|stop|restart}"
esac

One thought on “Oracle Forms and Reports 11g init startup script”

  1. Very useful blog. I too got alomst 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.pyimport sysimport osimport timedef 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 continuedisconnect() # 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] raisetry: # 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() raiseDomain stop script: StopWlsDomains.pyimport sysimport osimport timedef 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] raisetry: # 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() raiseCheersNarayana

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>