#! /bin/sh -f
# set -x
# 
#  Cancel job running in LoadLeveler.
#  Input: grami file (same as Globus)
# 
#  Based on globus submission script for pbs
#
#  Based on ng submission script for pbs
#    Christian Soettrup <soettrup@nbi.dk>

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

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

joboption_lrms=LL
##############################################################
# 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

LL_DEL='llcancel'
if [ ! -z "$LL_BIN_PATH" ] ; then
  LL_DEL="${LL_BIN_PATH}/${LL_DEL}"
fi

tmpdir=${TMP_DIR:-/tmp}

echo executing job removal with job id $joboption_jobid 1>&2
"${LL_DEL}" "${joboption_jobid}"

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


