From 08e864ac12a875a4c62fc1d4b9b165e5e914d29a Mon Sep 17 00:00:00 2001 From: saymrwulf Date: Wed, 15 Apr 2026 20:01:56 +0200 Subject: [PATCH] Report actual Jupyter access URL --- scripts/common.sh | 27 +++++++++++++++++++++++++++ scripts/start.sh | 26 +++++++++++++++++++------- scripts/status.sh | 7 +++++-- 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/scripts/common.sh b/scripts/common.sh index 42b3c0f..662ee8c 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -38,3 +38,30 @@ is_running() { kill -0 "$pid" 2>/dev/null } +runtime_json_for_pid() { + local pid="${1:-}" + local runtime_json="$REPO_ROOT/.jupyter_runtime/jpserver-$pid.json" + + [[ -n "$pid" ]] || return 1 + [[ -f "$runtime_json" ]] || return 1 + printf '%s\n' "$runtime_json" +} + +access_url_for_pid() { + local pid="${1:-}" + local runtime_json + + runtime_json="$(runtime_json_for_pid "$pid")" || return 1 + + "$VENV_PY" -c ' +import json +import sys + +with open(sys.argv[1], encoding="utf-8") as handle: + payload = json.load(handle) + +url = payload["url"].rstrip("/") +token = payload.get("token") +print(f"{url}/lab?token={token}" if token else f"{url}/lab") +' "$runtime_json" +} diff --git a/scripts/start.sh b/scripts/start.sh index ed0502b..a2f00da 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -13,7 +13,11 @@ if ! jupyter_installed; then fi if is_running; then - echo "JupyterLab is already running with pid $(<"$PID_FILE")." + 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 @@ -33,12 +37,20 @@ nohup env \ >"$LOG_FILE" 2>&1 & echo $! > "$PID_FILE" -sleep 1 +pid="$(<"$PID_FILE")" -if ! is_running; then - echo "JupyterLab failed to start. Check $LOG_FILE." - exit 1 -fi +for _ in $(seq 1 20); do + if ! is_running; then + echo "JupyterLab failed to start. Check $LOG_FILE." + exit 1 + fi -echo "JupyterLab started at http://127.0.0.1:$PORT/lab" + if access_url="$(access_url_for_pid "$pid" 2>/dev/null)"; then + echo "JupyterLab started at $access_url" + exit 0 + fi + sleep 0.5 +done + +echo "JupyterLab started with pid $pid, but the runtime URL was not detected yet. Check $LOG_FILE." diff --git a/scripts/status.sh b/scripts/status.sh index 374ba36..27cd6de 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -21,11 +21,14 @@ else fi if is_running; then + pid="$(<"$PID_FILE")" echo "server=running" - echo "pid=$(<"$PID_FILE")" + echo "pid=$pid" + if access_url="$(access_url_for_pid "$pid" 2>/dev/null)"; then + echo "access_url=$access_url" + fi else echo "server=stopped" fi echo "notebooks_dir=$REPO_ROOT/notebooks" -