This file is indexed.

/usr/share/arc/scan-lsf-job is in nordugrid-arc-arex 4.0.0-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/sh
#
#
#   Scan for finished LSF jobs, using bjobs
#
# usage: scan_lsf_job control_dir ...

# Set variables:
#   LSF_BIN_PATH

# ARC1 passes first the config file.
if [ "$1" = "--config" ]; then shift; ARC_CONFIG=$1; shift; fi

basedir=`dirname $0`
basedir=`cd $basedir > /dev/null && pwd` || exit $?

libexecdir="${ARC_LOCATION:-/usr}/lib/arc/"
pkgdatadir="$basedir"

# Assume that gm-kick is installed in the same directory
GMKICK=${libexecdir}/gm-kick

. "${pkgdatadir}/configure-lsf-env.sh" || exit $?

. "${pkgdatadir}/scan_common.sh" || exit $?

umask 022

if [ -z "$1" ] ; then
    echo "Missing Input Script file as arg1" 1>&2
    exit 1 ;
fi

# first control_dir is used for storing own files

echo `date`" : control_dir=$1" 1>&2

control_dir=$1
control_dirs=
while [ $# -gt 0 ] ; do
  control_dirs="${control_dirs} $1"
  shift
done

my_id=`id -u`

# Get all running jobs
#

if [ -z ${LSF_BIN_PATH} ]; then
    echo "${LSF_BIN_PATH} not set" 1>&2
    exit 1
fi

lsf_stat=`${LSF_BIN_PATH}/bjobs -a -u all 2>/dev/null` # | grep RUN | grep '^ [:digit:]'

if [ -z "${lsf_stat}" ] ; then
    echo "bjobs returned empty result" 1>&2
fi

pids=`echo "${lsf_stat}" | egrep 'PSUSP|USUSP|SSUSP|RUN|PEND' | sed -e 's/^\([^ ]*\).*/\1/'`

eval "set -- $control_dirs"

# Go through directories
for ctr_dir in $control_dir ; do

  # Obtain ids stored in job.*.local
    ids=`find ${ctr_dir}/processing -name 'job.*.status' -print0 \
         | sed 's/processing\/job\.\([^\.]*\)\.status/job.\1.local/g' \
         | xargs -0 grep -h "^localid=" 2>/dev/null | sed 's/^localid=\([0-9]*\).*/\1/'`

    if [ -z "$ids" ] ; then continue ; fi

    # compare them to running jobs and find missing
    bids=
    for id in $ids ; do
	found=`echo "$pids" | grep "^$id$"`
	if [ -z "$found" ] ; then
	    bids="$bids $id"
	fi
    done

    # go through missing ids
    for id in $bids ; do

	# find grid job corresponding to curent local id
        jobfile=`find ${ctr_dir}/processing -name 'job.*.status' -print0 \
                 | sed 's/processing\/job\.\([^\.]*\)\.status/job.\1.local/g' \
                 | xargs -0 grep -F -l "localid=$id" 2>/dev/null`
	if [ -z "$jobfile" ] ; then continue ; fi

	# extract grid id
	gridid=`basename "$jobfile" '.local' | sed 's/^job\.//'`
	donefile="${ctr_dir}/job.${gridid}.lrms_done"
	if [ -f "$donefile" ] ; then continue ; fi

	statusfile="${ctr_dir}/processing/job.${gridid}.status"
	if [ ! -f "$statusfile" ] ; then continue ; fi

	status=`cat "$statusfile"`
	if [ "$status" != "INLRMS" ] && [ "$status" != "CANCELING" ] ; then continue ; fi

        if [ "$my_id" != '0' ] ; then
          if [ ! -O "$jobfile" ] ; then continue ; fi
        fi
        uid=$(get_owner_uid "$jobfile")
        [ -z "$uid" ] && { log "Failed to stat $jobfile"; continue; }


	# get session directory of this job
	sessiondir=`grep -h '^sessiondir=' "$jobfile" | sed 's/^sessiondir=\(.*\)/\1/'`

	# get job specific output and remove header
	bjobs_output="`${LSF_BIN_PATH}/bjobs -W -w $id 2>/dev/null | sed -e'1,1d'`"
	job_status="`echo $bjobs_output | awk '{print $3}'`"
	# DONE if exit_code is 0, EXIT if non zero
	if [ "${job_status}" = "DONE" ] || [ "${job_status}" = "EXIT" ]; then

            job_read_diag

	    starttime="`echo $bjobs_output | awk '{print $14}' | sed 's/-/ /g'`"
	    endtime="`echo $bjobs_output | awk '{print $15}' | sed 's/-/ /g'`"
	    date_to_utc_seconds "$starttime"
	    starttime_seconds="$return_date_seconds"
	    seconds_to_mds_date "$return_date_seconds"
	    LRMSStartTime=$return_mds_date
	    date_to_utc_seconds "$endtime"
	    endtime_seconds="$return_date_seconds"
	    seconds_to_mds_date "$return_date_seconds"
	    LRMSEndTime=$return_mds_date

	    #TODO handle cputime (walltime * count?) etc.
            walltime=$(( $endtime_seconds - $starttime_seconds))
	    #cputime=$(( $walltime * $count))
            # Values to write to diag. These will override values already written.
            [ -n "$walltime" ] && WallTime=$walltime
            #[ -n "$cputime" ] && UserTime=$cputime
            #[ -n "$cputime" ] && KernelTime=0

            job_write_diag
	fi

	if [ -n "$sessiondir" ] ; then
	    # have chance to obtain exit code
	    diagfile="${sessiondir}.diag"

	    if [ -n "$sessiondir" ] ; then
		# have chance to obtain exit code
                exitcode=$(do_as_uid "$uid" "grep '^exitcode=' '$diagfile'" | sed 's/^exitcode=//')
	    fi

	    if [ -n "$exitcode" ] ; then
		# job finished and exit code is known
                save_commentfile "$uid" "${sessiondir}.comment" "${ctr_dir}/job.${gridid}.errors"
		echo "$exitcode Executable finished with exit code $exitcode" > "$donefile"
		${GMKICK} "$jobfile"
		continue
	    fi
	fi

	# job has probaly finished and exit code is not known
	exitcode='-1'
	countfile="${ctr_dir}/job.${gridid}.lrms_job"
	counter=0
	if [ -f "$countfile" ] ; then
	    counter=`cat "$countfile"`
	    counter=$(( $counter + 1 ))
	fi

	if [ "$counter" -gt 5 ] ; then
	    rm -f "$countfile"
            save_commentfile "$uid" "${sessiondir}.comment" "${ctr_dir}/job.${gridid}.errors"
	    echo "$exitcode Job was lost with unknown exit code" > "$donefile"
	    ${GMKICK} "$jobfile"
	else
	    echo "$counter" > "$countfile"
	fi


    done

    # go through existing ids
    for id in $pids ; do
	# find grid job corresponding to curent local id
	jobfile=`find ${ctr_dir} -name 'job.*.local' -print0 | xargs -0 grep -F -l "localid=$id." 2>/dev/null`
	if [ -z "$jobfile" ] ; then continue ; fi
	gridid=`basename "$jobfile" '.local' | sed 's/^job\.//'`
	countfile="${ctr_dir}/job.${gridid}.lrms_job"
	# reset failure counter
	rm -f "$countfile"
    done

done

sleep 60
exit 0