From be3d47e5e9d92c072fdf33fff6c9d1218dfdc07b Mon Sep 17 00:00:00 2001 From: Brian Clements Date: Fri, 20 Jun 2014 12:06:04 -0500 Subject: [PATCH] Omaha #3245 altered utility scripts to account for cave subprocess Change-Id: I085432b0aab9224bc0a9ffdf2d6c58301dd94dcd Former-commit-id: 0f25ac3b5b21aa2d9eaedd56a81ee9d7336bb8e2 [formerly aceeff1e02c896ff27794755eb10fc275718a68c] Former-commit-id: 3b71bedd14bdd19a20bf0f9cc91857a076bd7629 --- cave/build/static/linux/cave/caveUtil.sh | 23 ++++--- .../com.raytheon.uf.tools.cli/impl/capture | 60 +++++++++++++++---- 2 files changed, 65 insertions(+), 18 deletions(-) diff --git a/cave/build/static/linux/cave/caveUtil.sh b/cave/build/static/linux/cave/caveUtil.sh index 8338c90722..f7955d7302 100644 --- a/cave/build/static/linux/cave/caveUtil.sh +++ b/cave/build/static/linux/cave/caveUtil.sh @@ -32,6 +32,7 @@ # Feb 20, 2014 #2780 bclement added site type ini file check # # Mar 13 2014 #15348 kjohnson added function to remove logs +# Jun 20, 2014 #3245 bclement forEachRunningCave now accounts for child processes source /awips2/cave/iniLookup.sh @@ -135,17 +136,23 @@ function copyVizShutdownUtilIfNecessary() function forEachRunningCave() { local user=`whoami` - local caveProcs=`ps -ef | grep -E "(/awips2/cave|/usr/local/viz)/cave " | grep -v "grep" | grep $user` - # preserve IFS and set it to line feed only - local PREV_IFS=$IFS - IFS=$'\n' - - for caveProc in $caveProcs + for parent in $(pgrep -u $user '^cave$') do - "$@" $caveProc + # the cave process starts a new JVM as a child process + # find all children of the cave process + children=$(pgrep -P $parent) + if [[ -z $children ]] + then + # no children, assume that this is a main cave process + "$@" $(ps --no-header -fp $parent) + else + for child in $children + do + "$@" $(ps --no-header -fp $child) + done + fi done - IFS=$PREV_IFS } # takes in ps string of cave process, stores pid in _pids and increments _numPids diff --git a/edexOsgi/com.raytheon.uf.tools.cli/impl/capture b/edexOsgi/com.raytheon.uf.tools.cli/impl/capture index cc8adc2f0d..6653af386f 100644 --- a/edexOsgi/com.raytheon.uf.tools.cli/impl/capture +++ b/edexOsgi/com.raytheon.uf.tools.cli/impl/capture @@ -2,9 +2,6 @@ # base path to save capture data to, will create subdirectory for each workstation basePath="/data/fxa/cave" -# the grep string to find the cave processes -grepString="(/awips2/cave/cave|/usr/local/viz/cave)" - edexGrepString="edex.run.mode=" xorgLogPath="/var/log" @@ -59,9 +56,6 @@ usage() { echo -e "-f {y/n}\t\tdefault [$FORCE]" echo " Force a jstack/jmap by default" echo - echo -e "-g {grep string}\tdefault [$grepString]" - echo " The grep string used to find the processes" - echo echo -e "-l {y/n}\t\tdefault [$GRAB_CAVE_AND_ALERTVIZ_LOGS]" echo " Captures the cave and alertviz logs. If run for a specific pid the only cave log captured will be for that pid" echo @@ -420,6 +414,35 @@ runVersions() { $cmd >> ${dataPath}/versions.log 2>&1 } +# take in pid, output process name without args +getCommandName() { + ps --no-header c -p $1 -o cmd +} + +# take in pid, output parent process id +getParentPid() { + ps --no-header -p $1 -o ppid +} + +# take in pid, output associated cave executable pid if found, otherwise output given pid +determineCaveProcess() { + local RVAL=$1 + # check if supplied PID is for the cave executable + local CMD_NAME=$(getCommandName $1) + if [[ ! $CMD_NAME =~ cave ]] + then + # worker pid probably provided, check parent + RVAL=$(getParentPid $1) + if [[ ! $(getCommandName $RVAL) =~ cave ]] + then + # parent wasn't cave either... continue on using PID provided + echo "${t1}: Unable to find cave process for pid $1, proceeding with provided PID" >> $processFile + RVAL=$1 + fi + fi + echo $RVAL +} + # parse command line while [ ! -z "$1" ]; do arg=$1 @@ -430,7 +453,6 @@ while [ ! -z "$1" ]; do -d) RUN_JMAP="$1"; shift 1;; -e) EDEX_MODE="Y"; edexProcs[$edexProcCount]="$1"; shift 1; let "edexProcCount+=1";; -f) FORCE="$1"; shift 1;; - -g) grepString="$1"; shift 1;; -l) GRAB_CAVE_AND_ALERTVIZ_LOGS="$1"; shift 1;; -m) MOVE_ALL_HS_ERR_PID="$1"; shift 1;; -p) cavePid="$1"; shift 1;; @@ -537,10 +559,27 @@ if [ "$EDEX_MODE" == "y" ]; then done grepString="${grepString}) " + procs=`ps -ef | grep -E "$grepString" | grep -v "grep"` +else + #list of cave process ids to get ps output for + caveProcNums="" + for parent in $(pgrep '^cave$') + do + # the cave process starts a new JVM as a child process + # find all children of the cave process + children=$(pgrep -P $parent) + if [[ -z $children ]] + then + # no children, assume that this is a main cave process + caveProcNums="$caveProcNums $parent" + else + # otherwise, only get ps output for children + caveProcNums="$caveProcNums $children" + fi + done + procs=$(ps --no-header -fp $caveProcNums) fi -procs=`ps -ef | grep -E "$grepString" | grep -v "grep" | grep -v "cave.sh"` - if [ ! -z "$cavePid" ]; then # limit cave procs to the requested PID echo "Running in PID mode, only requesting for pid $cavePid" >> $processFile @@ -670,7 +709,8 @@ if [ "${GRAB_CAVE_AND_ALERTVIZ_LOGS}" == "y" ]; then echo "${t1}: Capturing cave logs" >> $processFile mkdir -p ${dataPath}/consoleLogs if [ ! -z ${cavePid} ]; then - find $dir -type f -name "*${cavePid}*" -exec cp {} ${dataPath}/consoleLogs \; + # logs have cave executable pid in the name, not worker pid + find $dir -type f -name "*$(determineCaveProcess ${cavePid})*" -exec cp {} ${dataPath}/consoleLogs \; else find $dir -type f -mmin -120 -exec cp {} ${dataPath}/consoleLogs \; fi