From 257a7389cf5064bf0d77e2aa1205a59e344e1754 Mon Sep 17 00:00:00 2001
From: Sofiane Bendoukha <bendoukha@dkrz.de>
Date: Wed, 7 Oct 2020 13:45:33 +0200
Subject: [PATCH] Added first support for singularity.

---
 start-jupyter | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/start-jupyter b/start-jupyter
index 55e0587..37baed4 100755
--- a/start-jupyter
+++ b/start-jupyter
@@ -93,6 +93,11 @@ SJ_INCFILE=""
 # where jupyter is running need a shared home file system.
 readonly SJ_FRONTEND_HOST="mistralpp.dkrz.de"
 
+# Image
+#
+# start the jupyter notebook in a singularity container from a given 
+# image name.
+SJ_IMAGE=""
 
 function clean_up () {
     trap - ERR EXIT
@@ -136,13 +141,14 @@ Available values for OPTION include:
   -p partition   run job on partition
   -t time        job runtime
   -u username    use username for login
+  -s image       singularity image
 
 EOF
 }
 
 function parse_options () {
     local option
-    while getopts 'A:c:di:n:p:t:u:' option; do
+    while getopts 'A:c:di:n:p:t:u:s:' option; do
         case ${option} in
             A) SJ_ACCTCODE="$OPTARG"
                ;;
@@ -160,6 +166,8 @@ function parse_options () {
                ;;
             u) SJ_USERNAME="$OPTARG"
                ;;
+            s) SJ_IMAGE="$OPTARG"
+               ;;
             ?) usage
             exit 1
             ;;
@@ -173,6 +181,7 @@ function parse_options () {
     readonly SJ_PARTITION
     readonly SJ_RUNTIME
     readonly SJ_USERNAME
+    readonly SJ_IMAGE
 }
 
 function ssh_frontend () {
@@ -206,16 +215,19 @@ function which_jupyter() {
     local which
     which="$(source_incfile "which jupyter")"
     ssh_frontend "/bin/bash -lc \"${which}\""
-}
+}  
 
 function assemble_commandline () {
     local logfile="$1"
 
-    local commandline="jupyter ${SJ_COMMAND} --no-browser 2>> ${logfile}"
+    local commandline="jupyter ${SJ_COMMAND} --no-browser 2>> ${logfile}" 
     # If we are not running a job, we have to perform our own scheduling
     if [[ -z ${SJ_ACCTCODE} ]]; then
         commandline="nohup ${commandline} > /dev/null & echo \$!"
     fi
+    if [[ -n ${SJ_IMAGE} ]]; then
+        commandline="singularity exec ${SJ_IMAGE} ${commandline}"
+    fi 
     commandline="$(source_incfile "${commandline}")"
     echo "${commandline}"
 }
@@ -342,6 +354,7 @@ function main () {
     trap clean_up INT QUIT TERM ERR EXIT
 
     echo "Establishing ssh master connection."
+    set -x
     # Set up control master for connection sharing
     mkdir -p "${HOME}/.ssh"
     ssh_socket_dir="$(mktemp -d "${HOME}/.ssh/socket.XXXXX")"
-- 
GitLab