From 5072f40a2f20567cbacf6baf633b09c73aa3c55f Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Wed, 28 Aug 2024 16:23:17 +0200 Subject: [PATCH] Leave automatic allocation in fpgalogin1 --- fpga/run-login.sh | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/fpga/run-login.sh b/fpga/run-login.sh index afe8dca..cc95b40 100755 --- a/fpga/run-login.sh +++ b/fpga/run-login.sh @@ -1,9 +1,16 @@ #!/usr/bin/bash -#set -x +# There are several situations in which we may find the jobs: +# - There are no jobs queued or running +# - There is at least one job running +# - There is one job queued +# - There was a job running but ended and is now ending + +set -x set -e path="$1" +allocated= # First determine if we already have jobs already n=$(squeue --me -lh | wc -l) @@ -15,17 +22,33 @@ fi if [ "$n" == 0 ]; then # No running jobs, so allocate a new job - echo salloc -N 1 --constraint=dmaqdma --no-shell + salloc -N 1 --constraint=dmaqdma --no-shell -t 1-00 + allocated=1 + + # Wait until the job is running + while [ "$n" != 1 ]; do + sleep 2 + n=$(squeue --me -lh | grep RUNNING | wc -l) + done +else + # There is one job, ensure it is running + n=$(squeue --me -lh | grep RUNNING | wc -l) + + if [ "$n" != 1 ]; then + echo "The job is not running, stopping" >&2 + exit 1 + fi fi -while [ "$n" != 1 ]; do - sleep 2 - n=$(squeue --me -lh) -done +# If this point is reached there is one job running host=$(squeue -h -o %N) - echo "Switching to $host" # Continue the execution there ssh "$host" "$path/run-node.sh" "$path" + +# Cancel our job if it was successful +if [ "$allocated" ]; then + scancel --me +fi