Tuesday, October 12, 2010

Apache Bounce Concurrent Request.


Bounce Apache Server – A Concurrent Request

Background: Need of Apache bounce concurrent request has come out of following requirements:
(i) Development team requires access on server for bouncing apache. DBA team cannot share master login credentials with development team but developers require bouncing Apache very frequently during testing phase. This has created the deadlock.
(ii) Bouncing Apache using concurrent request is faster and easier approach.
Before starting let me give you a brief idea on our architecture:-
Tier 1 :- Web server :- EBUS_WEB
Tier 2 :- CP, Admin and DB server :- EBUS_CM
Brainstorming: After lot of brainstorming we came to conclusion that we can create a master shell script on Tier 2 (CM server) that will be called by concurrent request. Master shell script will internally call apache_stop, apache_start & clear_cache script placed on Tier1 (Web server). SSH is used for connection from one server Tier 2 to Tier 1(i.e. web server).

How we did it:
Whole thing is divided into 2 parts:

Shell scripting:

As we have concurrent processing and Web server on different tier so we need a medium to communicate between them. After discussion with UNIX team we got SSH as medium to get same.
Following Scripts are created:
APACHE Bounce Master Script: This script is created on Concurrent Processing server and will be in direct contact with concurrent request. This script will internally call apache_start, apache_stop and clear_cache script placed on web server.
Content of APACHE shell script:
#!/bin/ksh
#########################################################################
#
# Program Name: Apace Bounce Script
#
# Created By: Deepak Jha
#
# Creation Date: 22 Jul 2009
#
# Version: 1.0
#
#########################################################################
#
# Description
# -----------
# Generic Script to bounce Apache server using Concurrent request.
#
# Date User Description
# ----------------------------------------------------------------------
# 22 Jul 2009 Deepak Jha Initial Creation
#
#
#########################################################################
echo $PATH
#Apache stop script
#All script referenced in this script is placed at /tmp location. You #can place it as per your convenience.
echo "Script start time: `date`"
printf "Calling Apache stop script on Webserver.\n"
ssh EBUS_WEB /tmp/apache_stop.sh
printf "Apache has been stopped, putting the request to sleep for 5 sec, so that all hanged apache processes get stopped.\n"
echo "Sleep In time: `date`"
sleep 5
echo "Sleep Out time: `date`"
printf "checking if clear cache is required.\n"
if [ "$5" = "y" ]
then
printf "Clear cache required.\n"
printf "clearing cache.......\n"
ssh EBUS_WEB /tmp/apache_clear_cache.sh
else
printf "Clear cache not required.\n"
fi
#Apache start script
ssh EBUS_WEB /tmp/apache_start.sh
sleep 30
echo "Script End time: `date`"

Apache Stop Script: This script should be placed on Web server (EBUS_WEB) and will be used to stop apache. This script will first stop apache by calling adapcctl.sh with stop parameter. This script is also capable of killing any hanged apache processes (that have not been killed even after apache stop).
Content of apache_stop.sh
#START OF SCRIPT#
$COMMON_TOP/admin/scripts/$CONTEXT_NAME/adapcctl.sh stop
#Identify if Apache processes are still alive
#c=`date '+%d%m%y.%H.%M.%S'`
echo " Checking if Apache Processes are still alive"
x=`ps -ef grep Apachegrep -v grepawk '{print $2}' wc -l`
echo $x
if [ $x -eq 0 ]
then
echo "No alive apache process and apache has been stopped cleanly."
else
echo "Following processes are still alive:"
ps -ef grep Apachegrep -v grepawk '{print $2}'
#Kill identified process
echo "Killing identified process"
kill -9 `ps -ef grep Apachegrep -v grepawk '{print $2}'`
printf "Processes killed at O.S level.\n"
printf "Apache Stopped Successfully.\n"
fi
#END OF SCRIPT#

Apache Clear Cache Script:- This file will come into action if user wants to bounce apache with clear cache option. It should also be placed at EBUS_WEB.
Content of apache_clear_cache.sh:
#START OF FILE#
c=`date '+%d%m%y.%H.%M.%S'`
printf "clearing cache in progress....\n"
mv $COMMON_TOP/_pages $COMMON_TOP/_pages.$c
printf "Cache Cleared.\n"
#END OF FILE#
Apache Start Script: This script will call adapcctl.sh with start parameter. It should also be placed at EBUS_WEB.
Content of apache_start.sh:
#START OF SCRIPT#
. $COMMON_TOP/admin/scripts/$CONTEXT_NAME/adapcctl.sh start
if [ ${?} -eq 0 ]
then
printf "Apache Started Successfully.\n"
else
printf "Apache could not be started. Please check Apache error log for more information.\n"
exit 1
fi
#END OF SCRIPT#

Concurrent Program Definition and other steps to be done through Oracle Application front end.

Concurrent Program Definition:-
Define Concurrent Program Executable

Concurrent --> Program --> Executable
Executable --> Any name but remember it because it should be provided at time to concurrent program creation.
Short Name --> Give it as executable to avoid confusion.
Application --> Application Object Library
Execution Method --> Host
Execution File Name --> Name of shell script placed on EBUS_CM at $FND_TOP/bin

Define Concurrent Program:-
Concurrent --> Program --> Define
Program --> Concurrent Program Name. It can be any name of your choice.
Short Name --> Should be same as provided at time of executable creation.
Application --> Application Object Library
Name --> Should be same as provided at time of executable creation.
Method --> host

Place master APACHE shell script at EBUS_CM (CM server) $FND_TOP/bin location. Create simlink between master shell script and fndcpesr
ln –s fndcpesr APACHE
mv APACHE APACHE.prog

Note Apache is main shell script to be called by concurrent request.

Define Custom Value set: - This needs to be created so that we can pass parameter to concurrent request for bouncing it with "Clear Cache" option.
Application --> Validations --> Set
Value Set Name --> Any name of your choice. You need to remember this name.
Maximum Size --> 50
Other choices can be default.
Define Values for Value Set
Application --> Validation à Values
In pop up window provide Value set name that has been created in previous step:
Click Find
In Value Field provide required values. N for not bouncing apache with clear cache and y for bouncing apache with clear cache

Attach Value set to concurrent request:-
Concurrent --> Program --> Define
Query your concurrent request and click parameter tab
seq --> any number
parameter--> Name of parameter to be presented to user while submitting concurrent request. It can be any name
Value Set --> Name of Value set created previously.
Other fields will get populated automatically.
Now everything is in place and we are good to bounce our apache server using Concurrent request.

Testing:
Run Concurrent request with parameter y for apache bounce with clear cache.
Run Concurrent request with parameter n for not bouncing apache with clear cache.
Result: Check the log files of concurrent request. It will give you output in desired way. If request provide error then DBA need to troubleshoot.

No comments:

Post a Comment