-
Notifications
You must be signed in to change notification settings - Fork 16
/
entrypoint.sh
executable file
Β·107 lines (92 loc) Β· 2.3 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/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
start_scripts() {
if [ ! -d "$START_SCRIPTS" ]; then
echo "> No start scripts defined."
return 0
fi
echo "> Running start up scripts."
for f in "${START_SCRIPTS}"/*.sh; do
echo "> Running $f"
bash "$f"
done
}
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
start_scripts
"$@" "${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
start_scripts
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