Skip to content

DBAzine.com

Sections
Personal tools
You are here: Home » Oracle » Oracle Articles Archive » DBA Scripts to Manage Oracle Application Server
Seeking new owner for this high-traffic DBAzine.com site.
Tap into the potential of this DBA community to expand your business! Interested? Contact us today.
Who Are You?
I am a:
Mainframe True Believer
Distributed Fast-tracker

[ Results | Polls ]
Votes : 3549
 

DBA Scripts to Manage Oracle Application Server

by Donald K. Burleson and John Garmany

You can automate many areas of Oracle Application Server administration using scripts.  Here is an example of a command list to start the iasdb database, the listener, the infrastructure instance, a midtier instance, and the Enterprise Manager Web site on both instances.

echo Setting Env for Infrastructure
source envInfra.sh
echo Starting Listener
$ORACLE_HOME/bin/lsnrctl start
echo Starting Database
$ORACLE_HOME/bin/sqlplus /nolog<<EOF
connect / as sysdba
startup
EOF
echo Starting all opmnctl controlled processes
$ORACLE_HOME/opmn/bin/opmnctl startall
echo Starting the EM website
#$ORACLE_HOME/bin/emctl start em
echo Setting Env for MidTier Instance
source envMidtier.sh
echo Starting all opmnctl controlled processes
$ORACLE_HOME/opmn/bin/opmnctl startall
echo Starting the EM website
#$ORACLE_HOME/bin/emctl start em
echo Startup Completed

By themselves, the command list is not very useful, but it becomes very powerful when embedded into a shell script. The source envMidtier.sh  statement changes the ORACLE_HOME environmental variable.  Each instance or Oracle Application Server must be installed in its own ORACLE_HOME.  This is covered in Chapter 2.

Because The Oracle Application Server command line utilities exist in many locations, it is critical that you set up your OS environment so that your scripts will be able to locate all of the utilities.  Here are examples of the proper PATH commands for UNIX and Windows.  These are normally placed in the startup shell script to be executed at sign-on time.

UNIX PATH Setup

ORACLE_HOME=/u01/app/oracle/product/9.2.0
export ORACLE_HOME
PATH=.:$PATH:.;$ORACLE_HOME/dcm/bin/:$ORACLE_HOME/j2ee/home/:$ORACLE_HOME/ldap/bin/:$
ORACLE_HOME/ldap/odi/admin/:$ORACLE_HOME/oca/bin/:$ORACLE_HOME/opmn/bin/:$ORACLE_HOME
/portal/admin/plsql/sso/:$ORACLE_HOME/sso/lib/:$ORACLE_HOME/uddi/lib/:$ORACLE_HOME/up
grade/:$ORACLE_HOME/wireless/bin/

Windows PATH Setup

Set ORACLE_HOME=c:\oracle\ora92
SETPATH=.;$PATH;%ORACLE_HOME%\dcm\bin\;%ORACLE_HOME%\j2ee\home\;%ORACLE_HOME%\ldap\bi
n\;%ORACLE_HOME%\ldap\odi\admin\;%ORACLE_HOME%\oca\bin\;%ORACLE_HOME%\opmn\bin\;%ORAC
LE_HOME%\portal\admin\plsql\sso\;%ORACLE_HOME%\sso\lib\;%ORACLE_HOME%\uddi\lib\;%ORAC
LE_HOME%\upgrade\;%ORACLE_HOME%\wireless\bin\

Once we have established the PATH variable we are able to create shell script that can be submitted in batch mode (in UNIX with the nohup command) to automate Oracle Application Server administrative tasks.  For example, an Oracle Application Server management shell script could be scheduled in the UNIX crontab to perform a scheduled shutdown of all Oracle Application Server services.

Of course, the PATH variable is only a part of an Oracle Application Server script, and the complete environment including ORACLE_BASE, ORACLE_HOME and ORACLE_SID must be enabled.  The env.ksh script shows a common environmental setting for Oracle Application Server command scripts.  Note that $ORACLE_HOME is set to ORACLE_BASE/midtier for mid-tier command scripts and ORACLE_BASE/infra for infrastructure command scripts.  Every Oracle Application Server Instance must be installed in a unique ORACLE_HOME and startup/shutdown scripts must set the environment variables for that instance.

env.sh

