diff --git a/README.md b/README.md index f904a21eb5e5816e26211fc0a2990dbba8865c3e..6287db602672775d76a5a522c6aca349b90e9633 100644 --- a/README.md +++ b/README.md @@ -57,3 +57,4 @@ And use the password set up during installation. server and 8787 for dask clients by default. * Jupyter lab does not currently allow connecting to unix sockets (sockets with a pathname). See https://github.com/jupyter/notebook/issues/2503. + diff --git a/start_jupyter_lab.sbatch b/start_jupyter_lab.sbatch index 2f29cd9cc86646f5bb7ae2ce91b5fe8fe5987a7d..91a6ab2a8fd6cf154206703e61d0b8c843d9b461 100644 --- a/start_jupyter_lab.sbatch +++ b/start_jupyter_lab.sbatch @@ -10,14 +10,22 @@ module purge oops() { - echo "OOPS: $*" - exit 1 + echo "OOPS: $*" + exit 1 } #export HDF5_USE_FILE_LOCKING="FALSE" #export PYTROLL_CHUNK_SIZE="2048" CONDA_ENV=/home/davidh/miniconda3 - source $CONDA_ENV/bin/activate pangeo -echo "ssh -N -L 8888:`hostname`:8888 -L 8787:`hostname`:8787 $USER@iris" | tee -a ${HOME}/.jupyter_lab_connect.txt -jupyter lab --no-browser --ip=`hostname` --port=8888 + +# Hack to find two useable ports +PORTS=$(python -c 'import socket; s1=socket.socket(); s2=socket.socket(); s1.bind(("", 0)); s2.bind(("", 0)); print(s1.getsockname()[1], s2.getsockname()[1]); s1.close(); s2.close()') +export JLAB_PORT=$(echo $PORTS | cut -d' ' -f1) +export DASK_PORT=$(echo $PORTS | cut -d' ' -f2) + +# Write out a usable SSH command to connect to jupyter lab +echo "ssh -N -L 8888:`hostname`:${JLAB_PORT} -L 8787:`hostname`:${DASK_PORT} $USER@iris" | tee -a ${HOME}/.jupyter_lab_connect.txt +# Start jupyter lab +jupyter lab --no-browser --ip=`hostname` --port ${JLAB_PORT} + diff --git a/start_jupyter_lab.sh b/start_jupyter_lab.sh index f5dc23e4f0ef0a4b93e06fbe147c3d1c6de6dec2..f301c93945ba8d926ac5ad4144948e2169c5a180 100755 --- a/start_jupyter_lab.sh +++ b/start_jupyter_lab.sh @@ -10,7 +10,7 @@ CONNECT_FILE="${HOME}/.jupyter_lab_connect.txt" rm -f $CONNECT_FILE # Tell slurm to run jupyter lab and write ssh command to CONNECT_FILE -sbatch --quiet "${SCRIPT_HOME}/start_jupyter_lab.sbatch" +sbatch --quiet "${SCRIPT_HOME}/start_jupyter_lab.sbatch" > /dev/null 2>&1 # Wait for slurm to start the job on a compute node while [ ! -f $CONNECT_FILE ]; do @@ -19,7 +19,7 @@ while [ ! -f $CONNECT_FILE ]; do done # Wait for jupyter lab to completely start -echo "Job started, waiting 5 seconds for jupyter lab to start..." +echo "Job started, waiting 5 seconds for jupyter lab to start..." >&2 sleep 5 # Now that we know it has started print out the SSH command the user should