-
Notifications
You must be signed in to change notification settings - Fork 26
/
start
54 lines (42 loc) · 2.05 KB
/
start
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
set -ex
# Write all server logs to ~/.jupyter-server-log.txt for debugging
echo "Notebook server start command: $@" | tee -a ~/.jupyter-server-log.txt
# mybinder sends a complex command to detect jupyter notebook or lab, using standard python3 executable:
# arg1: python3
# arg2: -c
# arg3: import os ... (long Python code, which adds "--NotebookApp.default_url=/lab/" to the argument list)
# arg4: --ip=0.0.0.0
# arg5: --port=8888
# arg6: --NotebookApp.base_url=/user/lassoan-slicernotebooks-1g6ow0gs/
# arg7: --NotebookApp.token=sw77G_ZwRdCCE8qy9-R_Tg
# ... (there may be more arguments)
# The docker image does not have system python, just Slicer's therefore we collect the arguments
# that configure the notebook and pass those to Slicer jupyter.
jupyter_args=()
for arg in "$@"
do
if [[ "$arg" =~ ^--ip=.+|^--port.+|^--NotebookApp\..+ ]]; then
jupyter_args+=("$arg")
fi
done
# Recent-enough jupyterlab is available, make it the default UI
jupyter_args+=("--NotebookApp.default_url=/lab/")
echo "Found jupyter notebook arguments: ${jupyter_args[@]}" 2>&1 | tee -a ~/.jupyter-server-log.txt
/home/sliceruser/run.sh
# Make output redirection of server logs more robust
export PYTHONUNBUFFERED=1
# Use bash as shell in Jupyter terminal (much more convenient than the default sh)
export SHELL=/bin/bash
exec /home/sliceruser/Slicer/bin/PythonSlicer -m jupyter notebook "${jupyter_args[@]}" 2>&1 | tee -a ~/.jupyter-server-log.txt
# If launching fails for *any reason* then all the information mybinder provides is something like this:
#
# 2021-10-16T05:57:55Z [Normal] Created container notebook
# 2021-10-16T05:57:55Z [Normal] Started container notebook
#
# ...and connection to the jupyter server times out.
#
# To debug the startup issues, the easiest method is to install system Python
# (similarly to this repository: https://github.com/jupyter/docker-stacks/tree/master/minimal-notebook)
# because mybinder surely works with that, and use the command terminal to access logs (~/.jupyter-server-log.txt)
# and test things interactively.