This repository has been archived by the owner on Feb 8, 2020. It is now read-only.
/
run.sh
executable file
·157 lines (124 loc) · 4.35 KB
/
run.sh
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/bash
set -eo pipefail
set -x
# Create a profile for 'notebook'. Add code for setting password for
# the notebook from an environment variable.
jupyter notebook --generate-config
cat >> ${HOME}/.jupyter/jupyter_notebook_config.py << !
import os
password = os.environ.get('JUPYTER_NOTEBOOK_PASSWORD')
if password:
import notebook.auth
c.NotebookApp.password = notebook.auth.passwd(password)
del password
del os.environ['JUPYTER_NOTEBOOK_PASSWORD']
!
# Create a profile for 'ipyparallel'. Create definitions files for
# communicating between the client, controller and engines using known
# ports and security keys. Also enable communication outside of the host
# so can distribute cluster across nodes.
ipython profile create --parallel
IPYPARALLEL_CONTROLLER_NAME=${IPYPARALLEL_CONTROLLER_NAME:-localhost}
TOKEN_FILE=/run/secrets/kubernetes.io/serviceaccount/token
if [ -f ${TOKEN_FILE} ]; then
TOKEN=`cat /run/secrets/kubernetes.io/serviceaccount/token`
IPYPARALLEL_SECRET_KEY=`echo -n $TOKEN | \
openssl dgst -sha256 -hmac "${IPYPARALLEL_CONTROLLER_NAME}" | \
sed -e 's/^.* //'`
else
IPYPARALLEL_SECRET_KEY="abcd1234-abcd-1234-abcd-1234abcd1234"
fi
cat >> ${HOME}/.ipython/profile_default/ipcontroller_config.py << !
c.IPControllerApp.reuse_files = True
c.RegistrationFactory.ip = u'*'
c.HubFactory.engine_ip = u'*'
c.HubFactory.client_ip = u'*'
c.HubFactory.monitor_ip = u'*'
!
cat >> ${HOME}/.ipython/profile_default/ipengine_config.py << !
c.RegistrationFactory.ip = u'*'
!
cat > ${HOME}/.ipython/profile_default/security/ipcontroller-client.json << !
{
"control": 10000,
"interface": "tcp://${IPYPARALLEL_CONTROLLER_NAME}",
"iopub": 10001,
"key": "${IPYPARALLEL_SECRET_KEY}",
"location": "${IPYPARALLEL_CONTROLLER_NAME}",
"mux": 10002,
"notification": 10003,
"pack": "json",
"registration": 10004,
"signature_scheme": "hmac-sha256",
"ssh": "",
"task": 10005,
"task_scheme": "leastload",
"unpack": "json"
}
!
cat > ${HOME}/.ipython/profile_default/security/ipcontroller-engine.json << !
{
"control": 10006,
"hb_ping": 10007,
"hb_pong": 10008,
"interface": "tcp://${IPYPARALLEL_CONTROLLER_NAME}",
"iopub": 10009,
"key": "${IPYPARALLEL_SECRET_KEY}",
"location": "${IPYPARALLEL_CONTROLLER_NAME}",
"mux": 10010,
"pack": "json",
"registration": 10004,
"signature_scheme": "hmac-sha256",
"ssh": "",
"task": 10011,
"unpack": "json"
}
!
unset IPYPARALLEL_SECRET_KEY
# Start up as 'ipyparallel' controller process if enabled.
if [ x"${IPYPARALLEL_SERVICE_TYPE}" = x"controller" ]; then
unset JUPYTER_NOTEBOOK_PASSWORD
exec ipcontroller
fi
# Start up as 'ipyparallel' engine process if enabled.
if [ x"${IPYPARALLEL_SERVICE_TYPE}" = x"engine" ]; then
unset JUPYTER_NOTEBOOK_PASSWORD
exec ipengine
fi
# Enable notebook server extensions.
if [ x"${JUPYTER_SERVER_EXTENSIONS}" != x"" ]; then
for extension in $(echo ${JUPYTER_SERVER_EXTENSIONS} | tr "," " "); do
jupyter serverextension enable --py ${extension} --user
done
fi
# Install assets and enable notebook extensions.
if [ x"${JUPYTER_NOTEBOOK_EXTENSIONS}" != x"" ]; then
for extension in $(echo ${JUPYTER_NOTEBOOK_EXTENSIONS} | tr "," " "); do
jupyter nbextension install --py ${extension} --user
jupyter nbextension enable --py ${extension} --user
done
fi
# Copy files into volume if specified and change notebook directory.
JUPYTER_NOTEBOOK_DIR=${JUPYTER_NOTEBOOK_DIR:-${WARPDRIVE_SRC_ROOT}}
if [ x"${JUPYTER_VOLUME_ROOTDIR}" != x"" ]; then
JUPYTER_VOLUME_WORKSPACE=${JUPYTER_VOLUME_WORKSPACE:-work}
WORKDIR=${JUPYTER_VOLUME_ROOTDIR}/${JUPYTER_VOLUME_WORKSPACE}
if [ ! -d ${WORKDIR} ]; then
mkdir -p ${WORKDIR}
cp -rp ${JUPYTER_NOTEBOOK_DIR}/. ${WORKDIR}
fi
JUPYTER_NOTEBOOK_DIR=${JUPYTER_VOLUME_ROOTDIR}
fi
# Start the Jupyter notebook instance.
cd ${JUPYTER_NOTEBOOK_DIR}
if [ x"${JUPYTER_SERVICE_TYPE}" == x"jupyterhub-singleuser" ]; then
exec jupyterhub-singleuser --ip=* --port=8080 \
--notebook-dir=${JUPYTER_NOTEBOOK_DIR} \
--hub-api-url=${JUPYTERHUB_API_URL} \
--hub-prefix=${JUPYTERHUB_SERVICE_PREFIX} \
--cookie-name=${JUPYTERHUB_SERVICE_NAME} \
--base-url=${JUPYTER_NOTEBOOK_PREFIX} \
--user=${JUPYTER_NOTEBOOK_USER}
fi
exec jupyter notebook --no-browser --ip=* --port=8080 \
--notebook-dir=${JUPYTER_NOTEBOOK_DIR}