#!/bin/ksh 
export ORACLE_BASE=/private/ias
# Use this ORACLE_HOME for midtier applications
#export ORACLE_HOME=$ORACLE_BASE/midtier
# Use this ORACLE_HOME for infra applications
export ORACLE_HOME=$ORACLE_BASE/infra
SETPATH=.;$PATH;%ORACLE_HOME%\dcm\bin\;%ORACLE_HOME%\j2ee\home\;%ORACLE_HOME%\ldap\bi
n\;%ORACLE_HOME%\ldap\odi\admin\;%ORACLE_HOME%\oca\bin\;%ORACLE_HOME%\opmn\bin\;%ORAC
LE_HOME%\portal\admin\plsql\sso\;%ORACLE_HOME%\sso\lib\;%ORACLE_HOME%\uddi\lib\;%ORAC
LE_HOME%\upgrade\;%ORACLE_HOME%\wireless\bin\
export ORACLE_SID=iasdb
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
#export DISPLAY=tor:2.0
    
echo ORACLE_HOME : $ORACLE_HOME
echo ORACLE_SID  : $ORACLE_SID
echo DISPLAY     : $DISPLAY
echo Set PATH and LD_LIBRARY_PATH

Here is a script to submit when there is a problem with OHS and you need to re-start it.  Some Oracle Application Server administrators place Apache user-exit code to automate the bouncing of the OHS.  For example, if an external connection fails to attach to an OHS listener, after 10 seconds the following code could be automatically invoked to bounce OHS.

bounce_ohs.ksh

#*****************************************************************
# Copyright (c) 2003 by Donald K. Burleson
#
#*****************************************************************
# Exit if no first parameter $1
if [ -z "$1" ]
then
   echo "ERROR: Please pass a valid ORACLE_SID to this script"
   exit 99
fi
# Validate Oracle
TEMP=`cat /etc/oratab|grep \^$1:|cut -f1 -d':'|wc -l`
tmp=`expr TEMP`            # Convert string to number
if [ $tmp -ne 1 ]
then
   echo
   echo "ERROR: Your input parameter $1 is invalid.  Please Retry"
   echo
   exit 99
fi


if [ `whoami` != 'oracle' ]
then
   echo "Error: You must be oracle to execute the script.  Exiting."
   exit
fi
# First, we must set the environment . . . .
export ORACLE_BASE=/private/ias
# Use this ORACLE_HOME for midtier applications
#export ORACLE_HOME=$ORACLE_BASE/midtier
# Use this ORACLE_HOME for infra applications
export ORACLE_HOME=$ORACLE_BASE/infra
SETPATH=.;$PATH;%ORACLE_HOME%\dcm\bin\;%ORACLE_HOME%\j2ee\home\;%ORACLE_HOME%\ldap\bi
n\;%ORACLE_HOME%\ldap\odi\admin\;%ORACLE_HOME%\oca\bin\;%ORACLE_HOME%\opmn\bin\;%ORAC
LE_HOME%\portal\admin\plsql\sso\;%ORACLE_HOME%\sso\lib\;%ORACLE_HOME%\uddi\lib\;%ORAC
LE_HOME%\upgrade\;%ORACLE_HOME%\wireless\bin\
export ORACLE_SID=iasdb
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
#export DISPLAY=tor:2.0
#************************************************************
#  Execute the DCM commands to bounce the OHS
#************************************************************
$ORACLE_HOME/dcm/bin/dcmctl stop -ct ohs
$ORACLE_HOME/dcm/bin/dcmctl start -ct ohs
$ORACLE_HOME/dcm/bin/dcmctl start -co OC4J_Portal

As we can see, these shell scripts with embedded Oracle Application Server commands are extremely useful for automatic Oracle Application Server administration.  As each component is discussed in later chapters, detailed scripts will be introduced to assist with the administration of that component.

---

The above text is an excerpt from the Oracle Application Server 10g Administration Handbook

Check out the whole series of exciting new Oracle10g books at http://shop.osborne.com/cgi-bin/oraclepress/

John Garmany is a leading expert in Oracle Application Server Consulting and Support.  He specializes in Oracle9iAS and Oracle Application Server 10g configuring and tuning.

Donald K. Burleson has been a working DBA for more than 20 years and specializes in creating large-scale, web-enabled Oracle Database systems.


Contributors : Donald K. Burleson, John Garmany
Last modified 2005-06-22 12:40 AM
Transaction Management
Reduce downtime and increase repeat sales by improving end-user experience.
Free White Paper
Database Recovery
Feeling the increased demands on data protection and storage requirements?
Download Free Report!
 
 

Powered by Plone