Skip to content

Instantly share code, notes, and snippets.

@jhamman
Created March 8, 2018 00:51
Show Gist options
  • Select an option

  • Save jhamman/d74f70d2447cdc201fe890089ae91e99 to your computer and use it in GitHub Desktop.

Select an option

Save jhamman/d74f70d2447cdc201fe890089ae91e99 to your computer and use it in GitHub Desktop.
NCAR start-notebook: adapted for use with conda/dask
#!/bin/bash
# Create trap to kill notebook when user is done
kill_server() {
if [[ $JNPID != -1 ]]; then
echo -en "\nKilling Jupyter Notebook Server with PID=$JNPID ... "
kill $JNPID
echo "done"
exit 0
else
exit 1
fi
}
JNPID=-1
trap kill_server SIGHUP SIGINT SIGTERM
# get available port
PORT=8878
DASK_PORT=8787
# Begin server creation
JNHOST=$(hostname)
LOGDIR=/glade/scratch/${USER}/.jupyter-notebook
LOGFILE=${LOGDIR}/log.$(date +%Y%m%dT%H%M%S)
mkdir -p $LOGDIR
if [[ $JNHOST == ch* || $JNHOST == r* ]]; then
STHOST=cheyenne
else
STHOST=$JNHOST
fi
echo "Logging this session in $LOGFILE"
# Check if running on login nodes
if [[ $JNHOST == yslogin* ]]; then
cat << EOF
See "Use of login nodes" here before running Jupyter Notebook on this
node: https://www2.cisl.ucar.edu/resources/yellowstone/using_resources.
Consider running on Geyser instead by using execgy to start a session. (Run execgy -help.)
EOF
elif [[ $JNHOST == cheyenne* ]]; then
cat << EOF
See "Use of login nodes" here before running Jupyter Notebook on this
node: https://www2.cisl.ucar.edu/resources/computational-systems/cheyenne/running-jobs.
Consider running in an interactive job instead by using qinteractive. (Run qinterative -help.)
EOF
fi
jupyter lab $@ --no-browser --ip=$JNHOST --port=$PORT >& $LOGFILE &
JNPID=$!
echo -en "\nStarting jupyter notebook server, please wait ... "
echo -e "done\n---\n"
cat << EOF
Run the following command on your desktop or laptop:
ssh -N -l $USER -L $PORT:${JNHOST}:$PORT -L $DASK_PORT:${JNHOST}:$DASK_PORT ${STHOST}.ucar.edu
Log in with your YubiKey/Cryptocard (there will be no prompt).
Then open a browser and go to http://localhost:$PORT. The Jupyter web
interface will ask you for a token. Use the following:
To stop the server, press Ctrl-C.
EOF
# Wait for user kill command
sleep inf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment