Spaces:
Sleeping
Sleeping
Adarsh Kumar commited on
Update start.sh
Browse files12345#!/usr/bin/env bashset -eXvfb :99 -screen 0 1280x720x24 -ac +extension RANDR &exec python server.py123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657#!/bin/bash# ╔══════════════════════════════════════════════════════════════╗# ║ entrypoint.sh ║# ║ 1. Create /tmp/.X11-unix if missing ║# ║ 2. Start Xvfb on :99 manually (avoids pyvirtualdisplay ║# ║ permission issues when running as non-root) ║# ║ 3. Export DISPLAY=:99 ║# ║ 4. Hand off to Python server ║# ╚══════════════════════════════════════════════════════════════╝set -eecho "[entrypoint] ── Starting up ──────────────────────────────"# ── 1. X11 socket directory ──────────────────────────────────# Xvfb needs this; fails silently if it doesn't exist when# running as non-root. Pre-create it so Xvfb can use it.mkdir -p /tmp/.X11-unixchmod 1777 /tmp/.X11-unix 2>/dev/null || trueecho "[entrypoint] /tmp/.X11-unix ready"# ── 2. Kill any stale Xvfb ───────────────────────────────────pkill Xvfb 2>/dev/null || truerm -f /tmp/.X11-unix/X99 2>/dev/null || true# ── 3. Start Xvfb on :99 ────────────────────────────────────echo "[entrypoint] Starting Xvfb on :99 ..."Xvfb :99 -screen 0 1920x1080x24 \-ac \+extension GLX \+extension RANDR \+render \-noreset \-nolisten tcp &XVFB_PID=$!echo "[entrypoint] Xvfb PID=$XVFB_PID"# ── 4. Wait for display to be usable ─────────────────────────for i in $(seq 1 20); doif xdpyinfo -display :99 >/dev/null 2>&1; thenecho "[entrypoint] ✓ Display :99 is ready (attempt $i)"breakfisleep 0.5done# ── 5. Export display for all child processes ─────────────────export DISPLAY=:99echo "[entrypoint] DISPLAY=$DISPLAY"# ── 6. Trap signals so Xvfb dies with the container ──────────trap "echo '[entrypoint] Shutting down...'; kill $XVFB_PID 2>/dev/null; exit 0" SIGTERM SIGINT# ── 7. Launch Python server ───────────────────────────────────echo "[entrypoint] ── Launching server ────────────────────────"exec python server.py
start.sh+54-2