diff --git a/jupyterhub_moss/batch_script.sh b/jupyterhub_moss/batch_script.sh index c486c1e..53bb064 100644 --- a/jupyterhub_moss/batch_script.sh +++ b/jupyterhub_moss/batch_script.sh @@ -1,21 +1,22 @@ #!/bin/bash -#SBATCH --job-name=jupyterhub +#SBATCH --job-name=spawner-jupyterhub #SBATCH --chdir={{homedir}} #SBATCH --export={{keepvars}} #SBATCH --get-user-env=L -#SBATCH --partition={{partition}} -{% if runtime %}#SBATCH --time={{runtime}} +{% if output %}#SBATCH --output={% if not output.startswith('/') %}{{homedir}}/{% endif %}{{output}} +{% endif %}{% if partition %}#SBATCH --partition={{partition}} +{% endif %}{% if runtime %}#SBATCH --time={{runtime}} +{% endif %}{% if memory %}#SBATCH --mem={{memory}} {% endif %}{% if gres %}#SBATCH --gres={{gres}} {% endif %}{% if nprocs %}#SBATCH --cpus-per-task={{nprocs}} -{% endif %}{% if mem %}#SBATCH --mem={{mem}} {% endif %}{% if reservation%}#SBATCH --reservation={{reservation}} -{% endif %}{% if exclusive %}#SBATCH --exclusive -{% endif %}{% if not output %}#SBATCH --output=/dev/null -{% endif %}{% if options %}#SBATCH {{options}} -{% endif %} +{% endif %}{% if options %}#SBATCH {{options}}{% endif %} set -euo pipefail trap 'echo SIGTERM received' TERM {{prologue}} -{{cmd}} +which jupyterhub-singleuser +{% if srun %}{{srun}} {% endif %}{{cmd}} +echo "jupyterhub-singleuser ended gracefully" +{{epilogue}} diff --git a/jupyterhub_moss/spawner.py b/jupyterhub_moss/spawner.py index cb4d267..e49a2b1 100644 --- a/jupyterhub_moss/spawner.py +++ b/jupyterhub_moss/spawner.py @@ -359,13 +359,21 @@ def __update_options(self, options, partition_info): The options dict is updated. """ + # Align names with sbatch script + if "mem" in options: + options["memory"] = options["mem"] + + # Convert output option from boolean to file pattern + has_output = options.get("output", False) + options["output"] = "slurm-%j.out" if has_output else "/dev/null" + # Specific handling of exclusive flag - # When mem=0 or all CPU are requested, set the exclusive flag + # When memory=0 or all CPU are requested, set the exclusive flag if ( options.get("nprocs") == partition_info["max_nprocs"] - or options.get("mem") == "0" + or options.get("memory") == "0" ): - options["exclusive"] = True + options["options"] = f"--exclusive {options.get('options', '')}" # Specific handling of ngpus as gres ngpus = options.get("ngpus", 0)