mirror of
https://github.com/saymrwulf/NTT-learning.git
synced 2026-05-14 20:47:53 +00:00
Report actual Jupyter access URL
This commit is contained in:
parent
f87f51a35c
commit
08e864ac12
3 changed files with 51 additions and 9 deletions
|
|
@ -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"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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."
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue