Skip to content

Commit dff4482

Browse files
committed
Update slurm batch script: handle signals and more options
- By using `srun` for cmd, slurm will properly signal shutdown with SIGTERM in advance. Closes: #50 - Add prologue and epilogue options in case other setup is needed before or after the script runs (e.g. `unset XDG_RUNTIME_DIR`). - Some other script nicesess. - This will eventually need porting to the other spawners, but will require some local knowledge. Slurm first, then others.
1 parent 6bcb70b commit dff4482

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

batchspawner/batchspawner.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ class BatchSpawnerBase(Spawner):
143143
help="Other options to include into job submission script"
144144
).tag(config=True)
145145

146+
req_prologue = Unicode('', \
147+
help="Scipt to run before single user server starts."
148+
).tag(config=True)
149+
150+
req_epilogue = Unicode('', \
151+
help="Scipt to run after single user server end."
152+
).tag(config=True)
153+
146154
req_username = Unicode()
147155
@default('req_username')
148156
def _req_username_default(self):
@@ -500,8 +508,12 @@ class SlurmSpawner(UserEnvMixin,BatchSpawnerRegexStates):
500508
{% endif %}{% if nprocs %}#SBATCH --cpus-per-task={{nprocs}}
501509
{% endif %}{% if options %}#SBATCH {{options}}{% endif %}
502510
511+
trap 'echo SIGTERM received' TERM
512+
{{prologue}}
503513
which jupyterhub-singleuser
504-
{{cmd}}
514+
srun {{cmd}}
515+
echo "jupyterhub-singleuser ended gracefully"
516+
{{epilogue}}
505517
""").tag(config=True)
506518
# outputs line like "Submitted batch job 209"
507519
batch_submit_cmd = Unicode('sudo -E -u {username} sbatch --parsable').tag(config=True)

0 commit comments

Comments
 (0)