Skip to content

Commit

Permalink
Update stop-its shell script
Browse files Browse the repository at this point in the history
updates parsing and adds comments and output statements for logs
  • Loading branch information
sanjaysrikakulam committed Aug 30, 2023
1 parent 81944eb commit 61d688c
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions roles/usegalaxy-eu.fix-stop-ITs/templates/stop-ITs.sh.j2
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
#!/bin/sh
TODAY=$(date +"%d-%m-%y %H:%M:%S")
DAY=86400
. {{ galaxy_root }}/.bashrc
cd ~
for job in $(gxadmin query queue-detail --all | grep running | grep interactive_tool | awk '{print $3}')
do
# Get job working directory
JWD=$(python3 /usr/local/bin/galaxy_jwd get $job)
pushd $JWD
ClusterID=$( head -n 1 job_condor.log | awk '{print $2}' | awk -F. '{print $1"."$2}' | sed 's/^(//' )
if [ "$(condor_q -global $ClusterID -autoformat JobStartDate)" == "undefined" ] || [ "$(condor_q -global $ClusterID -autoformat JobStartDate)" == "" ]
then

# Get external/Condor job ID from either external_id file or job_condor.log file from JWD
if [ -f $JWD/external_id ]; then
ClusterID=$(cat $JWD/external_id | tr -d '"')
elif [ -f $JWD/job_condor.log ]; then
ClusterID=$(head -n 1 $JWD/job_condor.log | sed -n 's/.*(\([0-9]*\)\..*/\1/p')
fi

# If cluster ID is found
if [ ! -z "$ClusterID" ]; then
# Check if job is running for more than 24 hrs and remove it
if [ "$(condor_q -global $ClusterID -autoformat JobStartDate)" == "undefined" ] || [ "$(condor_q -global $ClusterID -autoformat JobStartDate)" == "" ]; then
echo "Removing condor job $ClusterID (Galaxy job id: $job) on $TODAY"
condor_rm $ClusterID

elif [ $(($(date +"%s") - $(condor_q -global $ClusterID -autoformat JobStartDate))) -ge $DAY ]; then
echo "Removing condor job $ClusterID (Galaxy job id: $job) on $TODAY"
condor_rm $ClusterID
elif [ $(($(date +"%s") - $(condor_q -global $ClusterID -autoformat JobStartDate))) -ge $DAY ]
then
condor_rm $ClusterID
fi
fi
popd
done

0 comments on commit 61d688c

Please sign in to comment.