-
Notifications
You must be signed in to change notification settings - Fork 0
/
worsica_grid_kill_submission.sh
executable file
·71 lines (66 loc) · 2.89 KB
/
worsica_grid_kill_submission.sh
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
SUBMISSION_NAME=$1
TIME_SLEEP=10
#e.g: $1 = worsica-processing-service-coastal-user1-roi144-simulation170-1719-converting
echo "[worsica_grid_kill_submission.sh] 1) Get $1"
if ls ../worsica_web_products/grid/jobids/ | grep "$1"; then
#20220517-172643-worsica-processing-service-coastal-user1-roi144-simulation170-1719-converting.job.id
JOBID_FILE=$(ls ../worsica_web_products/grid/jobids/ | grep "$1")
#$HOME/worsica_web_products/grid/jobids/20220517-172643-worsica-processing-service-coastal-user1-roi144-simulation170-1719-converting.job.id
JOBID_FILEPATH=$HOME/worsica_web_products/grid/jobids/$JOBID_FILE
#$HOME/worsica_web_products/log/20220517-172643-worsica-processing-service-coastal-user1-roi144-simulation170-1719-converting.out
LOG_FILEPATH=${JOBID_FILEPATH/.job.id/.out}
LOG_FILEPATH=${LOG_FILEPATH/grid\/jobids/log}
echo "$LOG_FILEPATH"
echo "[worsica_grid_kill_submission.sh] Found $JOBID_FILEPATH!"
else
echo "[worsica_grid_kill_submission.sh] Fail getting $1!"
exit 1
fi
#echo '[worsica_grid_kill_submission.sh] 2) Trying to clean job'
#if arcclean -i $JOBID_FILEPATH; then
# echo "[worsica_grid_kill_submission.sh] Done!!"
# exit 0
#else
# echo "[worsica_grid_kill_submission.sh] Fail killing $1!"
# #exit 1
#fi
echo '[worsica_grid_kill_submission.sh] 2) Killing' #queuing, running, finishing,
while true; do
JOB_STATE=$(arcstat -i $JOBID_FILEPATH | grep "Hold\|Accepted\|Preparing\|Queuing\|Running\|Finishing\|Finished\|Job information not found in the information system\|Job not found in job list")
echo '[worsica_grid_kill_submission.sh] Check status'
echo '------------'
echo $JOB_STATE
echo '------------'
#stop looping if job does not exist
if [[ ${JOB_STATE} == *"Job not found in job list"* ]] ; then
echo "[worsica_grid_launch_submission.sh] Job not found in job list! Exit!"
exit 1
fi
#
if [[ ${JOB_STATE} == *"Finished"* ]] ; then
#optionally clean
if arcclean -i $JOBID_FILEPATH; then
echo "[worsica_grid_kill_submission.sh] Cleaned!"
break
fi
fi
#or proceed
echo "[worsica_grid_kill_submission.sh] Fetch output to $LOG_FILEPATH..."
if arccat -o -i $JOBID_FILEPATH > $LOG_FILEPATH ; then
echo "[worsica_grid_kill_submission.sh] Fetched!"
else
echo "[worsica_grid_kill_submission.sh] Fail fetching, ignore!" #In some cases, the job has only been submitted, but not run.
fi
#
echo '[worsica_grid_kill_submission.sh] Trying to kill job'
if arckill -i $JOBID_FILEPATH; then
echo "[worsica_grid_kill_submission.sh] Killed!"
break
else
echo "[worsica_grid_kill_submission.sh] ...not yet dead..."
echo "[worsica_grid_kill_submission.sh] ...check again ${TIME_SLEEP}s..."
sleep ${TIME_SLEEP}
fi
done
echo "[worsica_grid_kill_submission.sh] Done!"
exit 0