#!/bin/bash
if [ $# -ne 1 ] ; then
   echo "Usage: $0 machine"
   echo "       Stop Condor completely on the indicated WN"
   exit 1
fi

setupDir=`dirname $0`
if [ -e $setupDir/clusco_setup.sh ] ; then
   source $setupDir/clusco_setup.sh
elif [[ "$clusCoDir" == "" ]] ; then
   echo "Abort: No clusco_setup file found"
   exit 2
fi

mach=$1
# Need to strip off any domain extensions here for matching purposes
#
machine=`echo $mach | sed -e s/[.]/\ /g | awk '{print $1}'`

line=`grep "${machine}\"" $clusCoDir/nodeinfo.csv`
if [ $? -ne 0 ] ; then
   echo "Indicated $machine is not in the DB file"
   exit 3
fi

echo "Turning off condor on $machine"

localMachine=$(python $clusCoCmd $machine NAME_PRIVATE)
localNet=$(python $clusCoCmd $machine DOMAIN_PRIVATE)

ssh -x root@${localMachine}.${localNet} condor_off -daemon master

${clusCoDir}/set_condor_state.sh $localMachine DOWN