diff --git a/scripts/raijin_jupyter b/scripts/raijin_jupyter new file mode 100755 index 0000000..b5f4a58 --- /dev/null +++ b/scripts/raijin_jupyter @@ -0,0 +1,171 @@ +#!/bin/bash + +# Scott Wales 20190522 + +print_help() { +cat < \$WORKDIR/jobid < "\$WORKDIR/message" + +echo "runjp log dir \$WORKDIR" +cat "\$WORKDIR/message" + +module purge +module use /g/data3/hh5/public/modules +module load pbs +module load conda/analysis3-unstable + +export DASK_LABEXTENSION__FACTORY__MODULE='dask_jobqueue' +export DASK_LABEXTENSION__FACTORY__CLASS='PBSCluster' +export DASK_LABEXTENSION__FACTORY__KWARGS__QUEUE='normal' +export DASK_LABEXTENSION__FACTORY__KWARGS__CORES='8' +export DASK_LABEXTENSION__FACTORY__KWARGS__MEMORY='16gb' +export DASK_LABEXTENSION__FACTORY__KWARGS__RESOURCE_SPEC='ncpus=8,mem=16gb' +export DASK_LABEXTENSION__FACTORY__KWARGS__INTERFACE='ib0' + +jupyter notebook --NotebookApp.token="\\\$TOKEN" --no-browser --ip="\\\$HOSTNAME" --port 8888 +EOQ + + +# Wait for the message file to appear, then return to the local process +while [ ! -f "\$WORKDIR/message" ]; do + sleep 5 +done +cat "\$WORKDIR/message" +EOF +) + +# Grab info from the PBS job +read jobhost token jobid <<< "$message" + +echo "Notebook running as PBS job ${jobid}" +echo +echo "Starting tunnel..." +$SSH -N -L "8888:$jobhost:8888" -L "8787:$jobhost:8787" "$LOGINNODE" & +tunnelid=$! + +# Shut everything down on exit +trap "{ echo 'Closing connections...' ; kill $tunnelid ; $SSH "$LOGINNODE" qdel $jobid ; }" EXIT + +# Wait for startup then open a browser +sleep 5 +URL="http://localhost:8888/lab?token=${token}" + +echo +echo "Opening ${URL}" +if [ "$(uname)" = "Darwin" ]; then + open "$URL" +else + xdg-open "$URL" +fi + +# Keep open as long as the tunnel exists +wait "$tunnelid"