|
|
|
|
|
Start / Stop Scripts
Contained in this document is the code for an example start and stop
script for Oracle databases. An additional feature of the start script
is that it assigns a Workload Manager (WLM) TAG to the oracle processes
being started. Also included is a WLM assignment script which searches
processes for a matching WLM subclass string, and assigns those
processes to the associated WLM class and subclass.
The name structure used for the start/stop scripts with
example names follow:
RG Name
|
Business Function
and Sequence ID
|
Start or Stop
|
Interpreter ID
|
Example
|
ednpdmx1
|
db01
|
start
|
sh
|
ednpdmx1_db01_start.sh
|
ednpdmx1
|
db01
|
stop
|
sh
|
ednpdmx1_db01_stop.sh
|
ednpdmx1
|
appl01
|
start
|
sh
|
ednpdmx1_appl01_start.sh
|
ednpdmx1
|
appl01
|
stop
|
sh
|
ednpdmx1_appl01_stop.sh
|
ijtpamx9
|
db01
|
start
|
sh
|
ijtpamx9_db01_start.sh
|
ijtpamx9
|
db01
|
stop
|
sh
|
ijtpamx9_db01_stop.sh
|
ijtpamx9
|
appl01
|
start
|
sh
|
ijtpamx9_appl01_start.sh
|
ijtpamx9
|
appl01
|
stop
|
sh
|
ijtpamx9_appl01_stop.sh
|
Legend:
- RG = Resource Group
- Sequence ID = to distinguish between muliple instances
- appl = Application
- db = Database
- Interpreter = identification of script interpreter
Example Start Script: ijtpamx9_db01_start.sh
#!/usr/bin/ksh93
################################################################
print "START SCRIPT BEGIN: ${0}"
RG="ijtpamx9"
DBNAME="MTX22DB"
UNAME="oraijt1"
LSNRPORT="1571"
typeset -l WLMTAG="${DBNAME}"
print "/${RG}/u01/app/oracle/product/9.2.0/bin/dbstart ${DBNAME}" > /tmp/dbstart.${DBNAME}.${$}.sh
chmod 755 /tmp/dbstart.${DBNAME}.${$}.sh
su - ${UNAME} -c "/usr/local/bin/wlmsettag ${WLMTAG} /tmp/dbstart.${DBNAME}.${$}.sh" &
su - ${UNAME} -c "/${RG}/u01/app/oracle/product/9.2.0/bin/lsnrctl start lsnr_${UNAME}_${LSNRPORT}" &
/usr/local/hascripts/rg_wlmassign.sh
print "START SCRIPT END: ${0}"
exit 0
Example Stop Script: ijtpamx9_db01_stop.sh
#!/usr/bin/ksh93
################################################################
print "STOP SCRIPT BEGIN: ${0}"
RG="ijtpamx9"
DBNAME="MTX22DB"
UNAME="oraijt1"
LSNRPORT="1571"
su - ${UNAME} -c "/${RG}/u01/app/oracle/product/9.2.0/bin/lsnrctl stop lsnr_${UNAME}_${LSNRPORT}" &
su - ${UNAME} -c "/${RG}/u01/app/oracle/product/9.2.0/bin/dbshut ${DBNAME}" &
CNT="0"
while (( $( jobs | wc -l ) > 0 ))
do
print "STOP SCRIPT KILL TIMER: $( date )"
if (( CNT >= 300 ))
then
for SIG in 15 1 2 9
do
ps -fu ${UNAME}
for PID in $( ps -fu ${UNAME} -F pid | grep -v PID )
do
print kill -${SIG} ${PID}
kill -${SIG} ${PID}
done
sleep 15
done
break
fi
sleep 15
(( CNT = CNT + 15 ))
done
while (( $( ps -fu ${UNAME} -F pid | grep -v PID | wc -l ) > 0 ))
do
print "STOP SCRIPT WAIT TIMER: $( date )"
sleep 15
(( CNT = CNT + 15 ))
(( CNT >= 300 )) && break
done
ps -fu ${UNAME}
for SIG in 15 1 2 9
do
for PID in $( ps -fu ${UNAME} -F pid | grep -v PID )
do
print kill -${SIG} ${PID}
kill -${SIG} ${PID}
done
sleep 2
done
print "STOP SCRIPT END: ${0}"
exit 0
Example Workload Manager Assignment Script: rg_wlmassign.sh
#!/usr/bin/ksh93
################################################################
####
#### Description: This script assigns processes to WLM
#### subclasses based on the structure of the process
#### arguments. It is expected that the subclass name
#### appears in uppercase letters in the process arguments,
#### if so the associated process ID is used to assign
#### the process to the WLM class.subclass.
####
################################################################
TRUE="0"
FALSE="1"
VERBOSE="${TRUE}"
(( VERBOSE == TRUE )) && print "# RG WLMASSIGN SCRIPT BEGIN: ${0}"
#### Get list of WLM classes
for CL in $( lsclass )
do
#### Get list of WLM subclasses under each WLM class
for SUBCL in $( lsclass -S ${CL} )
do
#### Define uppercase representations of the subclass
typeset -u UPPERSC="${SUBCL}"
#### Generate a list of all process ID's and associated command line arguments
ps -ef -F pid,args | while read -r -- PID ARGS
do
#### If the process arguments do not contain the uppercase representation
#### of the subclass, ignore it and go to the next process in the list
[[ "_${ARGS}" != _*${UPPERSC}* ]] && continue
(( VERBOSE == TRUE )) && print -u 2 "# wlmassign ${CL}.${SUBCL} ${PID}"
#### Assign each process to a WLM class and subclass
wlmassign ${CL}.${SUBCL} ${PID}
(( VERBOSE == TRUE )) &&
print -u 2 "# $( ps -fp ${PID} -F user,pid,class,args | tail -1 ) "
done
done
done
(( VERBOSE == TRUE )) && print "# RG WLMASSIGN SCRIPT END: ${0}"
exit 0
Workload Manager TAG Assignment Program: wlmsettag.c
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <sys/wlm.h>
/* ################################################################ */
/* Program for launching and tagging an application */
main (argc,argv)
char **argv;
int argc;
{
int rc,flags;
if (argc != 3) {
usage(argv[0]);
exit(1);
}
flags= WLM_VERSION|SWLMTAGINHERITFORK|SWLMTAGINHERITEXEC;
if(wlm_initialize(WLM_VERSION)){
perror("wlm_initialize");
exit(1);
}
if(wlm_set_tag(argv[1],&flags)){
perror("wlm_set_tag");
exit(2);
}
if (execlp(argv[2],argv[2],0)){
perror("execlp"); printf("Problem launching app...\n");
exit(3);
}
exit(0);
}
/* ################################################################ */
usage(char *cp)
{
printf("\n %s takes 2 arguments:\n",cp);
printf("Usage: %s tag_name program_name \n",cp);
printf("where: tag_name is the rule tag that program_name will inherit \
\n");
}
|
|
|
|
|
|
|