NTT-learning/scripts/start.sh

57 lines
1.3 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/common.sh"
require_venv
ensure_runtime_dirs
if ! jupyter_installed; then
echo "jupyterlab is not installed in .venv. Run scripts/bootstrap.sh first."
exit 1
fi
if is_running; then
2026-04-15 18:01:56 +00:00
pid="$(<"$PID_FILE")"
echo "JupyterLab is already running with pid $pid."
if access_url="$(access_url_for_pid "$pid" 2>/dev/null)"; then
echo "$access_url"
fi
exit 0
fi
PORT="${PORT:-8888}"
nohup env \
JUPYTER_CONFIG_DIR="$REPO_ROOT/.jupyter_config" \
JUPYTER_DATA_DIR="$REPO_ROOT/.jupyter_data" \
JUPYTER_RUNTIME_DIR="$REPO_ROOT/.jupyter_runtime" \
IPYTHONDIR="$REPO_ROOT/.ipython" \
MPLCONFIGDIR="$REPO_ROOT/.cache/matplotlib" \
"$VENV_PY" -m jupyter lab \
--no-browser \
--ip=127.0.0.1 \
--port="$PORT" \
--ServerApp.root_dir="$REPO_ROOT" \
>"$LOG_FILE" 2>&1 &
echo $! > "$PID_FILE"
2026-04-15 18:01:56 +00:00
pid="$(<"$PID_FILE")"
2026-04-15 18:01:56 +00:00
for _ in $(seq 1 20); do
if ! is_running; then
echo "JupyterLab failed to start. Check $LOG_FILE."
exit 1
fi
if access_url="$(access_url_for_pid "$pid" 2>/dev/null)"; then
echo "JupyterLab started at $access_url"
exit 0
fi
2026-04-15 18:01:56 +00:00
sleep 0.5
done
2026-04-15 18:01:56 +00:00
echo "JupyterLab started with pid $pid, but the runtime URL was not detected yet. Check $LOG_FILE."