Skip to content

Instantly share code, notes, and snippets.

@zonca
Last active May 14, 2020
Embed
What would you like to do?
Batchspawner configuration to launch Jupyter Notebooks on Comet computing nodes
import batchspawner
# The port for this process
c.JupyterHub.hub_port = 8081
# The ip for this process
c.JupyterHub.hub_ip = '127.0.0.1'
class SlurmSpawnerNoLocalUsers(batchspawner.SlurmSpawner):
"""Slurm Spawner that does not need local Unix users on the Hub server"""
def user_env(self, env):
"""get user environment"""
env['USER'] = self.user.name
return env
def _req_homedir_default(self):
return "/home/FIXME/{}/".format(self.user.name)
c.JupyterHub.spawner_class = SlurmSpawnerNoLocalUsers
c.SlurmSpawner.req_nprocs = "2"
c.SlurmSpawner.req_queue = "compute"
c.SlurmSpawner.req_runtime = "01:20:00"
c.SlurmSpawner.req_memory = "4gb"
c.SlurmSpawner.req_host = "comet.sdsc.edu"
c.SlurmSpawner.batch_script = """#!/bin/bash
#SBATCH --job-name="jupyterhub"
#SBATCH --output="/oasis/scratch/comet/FIXME/temp_project/jupyterhub_logs/jupyterhub.%j.%N.out"
#SBATCH --partition={queue}
#SBATCH --nodes=1
###SBATCH --ntasks-per-node=24 # needs to be modified for shared queues
###SBATCH --export=ALL
#SBATCH --time={runtime}
#SBATCH --export={keepvars}
#SBATCH --get-user-env=L
###SBATCH --reservation=reservation_name
# create tunnelbot private SSH key
TUNNELBOT_RSA_PATH=$(mktemp)
echo "-----BEGIN RSA PRIVATE KEY-----
CONF_TUNNELBOTRSAPRIVATEKEY
-----END RSA PRIVATE KEY-----" > $TUNNELBOT_RSA_PATH
chmod 600 $TUNNELBOT_RSA_PATH
# create tunnel from Comet to Jupyterhub
ssh -o "StrictHostKeyChecking no" -i $TUNNELBOT_RSA_PATH -N -f -L 8081:localhost:8081 tunnelbot@xxx-xxx-xxx-xxx.compute.cloud.sdsc.edu
echo "Launch jupyter-singleuser for $JUPYTERHUB_USER"
if [ ! -d $JUPYTERHUB_USER ]
then
git clone https://github.com/sdsc-scicomp/lightning-tutorials-sc18.git $JUPYTERHUB_USER
fi
cd $JUPYTERHUB_USER
{cmd}
"""
c.SlurmSpawner.cmd = [
"/opt/singularity/bin/singularity",
"exec",
"/oasis/scratch/comet/zonca/temp_project/singularity_comet_2018.img",
"/opt/conda/bin/jupyterhub-singleuser",
]
var = "JUPYTERHUB_API_TOKEN,JPY_API_TOKEN,JUPYTERHUB_CLIENT_ID,JUPYTERHUB_HOST,JUPYTERHUB_OAUTH_CALLBACK_URL,JUPYTERHUB_USER,JUPYTERHUB_API_URL,JUPYTERHUB_BASE_URL,JUPYTERHUB_SERVICE_PREFIX"
gateway_user = "FIXME"
ssh_command = " ".join(["ssh", gateway_user + "@{host}", "env"] + [v+"=$"+v for v in var.split(",")]) + " "
c.SlurmSpawner.batch_submit_cmd = ssh_command + "sbatch --parsable"
c.SlurmSpawner.batch_query_cmd = (
ssh_command + """ 'squeue -h -j {job_id} -o "%T %B"' """
)
c.SlurmSpawner.batch_cancel_cmd = ssh_command + "scancel {job_id}"
c.SlurmSpawner.start_timeout = 7200
c.SlurmSpawner.startup_poll_interval = 5.0
c.SlurmSpawner.http_timeout = 7200
c.SlurmSpawner.state_exechost_exp = r'\1.sdsc.edu'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment