From 119b2bff17491f1eac94afe2f20905a68b4ef8e0 Mon Sep 17 00:00:00 2001 From: Brian Clements Date: Thu, 9 Oct 2014 11:04:49 -0500 Subject: [PATCH] Omaha #3675 alertviz cleanly exits when killed by signal Change-Id: I0ef7c8936558ccd8b927edb64143315afcb04631 Former-commit-id: 6bc42c58541363bee9be1607b1bdf2aca6f5a000 --- cave/build/static/linux/alertviz/alertviz.sh | 49 ++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/cave/build/static/linux/alertviz/alertviz.sh b/cave/build/static/linux/alertviz/alertviz.sh index 598cb3887d..573bbefb11 100644 --- a/cave/build/static/linux/alertviz/alertviz.sh +++ b/cave/build/static/linux/alertviz/alertviz.sh @@ -3,6 +3,31 @@ # Alert VIZ Startup Script # Note: Alert VIZ will not run as 'root' +# This software was developed and / or modified by Raytheon Company, +# pursuant to Contract DG133W-05-CQ-1067 with the US Government. +# +# U.S. EXPORT CONTROLLED TECHNICAL DATA +# This software product contains export-restricted data whose +# export/transfer/disclosure is restricted by U.S. law. Dissemination +# to non-U.S. persons whether in the United States or abroad requires +# an export license or other authorization. +# +# Contractor Name: Raytheon Company +# Contractor Address: 6825 Pine Street, Suite 340 +# Mail Stop B8 +# Omaha, NE 68106 +# 402.291.0100 +# +# See the AWIPS II Master Rights File ("Master Rights File.pdf") for +# further licensing information. +# +# +# SOFTWARE HISTORY +# Date Ticket# Engineer Description +# ------------ ---------- ----------- -------------------------- +# Oct 09, 2014 #3675 bclement added cleanExit signal trap +# + user=`/usr/bin/whoami` if [ ${user} == 'root' ]; then echo "WARNING: Alert VIZ cannot be run as user '${user}'!" @@ -78,6 +103,22 @@ if [ ! -d $LOGDIR ]; then mkdir -p $LOGDIR fi +# takes in a process id +# kills spawned subprocesses of pid +# and then kills the process itself and exits +function cleanExit() +{ + pid=$1 + if [[ -n $pid ]] + then + pkill -P $pid + kill $pid + fi + exit +} + +trap 'cleanExit $pid' SIGHUP SIGINT SIGQUIT SIGTERM + #run a loop for alertviz count=0 while [ $exitVal -ne 0 -a $count -lt 10 ] @@ -99,11 +140,13 @@ do else #finally check if we can write to the file if [ -w ${LOGFILE} ]; then - ${dir}/alertviz $* > ${LOGFILE} 2>&1 + ${dir}/alertviz $* > ${LOGFILE} 2>&1 & else - ${dir}/alertviz $* + ${dir}/alertviz $* & fi + pid=$! + wait $pid + exitVal=$? fi - exitVal=$? done