#!/bin/bash
#
# Description: Reset all processes in the same process group ID as the CCFW Manager by killing
#              these processes and then starting the CCFW Manager.  The local browser is also
#              terminated by killing all processes running under the browser userid.
#
# Change Activity:
#   10/19/2004 P. Callaghan - initial version
#   12/15/2006 L. Brocious  -01 Kill local browser, add logging
#
#STARTUSAGE
#
# Usage:
#   resetccfw
#
#ENDUSAGE
#****************************************************************************

# -01 Begin
logfn='/var/hsc/log/resetccfw.log'

# Add a line to our log file just to mark that it was this script that initiated 
# the CCFW restart
echo "resetccfw invoked on $(date) ($(date --utc))" >> $logfn
# -01 End

# Kill the currently running CCFW
export PATH=$PATH:/opt/hsc/bin/
killGroupOf '/bin/sh /opt/ccfw/runccfw /opt/ccfw ccfw'
killRC=$?
#if [ "$killRC" != "0" ] ; then
#  exit $killRC
#fi

# -01 Begin
# Kill the local browser so it doesn't interfere with the new instance about to be
# started by CCFW.
pids=$(ps -U browser -o pid --no-heading)
if [ -n "$pids" ]; then
   kill -9 $pids
fi
# -01 End

# Now restart CCFW, which will also restart the local browser
set -m
/bin/bash /opt/ccfw/startccfw & 

exit $?
