#!/bin/sh
# Starts render-service/ (whiteboard frame mode's Excalidraw-to-PNG
# sidecar, see its own README) in the background, bound to 127.0.0.1 --
# reachable from this container's Python process, never from outside it.
# Then execs uvicorn as the foreground/PID 1 process so it receives
# Docker's stop signal directly.
#
# Wrapped in a restart loop, not a bare `node ... &`: a bare background
# process that crashes stays dead for good, with nothing to bring it
# back -- turning any single render crash (a not-yet-found jsdom/
# Excalidraw edge case, say) into a silent, permanent whiteboard outage
# that looks exactly like "stuck showing stale content forever" from the
# outside, since routers/common.py's get_or_refresh_whiteboard falls
# back to the last good cached image on every failed refresh rather than
# going blank. The 2s sleep just avoids a hot-crash-loop pegging a core
# if something's wrong at every single startup.
(
  while true; do
    node ./render-service/server.js
    echo "whiteboard render sidecar exited (code $?) -- restarting in 2s" >&2
    sleep 2
  done
) &
exec uvicorn app.main:app --host 0.0.0.0 --port 8420
