#! /bin/sh -f
# set -x
# 
#  Cancel job running in SGE.
#  Input: grami file (same as Globus)
# 
#  Based on globus submission script for pbs
#
#  Based on ng submission script for pbs
#    Guenter Duckeck <gduckeck@lmu.de>
#    Juha Lento <Juha.Lento@csc.fi>


echo "----- starting cancel_sge_job -----" 1>&2

# Set variables:
#   SGE_BIN_PATH
#
if [ -z ${NORDUGRID_LOCATION} ] ; then
    echo "NORDUGRID_LOCATION not set."  1>&2
    exit 1
fi
if [ ! -f "${NORDUGRID_LOCATION}/libexec/configure-sge-env.sh" ] ; then
    echo "${NORDUGRID_LOCATION}/libexec/configure-sge-env.sh not found." 1>&2
    exit 1
fi
source ${NORDUGRID_LOCATION}/libexec/configure-sge-env.sh

joboption_lrms=SGE
##############################################################
# These should be set automatically
##############################################################
# Where to store temporary files on gatekeeper
TMP_DIR=${TMP_DIR:-/tmp}
# Where runtime scripts can be found on computing nodes (empty if does not exist)
RUNTIME_CONFIG_DIR=${RUNTIME_CONFIG_DIR:-}
# Description of (cross-)mounted disc space on cluster
RUNTIME_LOCAL_SCRATCH_DIR=${RUNTIME_LOCAL_SCRATCH_DIR:-}
RUNTIME_FRONTEND_SEES_NODE=${RUNTIME_FRONTEND_SEES_NODE:-}
#RUNTIME_NODE_SEES_FRONTEND=${RUNTIME_NODE_SEES_FRONTEND:-}
RUNTIME_NODE_SEES_FRONTEND=${RUNTIME_NODE_SEES_FRONTEND:-yes}


arg_file=$1
##############################################################
# Source the argument file. 
##############################################################
if [ -z "$arg_file" ] ; then
   echo "Arguments file should be specified" 1>&2
   exit 1
fi
if [ ! -f $arg_file ] ; then
   echo "Missing arguments file" 1>&2
   exit 1
fi
. $arg_file

SGE_QDEL='qdel'
if [ ! -z "$SGE_BIN_PATH" ] ; then
  SGE_QDEL="${SGE_BIN_PATH}/${SGE_QDEL}"
fi

tmpdir=${TMP_DIR:-/tmp}

echo executing qdel with job id $joboption_jobid 1>&2
"${SGE_QDEL}" "${joboption_jobid}"

echo "----- exiting cancel_sge_job -----" 1>&2
echo "" 1>&2
exit 0







