Skip to content

Commit dab386c

Browse files
committed
Fail hard on first error in batch script
Bash generally keeps executing code line by line even if any of the lines fail. For example, if your path is not set properly, `batchspawner-singleuser` will not be found by `which`. This should terminate execution. However, without `set -e`, execution will just continue and fail with a different error. This patch does `set -euo pipefail` for all submission scripts. This causes them to fail on: 1. Any non-zero command return code (-e) 2. On undefined environment variables (-u) 3. Treat failures in any part of a pipeline as failure, rather than just the last command (-o pipefail)
1 parent 33b4a7b commit dab386c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

batchspawner/batchspawner.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,8 @@ class TorqueSpawner(BatchSpawnerRegexStates):
504504
#PBS -v {keepvars}
505505
#PBS {options}
506506
507+
set -euo pipefail
508+
507509
{prologue}
508510
{cmd}
509511
{epilogue}
@@ -543,6 +545,8 @@ class PBSSpawner(TorqueSpawner):
543545
#PBS -v {{keepvars}}
544546
{% if options %}#PBS {{options}}{% endif %}
545547
548+
set -euo pipefail
549+
546550
{{prologue}}
547551
{{cmd}}
548552
{{epilogue}}
@@ -598,6 +602,8 @@ class SlurmSpawner(UserEnvMixin,BatchSpawnerRegexStates):
598602
{% endif %}{% if reservation%}#SBATCH --reservation={{reservation}}
599603
{% endif %}{% if options %}#SBATCH {{options}}{% endif %}
600604
605+
set -euo pipefail
606+
601607
trap 'echo SIGTERM received' TERM
602608
{{prologue}}
603609
which jupyterhub-singleuser
@@ -671,6 +677,8 @@ class GridengineSpawner(BatchSpawnerBase):
671677
#$ -v {keepvars}
672678
#$ {options}
673679
680+
set -euo pipefail
681+
674682
{prologue}
675683
{cmd}
676684
{epilogue}
@@ -761,6 +769,8 @@ class LsfSpawner(BatchSpawnerBase):
761769
#BSUB -o {homedir}/.jupyterhub.lsf.out
762770
#BSUB -e {homedir}/.jupyterhub.lsf.err
763771
772+
set -euo pipefail
773+
764774
{prologue}
765775
{cmd}
766776
{epilogue}

0 commit comments

Comments
 (0)