|
1 |
| -#!/bin/bash |
| 1 | +#!/usr/bin/env python -u |
2 | 2 | # Copyright (c) Jupyter Development Team.
|
3 | 3 | # Distributed under the terms of the Modified BSD License.
|
| 4 | +import os |
| 5 | +import sys |
| 6 | +import shlex |
4 | 7 |
|
5 |
| -set -e |
6 | 8 |
|
7 |
| -# The Jupyter command to launch |
8 |
| -# JupyterLab by default |
9 |
| -DOCKER_STACKS_JUPYTER_CMD="${DOCKER_STACKS_JUPYTER_CMD:=lab}" |
| 9 | +# If we are in a JupyterHub, we pass on to `start-singleuser.sh` instead so it does the right thing |
| 10 | +if "JUPYTERHUB_API_TOKEN" not in os.environ: |
| 11 | + print( |
| 12 | + "WARNING: using start-singleuser.sh instead of start-notebook.sh to start a server associated with JupyterHub.", |
| 13 | + file=sys.stderr, |
| 14 | + ) |
| 15 | + os.execvp("/usr/local/bin/start-singleuser.sh", sys.argv[1:]) |
10 | 16 |
|
11 |
| -if [[ -n "${JUPYTERHUB_API_TOKEN}" ]]; then |
12 |
| - echo "WARNING: using start-singleuser.sh instead of start-notebook.sh to start a server associated with JupyterHub." |
13 |
| - exec /usr/local/bin/start-singleuser.sh "$@" |
14 |
| -fi |
15 | 17 |
|
16 |
| -wrapper="" |
17 |
| -if [[ "${RESTARTABLE}" == "yes" ]]; then |
18 |
| - wrapper="run-one-constantly" |
19 |
| -fi |
| 18 | +# Wrap everything in start.sh, no matter what |
| 19 | +command = ["/usr/local/bin/start.sh"] |
20 | 20 |
|
21 |
| -# shellcheck disable=SC1091,SC2086 |
22 |
| -exec /usr/local/bin/start.sh ${wrapper} jupyter ${DOCKER_STACKS_JUPYTER_CMD} ${NOTEBOOK_ARGS} "$@" |
| 21 | +# If we want to survive restarts, tell that to start.sh |
| 22 | +if os.environ.get("RESTARTABLE") == "yes": |
| 23 | + command.append("run-one-constantly") |
| 24 | + |
| 25 | +# We always launch a jupyter subcommand from this script |
| 26 | +command.append("jupyter") |
| 27 | + |
| 28 | +# Launch the configured subcommand. Note that this should be a single string, so we don't split it |
| 29 | +# We default to lab |
| 30 | +jupyter_command = os.environ.get("DOCKER_STACKS_JUPYTER_CMD", "lab") |
| 31 | +command.append(jupyter_command) |
| 32 | + |
| 33 | +# Append any optional NOTEBOOK_ARGS we were passed in. This is supposed to be multiple args passed |
| 34 | +# on to the notebook command, so we split it correctly with shlex |
| 35 | +command += ( |
| 36 | + [] |
| 37 | + if "NOTEBOOK_ARGS" not in os.environ |
| 38 | + else shlex.split(os.environ["NOTEBOOK_ARGS"]) |
| 39 | +) |
| 40 | + |
| 41 | +# Execute the command! |
| 42 | +os.execvp(command[0], command) |
0 commit comments