-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun
executable file
·76 lines (53 loc) · 2.32 KB
/
run
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
set -eo pipefail
### configuration ######################################################
echo "
#Setting Jupyter configuration ... "
#jupyter notebook --generate-config
#CONFIG=$"$HOME/.jupyter/jupyter_notebook_config.py"
#if [ -f "$CONFIG" ]; then#
#
# sed -i "s/c.NotebookApp.tornado_settings = {}/c.NotebookApp.tornado_settings = {'static_url_prefix':'\/notebook\/static\/'}/1" $CONFIG
# sed -i -E "s/#\s?c.NotebookApp.tornado_settings/c.NotebookApp.tornado_settings/1" $CONFIG
# echo "c.NotebookApp.tornado_settings = {'static_url_prefix':'/notebook/static/'}"
#fi
set default ip to 0.0.0.0
if [[ "$NOTEBOOK_ARGS $@" != *"--ip="* ]]; then
NOTEBOOK_ARGS="--ip=0.0.0.0 --NotebookApp.token=''"
fi
# Ensure that assigned uid has entry in /etc/passwd.
if [ `id -u` -ge 10000 ]; then
cat /etc/passwd | sed -e "s/^$NB_USER:/builder:/" > /tmp/passwd
echo "$NB_USER:x:`id -u`:`id -g`:,,,:/home/$NB_USER:/bin/bash" >> /tmp/passwd
cat /tmp/passwd > /etc/passwd
rm /tmp/passwd
fi
# Calculate login token from the supplied password.
if [ x"${JUPYTER_NOTEBOOK_PASSWORD}" != x"" ]; then
NOTEBOOK_ARGS=--NotebookApp.password=`python -c "import notebook.auth; \
print(notebook.auth.passwd(\"$JUPYTER_NOTEBOOK_PASSWORD\"))"`
unset JUPYTER_NOTEBOOK_PASSWORD
fi
# Copy files into volume if specified and change notebook directory.
JUPYTER_NOTEBOOK_DIR=${JUPYTER_NOTEBOOK_DIR:-/home/$NB_USER/work}
if [ x"${PERSISTENT_VOLUME_ROOTDIR}" != x"" ]; then
PERSISTENT_VOLUME_WORKSPACE=${PERSISTENT_VOLUME_WORKSPACE:-work}
WORKDIR=${PERSISTENT_VOLUME_ROOTDIR}/${PERSISTENT_VOLUME_WORKSPACE}
if [ ! -d ${WORKDIR} ]; then
mkdir -p ${WORKDIR}
cp -rp ${JUPYTER_NOTEBOOK_DIR}/. ${WORKDIR}
fi
JUPYTER_NOTEBOOK_DIR=${PERSISTENT_VOLUME_ROOTDIR}
fi
NOTEBOOK_ARGS="$NOTEBOOK_ARGS --notebook-dir=${JUPYTER_NOTEBOOK_DIR}"
cd ${JUPYTER_NOTEBOOK_DIR}
# Activate Python virtual environment if one exists in the volume.
if [ x"${PERSISTENT_VOLUME_ROOTDIR}" != x"" ]; then
PERSISTENT_VOLUME_VIRTUALENV=${PERSISTENT_VOLUME_VIRTUALENV:-venv}
VENVDIR=${PERSISTENT_VOLUME_ROOTDIR}/${PERSISTENT_VOLUME_VIRTUALENV}
if [ -f "${VENVDIR}/bin/jupyter" ]; then
source activate ${VENVDIR}
fi
fi
# Start the Jupyter notebook instance.
exec /usr/local/bin/start-notebook.sh $NOTEBOOK_ARGS