Clear stale X display lock before starting Xvfb

A bot crash leaves /tmp/.X99-lock behind; the next container start
hits "Server is already active for display 99" and the entrypoint
previously fell through with only a warning, so Chromium then died
with "Missing X server or $DISPLAY" in a tight crash loop. Remove
the stale lock up-front and fail hard if Xvfb still won't come up,
so the failure mode is "container won't start" rather than "bot
crashes forever".

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
jjbruntonandClaude Opus 4.7 committed 2026-05-22 21:04:28 +01:00
1 parent 1b6dfd67e3
commit 665ff8b1f3
1 file changed
+11 -3
+11 -3
View File
@@ -25,22 +25,30 @@ if [ ! -e "${NOVNC_WEB_DIR}/index.html" ] && [ -e "${NOVNC_WEB_DIR}/vnc.html" ];
ln -sf vnc.html "${NOVNC_WEB_DIR}/index.html"
fi
# Clear any stale lock from a prior unclean exit — otherwise Xvfb refuses
# to bind to the display and the bot starts up with no X server.
rm -f "/tmp/.X${DISPLAY_NUM}-lock" "/tmp/.X11-unix/X${DISPLAY_NUM}" 2>/dev/null || true
echo "[entrypoint] starting Xvfb on ${DISPLAY} (${GEOMETRY})"
Xvfb "${DISPLAY}" -screen 0 "${GEOMETRY}" -ac +extension RANDR &
XVFB_PID=$!
# Give Xvfb a moment to come up. Requires x11-utils (xdpyinfo).
XVFB_READY=0
for i in $(seq 1 50); do
if xdpyinfo -display "${DISPLAY}" >/dev/null 2>&1; then
echo "[entrypoint] Xvfb is ready after ${i} checks"
XVFB_READY=1
break
fi
sleep 0.2
if [ "${i}" = "50" ]; then
echo "[entrypoint] WARNING: Xvfb did not respond after 10s" >&2
fi
done
if [ "${XVFB_READY}" != "1" ]; then
echo "[entrypoint] FATAL: Xvfb did not respond after 10s — refusing to launch bot without a display" >&2
exit 1
fi
# Minimal window manager so dialogs and tabs aren't stuck behind the root window.
if command -v fluxbox >/dev/null 2>&1; then
fluxbox >/dev/null 2>&1 &