Spaces:
Sleeping
Sleeping
Adarsh Kumar commited on
Rename start.sh to entrypoint.sh
Browse filesFiles changed (2)
- entrypoint.shAdded+46
- start.shDeleted-57
12345678910111213141516171819202122232425262728293031323334353637383940414243444546#!/usr/bin/env bashset -euo pipefail
echo "[entrypoint] starting up"
mkdir -p /tmp/.X11-unixchmod 1777 /tmp/.X11-unix 2>/dev/null || true
pkill -x Xvfb 2>/dev/null || truerm -f /tmp/.X11-unix/X99 2>/dev/null || true
echo "[entrypoint] starting Xvfb on :99"Xvfb :99 -screen 0 1280x720x24 \ -ac \ +extension GLX \ +extension RANDR \ +render \ -noreset \ -nolisten tcp >/tmp/xvfb.log 2>&1 &
XVFB_PID=$!
cleanup() { echo "[entrypoint] shutting down" kill "$XVFB_PID" 2>/dev/null || true wait "$XVFB_PID" 2>/dev/null || true}trap cleanup SIGTERM SIGINT EXIT
for i in $(seq 1 40); do if xdpyinfo -display :99 >/dev/null 2>&1; then echo "[entrypoint] display :99 is ready" break fi if ! kill -0 "$XVFB_PID" >/dev/null 2>&1; then echo "[entrypoint] Xvfb died early" cat /tmp/xvfb.log || true exit 1 fi sleep 0.5done
export DISPLAY=:99echo "[entrypoint] DISPLAY=$DISPLAY"
exec python -u 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 -e
echo "[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); do if xdpyinfo -display :99 >/dev/null 2>&1; then echo "[entrypoint] ✓ Display :99 is ready (attempt $i)" break fi sleep 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.pyentrypoint.shAdded+46
start.shDeleted-57