singularity/socket/jupyter

Launcher: singularity

A singularity jupyter notebook or lab to run directly on a remote (e.g., head node)

Usage

$ tunel run-app <server> singularity/socket/jupyter

Arguments

Name Description Split By
container Change the jupyter container used (default is datascience notebook). Must start with container URI to pull (e.g., docker://) NA
jupyterlab Try running jupyterlab instead (e,g. set to true to enable) NA
modules comma separated list of modules to load ,


If split by is provided, this means the argument takes a list, and you should use this as a delimiter.

Needs

  • socket

Examples

# Run jupyter notebook on login node with custom container
tunel run-app waffles singularity/socket/jupyter --container=docker://jupyter/datascience-notebook
# Run Jupyterlab login node (via Singularity container) on open science grid
tunel run-app osg singularity/socket/jupyter --jupyterlab=true

Scripts

jupyter.sh

This app uses the singularity launcher by default.

#!/bin/bash

JOB_NAME="{{ jobname }}"
SOCKET_DIR="{{ scriptdir }}"
mkdir -p ${SOCKET_DIR}

# Include Singularity cachedir if not set
{% include "bash/singularity/set-cache-tmp.sh" %}

# Source ~/bash_profile or ~/.profile
{% include "bash/source-profile.sh" %}

# Set WORKDIR, first to args.workdir, then settings.yml workdir, then $HOME
{% include "bash/set-workdir.sh" %}
cd $WORKDIR

echo "Job is ${JOB_NAME}"
echo "Socket directory is ${SOCKET_DIR}"
echo "Notebook working directory is ${WORKDIR}"

# Create .local folder for default modules, if doesn't exist
{% include "bash/python/create-local.sh" %}

# Remove socket if exists
{% include "bash/socket/set-socket.sh" %}

# Load modules requested by user
{% for module in args.modules %}module load {{ module }} || printf "Could not load {{ module }}\n"
{% endfor %}

# Add variables to PATH
{% for path in paths %}export PATH={{ path }}:${PATH}
{% endfor %}

# Just pull to tmp for now so cleaned up
SIF="${SINGULARITY_CACHEDIR}/jupyter-notebook.sif"
CONTAINER="{% if args.container %}{{ args.container }}{% else %}docker://jupyter/datascience-notebook{% endif %}"

# First effort
if command -v singularity &> /dev/null
then
    printf "singularity pull ${CONTAINER}\n"

    # Only pull the container if we do not have it yet
    if [[ ! -f "${SIF}" ]]; then
        singularity pull ${SIF} ${CONTAINER}
    fi

    # In case they don't exist yet
    mkdir -p $HOME/.jupyter

    printf "singularity exec {% if args.jupyterlab %}--env JUPYTER_ENABLE_LAB=yes{% endif %} --home ${HOME} --bind ${HOME}/.local:/home/jovyan/.local ${CONTAINER} jupyter {% if args.jupyterlab %}lab{% else %}notebook{% endif %} --no-browser --sock ${SOCKET}\n"
    singularity exec {% if args.jupyterlab %}--env JUPYTER_ENABLE_LAB=yes{% endif %} --home ${HOME} --bind ${HOME}/.local:/home/jovyan/.local --bind ${HOME}/.jupyter:/home/jovyan/.jupyter "${SIF}" jupyter {% if args.jupyterlab %}lab{% else %}notebook{% endif %} --no-browser --sock ${SOCKET}
else
    printf "Singularity is not available.\n"
fi

Have any questions, or want to request a new app or launcher? Ask us!