forked from quantbelt/jupyter-quant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·91 lines (79 loc) · 2.06 KB
/
entrypoint.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
#!/usr/bin/env bash
###############################################################################
# entrypoint.sh
#
# docker jupyter
#
# entrypoint script for jupyter docker image. it starts jupyter-lab by
# default.
#
###############################################################################
set -e
DAEMON=jupyter-lab
# APT Proxy Cache
if [ -n "${APT_PROXY}" ]; then
echo "> Setting apt proxy 📌"
echo "Acquire::http { Proxy \"${APT_PROXY}\"; }" |
sudo tee /etc/apt/apt.conf.d/01proxy
fi
# dotfiles
if [ -d "$BYODF" ]; then
echo "> setting dotfiles 📌 at $BYODF"
stow --adopt -t "$HOME" -d "$(dirname "$BYODF")" "$(basename "$BYODF")"
git -C "$BYODF" reset --hard 1>/dev/null
fi
# ssh keys
if [ -d "${SSH_KEYDIR}" ]; then
if [ ! -L /home/"${USER}"/.ssh ]; then
echo "> Setting SSH key 🔑 at $SSH_KEYDIR"
ln -s "${SSH_KEYDIR}" /home/"${USER}"/.ssh
else
echo "> Setting SSH key 🔑: keys already exists /home/${USER}/.ssh"
fi
fi
# jupyterlab-lsp
JUPYTER_OPT='--ContentsManager.allow_hidden=True'
# language server symlink
if [ ! -L "${JUPYTER_SERVER_ROOT}"/.lsp_symlink ]; then
ln -s / .lsp_symlink
fi
stop() {
echo "> 😘 Received SIGINT or SIGTERM. Shutting down $DAEMON"
# Get PID
local pid
pid=$(cat /tmp/$DAEMON.pid)
# Set TERM
kill -SIGTERM "${pid}"
# Wait for exit
wait "${pid}"
# All done.
echo "> Done... $?"
}
echo "> Running Jupyter-lab 🐍"
echo "> Running as $(id)"
echo "> Parameters: $*"
echo "> Jupyter options: $JUPYTER_OPT"
if [ "$(basename "$1" 2>/dev/null)" == "$DAEMON" ]; then
echo "> Starting $* $JUPYTER_OPT"
trap stop SIGINT SIGTERM
"$@" "${JUPYTER_OPT}" &
pid="$!"
echo $pid >/tmp/$DAEMON.pid
echo "> $DAEMON pid: $pid"
wait "${pid}"
exit $?
elif echo "$*" | grep ^--; then
# accept parameters from command line or compose
echo "> Starting $* $JUPYTER_OPT"
trap stop SIGINT SIGTERM
jupyter-lab --no-browser --ip=0.0.0.0 "${JUPYTER_OPT}" "$@" &
pid="$!"
echo "$pid" >/tmp/"$DAEMON".pid
echo "> $DAEMON pid: $pid"
wait "${pid}"
exit $?
else
# run command from docker run
echo "> Starting $* "
exec "$@"
fi