run.sh: PID-file restart; pkill fallback scoped to :8321 so test servers on :8399 are never hit

This commit is contained in:
jozamudi committed 2026-09-16 00:56:48 +00:00
1 parent 673aca827f
commit 826ee9165d
2 files changed
+24 -5

No files matched your search

+1
View File
@@ -4,5 +4,6 @@ __pycache__/
*.tar.gz *.tar.gz
server/data/ server/data/
server.log server.log
server.pid
pi-session-*.html pi-session-*.html
.pytest_cache/ .pytest_cache/
+23 -5
View File
@@ -2,11 +2,29 @@
# launch (or restart) the ani-web server # launch (or restart) the ani-web server
cd "$(dirname "$0")" || exit 1 cd "$(dirname "$0")" || exit 1
[ -x .venv/bin/python ] || { echo "no .venv — run: uv venv .venv && uv pip install --python .venv/bin/python -r requirements.txt"; exit 1; } [ -x .venv/bin/python ] || { echo "no .venv — run: uv venv .venv && uv pip install --python .venv/bin/python -r requirements.txt"; exit 1; }
pkill -f "uvicorn .*app:app" 2>/dev/null; sleep 1
# graceful shutdown waits for in-flight /stream requests; force-kill anything # stop the old instance via its PID file. Only when no pid file exists (first
# still holding the port, or the old process outlives the restart # boot under this scheme) fall back to pkill — and then PORT-SCOPED: the old
pkill -9 -f "uvicorn .*app:app" 2>/dev/null # global "uvicorn .*app:app" pattern also matched the throwaway test server
# (server.app:app --host 127.0.0.1 --port 8399), so an ani-web restart killed
# running test sessions, and a stray test server kept port 8321's holder alive.
PIDF=server.pid
if [ -f "$PIDF" ]; then
oldpid=$(cat "$PIDF" 2>/dev/null)
if [ -n "$oldpid" ] && kill -0 "$oldpid" 2>/dev/null; then
kill "$oldpid" 2>/dev/null
i=0
while kill -0 "$oldpid" 2>/dev/null && [ "$i" -lt 10 ]; do sleep 0.5; i=$((i + 1)); done
kill -9 "$oldpid" 2>/dev/null
fi
rm -f "$PIDF"
else
pkill -f "app:app --host 0.0.0.0 --port 8321" 2>/dev/null
sleep 1
fi
# ANIWEB_SECURE=1: session cookie is Secure — only usable via the HTTPS # ANIWEB_SECURE=1: session cookie is Secure — only usable via the HTTPS
# proxy (plain http://<this machine>:8321 can no longer hold a session). # proxy (plain http://<this machine>:8321 can no longer hold a session).
ANIWEB_SECURE=1 nohup .venv/bin/python -m uvicorn server.app:app --host 0.0.0.0 --port 8321 --timeout-graceful-shutdown 3 > server.log 2>&1 & ANIWEB_SECURE=1 nohup .venv/bin/python -m uvicorn server.app:app --host 0.0.0.0 --port 8321 --timeout-graceful-shutdown 3 > server.log 2>&1 &
echo "ani-web on http://localhost:8321 (pid $!) — use the HTTPS proxy to log in" echo $! > "$PIDF"
echo "ani-web on http://localhost:8321 (pid $(cat "$PIDF")) — use the HTTPS proxy to log in"