#!/bin/bash

# This script finds TRCDaemon and kills it as well as all its children
# (execute_activity.sh scripts).
# It should normally be used only in CyFlex go script.

__find_trc_daemon()
{
   /bin/ps axh -o pid,cmd | while read pid cmd; do
      echo "$cmd" | grep java | grep com.cybermetrix.trs.trc.TRCDaemon > /dev/null;
      [ $? -eq 0 ] && echo $pid;
   done
}

pid=`__find_trc_daemon`
if [ -z "$pid" ]; then
    echo "No prior TRC Daemon found to terminate";
    exit 1;
fi

echo Found TRC Daemon with with PID = $pid.  Terminating it.
/cyflex/cmds/trs/trc_kill_tree.sh -15 $pid
