Stream jupyter server logs to a file
By streaming the logs also to a file users can access them from inside
the container which helps them debug issues without having to ask an
admin.
# lightest possible entrypoint that ensures that
# we use a login shell to get a fully configured shell environment
# (e.g. sourcing /etc/profile.d, ~/.bashrc, and friends)
+
+# Setup a file descriptor (FD) that is connected to a tee process which
+# writes its input to $REPO_DIR/.jupyter-server-log.txt
+# We later use this FD as a place to redirect the output of the actual
+# command to. We can't add `tee` to the command directly as that will prevent
+# the container from exiting when `docker stop` is run.
+exec {log_fd}> >(exec tee $REPO_DIR/.jupyter-server-log.txt)
+
if [[ ! -z "${R2D_ENTRYPOINT:-}" ]]; then
if [[ ! -x "$R2D_ENTRYPOINT" ]]; then
chmod u+x "$R2D_ENTRYPOINT"
fi
- exec "$R2D_ENTRYPOINT" "$@"
+ exec "$R2D_ENTRYPOINT" "$@" >&"$log_fd" 2>&1
else
- exec "$@"
+ exec "$@" >&"$log_fd" 2>&1
fi
