#!/bin/bash
#
# sccl_stop_tst stoppt ein Test-Paket im Script-Cluster
#
# Aufruf:
#
# sccl_stop_tst <lock> [<node>]
#
# Das Test-Paket <lock> wird gestoppt.
#
########################################################################################
#
. $(dirname $0)/globals.settings
#
########################################################################################
#
if [[ $# -lt 1 ]]; then
  echo "usage: $MYPRG <lock> [<node>]"
  exit 1
fi
#
if [[ -z "$2" ]]; then
  if ! NODE=`sccl_get_actnode $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&initiated=${scclinitiated:-$THISHOSTNAME}"
else
  #
  if PID=`cat "$LOCKDIR/$1.pid"`; then
     if ps -ef | awk '$2 == '$PID'{print $0}' | grep -q "/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
