#!/bin/bash
#
# sccl_stop_tst stoppt ein Test-Paket im Script-Cluster
#
# Aufruf:
#
# sccl_stop_tst <lock> [<node>]
#
# Das Test-Paket <lock> wird gestoppt.
#
########################################################################################
#echo $0 $*
#
. `dirname $0`/globals.functions
#
########################################################################################
#
if [[ $# -lt 1 ]]
 then
  echo "usage: $0 <lock> [<node>]"
  exit 1
fi
#
if [[ -z "$2" ]]
 then
  if ! NODE=`sccl_get_aktnode $1`
   then
    echo "Das Test-Paket $1 ist im Cluster nicht aktiv."
    exit 0
  fi
else
  NODE=$2
fi
#
#
if [[ "$NODE" != "THISNODE" && $NODE != $THISHOSTNAME && $NODE != $THISFQDN ]]
 then
  callnode $NODE "sccl_stop_tst.s3w?lock=$1"
else
  #
  if PID=`cat $LOCKDIR/$1.pid`
   then
     if ps -efa | awk '$2 == '$PID'{print $0}' | grep -q " /usr/share/sccl/bin/sccl_probe_res $1 "
     then
      kill $PID
      echo "Test-Paket $1 gestoppt."
      rm $LOCKDIR/$1$LOCKEXTENSION $LOCKDIR/$1.pid
    else
      echo "Test-Paket $1 konnte nicht bestimmt werden."
      exit 2
    fi
  else
    echo "Lockdatei $LOCKDIR/$1.pid nicht gefunden"
    exit 3
  fi
fi
