diff --git a/cave/build/static/linux/cave/cave.sh b/cave/build/static/linux/cave/cave.sh index 7bb4f35ad9..326839a0c3 100644 --- a/cave/build/static/linux/cave/cave.sh +++ b/cave/build/static/linux/cave/cave.sh @@ -32,6 +32,7 @@ # Jan 30, 2014 #2593 bclement warns based on memory usage, fixed for INI files with spaces # Jul 10, 2014 #3363 bclement logs command used to launch application to console logs # Oct 10, 2014 #3675 njensen Logback now does console logging to ensure correct pid +# Oct 13, 2014 #3675 bclement startup shutdown log includes both launching pid and placeholder # # @@ -211,7 +212,9 @@ curTime=`date +%Y%m%d_%H%M%S` ( export pid=`/bin/bash -c 'echo $PPID'` - LOGFILE_STARTUP_SHUTDOWN="${LOGDIR}/${PROGRAM_NAME}_${curTime}_pid_${pid}_startup-shutdown.log" + # we include the PID of the launching process along with + # a %PID% placeholder to be replaced with the "real" PID + LOGFILE_STARTUP_SHUTDOWN="${LOGDIR}/${PROGRAM_NAME}_${pid}_${curTime}_pid_%PID%_startup-shutdown.log" export LOGFILE_CAVE="${LOGDIR}/${PROGRAM_NAME}_${curTime}_pid_%PID%_logs.log" export LOGFILE_CONSOLE="${LOGDIR}/${PROGRAM_NAME}_${curTime}_pid_%PID%_console.log" export LOGFILE_PERFORMANCE="${LOGDIR}/${PROGRAM_NAME}_${curTime}_pid_%PID%_perf.log" @@ -245,9 +248,6 @@ curTime=`date +%Y%m%d_%H%M%S` echo "Launching cave application using the following command: " >> ${LOGFILE_STARTUP_SHUTDOWN} echo "${CAVE_INSTALL}/cave ${CAVE_INI_ARG} ${SWITCHES} ${USER_ARGS[@]}" >> ${LOGFILE_STARTUP_SHUTDOWN} - # TODO would be cool if we spawned another process to figure out the pid of - # the actual cave java process and logged that to the startup file to make it - # easier to correlate a startup log to the other cave logs if [[ "${redirect}" == "true" ]] ; then # send output to /dev/null because the logback CaveConsoleAppender will capture that output @@ -259,7 +259,7 @@ curTime=`date +%Y%m%d_%H%M%S` ) & pid=$! -LOGFILE_STARTUP_SHUTDOWN="${LOGDIR}/${PROGRAM_NAME}_${curTime}_pid_${pid}_startup-shutdown.log" +LOGFILE_STARTUP_SHUTDOWN="${LOGDIR}/${PROGRAM_NAME}_${pid}_${curTime}_pid_%PID%_startup-shutdown.log" logExitStatus $pid $LOGFILE_STARTUP_SHUTDOWN diff --git a/cave/build/static/linux/cave/caveUtil.sh b/cave/build/static/linux/cave/caveUtil.sh index 0a3e7ea12a..2630114137 100644 --- a/cave/build/static/linux/cave/caveUtil.sh +++ b/cave/build/static/linux/cave/caveUtil.sh @@ -36,6 +36,7 @@ # Jul 02, 2014 #3245 bclement account for memory override in vm arguments # Jul 10, 2014 #3363 bclement fixed precedence order for ini file lookup # Jul 11, 2014 #3371 bclement added killSpawn() +# Oct 13, 2014 #3675 bclement logExitStatus() waits for child to start and renames log with child PID source /awips2/cave/iniLookup.sh @@ -330,6 +331,14 @@ function logExitStatus() logFile=$2 trap 'killSpawn $pid' SIGHUP SIGINT SIGQUIT SIGTERM + + childPid=$(waitForChildToStart $pid) + if [[ -n $childPid ]] + then + newFileName=${logFile/\%PID\%/$childPid} + mv $logFile $newFileName + logFile=$newFileName + fi wait $pid exitCode=$? curTime=`date --rfc-3339=seconds` @@ -348,6 +357,24 @@ function logExitStatus() fi } +# takes in a PID +# waits for PID to spawn child +# outputs the PID of the child or nothing if PID exits first +function waitForChildToStart() +{ + pid=$1 + # check if PID is still running + while ps -p $pid > /dev/null + do + sleep 1s + if child=$(pgrep -P $pid) + then + echo $child + break + fi + done +} + #Delete old CAVE logs DR 15348 function deleteOldCaveLogs() { diff --git a/edexOsgi/com.raytheon.uf.tools.cli/impl/capture b/edexOsgi/com.raytheon.uf.tools.cli/impl/capture index 1628567b44..48d0d21eec 100644 --- a/edexOsgi/com.raytheon.uf.tools.cli/impl/capture +++ b/edexOsgi/com.raytheon.uf.tools.cli/impl/capture @@ -718,8 +718,8 @@ if [ "${GRAB_CAVE_AND_ALERTVIZ_LOGS}" == "y" ]; then echo "${t1}: Capturing cave logs" >> $processFile mkdir -p ${dataPath}/consoleLogs if [ ! -z ${cavePid} ]; then - # logs have cave executable pid in the name, not worker pid - find $dir -type f -name "*$(determineCaveProcess ${cavePid})*" -exec cp {} ${dataPath}/consoleLogs \; + # logs have cave executable pid or worker pid in the name (-o means OR) + find $dir -type f -name "*$(determineCaveProcess ${cavePid})*" -o -name "*${cavePid}*" -exec cp {} ${dataPath}/consoleLogs \; else find $dir -type f -mmin -120 -exec cp {} ${dataPath}/consoleLogs \; fi