Skip to content

Commit 41dc003

Browse files
committed
SlurmSpawner: make "srun" optional
- To properly run in slurm, one is supposed to use "srun" for each job step (though this isn't required). dff4482 added the srun, but this has some side-effects, mainly (for me at least) that environment is *actually* handled the way it should be. But this broke some functionality that depended on environment. Since this caused problems, and may cause problems for others, "srun" should be made optional. This does that. - The root problem is that the batch script reads .bashrc / .bash_profile, but when the notebook server is run using 'srun', it clears these environment variables and uses only the keepvars setting. (Of course, this itself is a security risk and the initial purpose of limiting the environment). - To disable srun, set SlurmSpawner.req_srun=''. - If, upon upgrading, your environment goes crazy and you aren't seeing environment variables you expected, try setting this to ''.
1 parent c0da1f3 commit 41dc003

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

batchspawner/batchspawner.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,11 @@ class SlurmSpawner(UserEnvMixin,BatchSpawnerRegexStates):
513513
help="QoS name to submit job to resource manager"
514514
).tag(config=True)
515515

516+
req_srun = Unicode('srun',
517+
help="Job step wrapper, default 'srun'. Set to '' you do not want "
518+
"to run in job step (affects environment handling)"
519+
).tag(config=True)
520+
516521
batch_script = Unicode("""#!/bin/bash
517522
#SBATCH --output={{homedir}}/jupyterhub_slurmspawner_%j.log
518523
#SBATCH --job-name=spawner-jupyterhub
@@ -528,7 +533,7 @@ class SlurmSpawner(UserEnvMixin,BatchSpawnerRegexStates):
528533
trap 'echo SIGTERM received' TERM
529534
{{prologue}}
530535
which jupyterhub-singleuser
531-
srun {{cmd}}
536+
{% if srun %}{{srun}} {% endif %}{{cmd}}
532537
echo "jupyterhub-singleuser ended gracefully"
533538
{{epilogue}}
534539
""").tag(config=True)

0 commit comments

Comments
 (0)