Adarshu07 commited on
Commit
9eb2838
Β·
verified Β·
1 Parent(s): b2031a9

Rename start.sh to entrypoint.sh

Browse files
Files changed (2) hide show
  1. entrypoint.sh +46 -0
  2. start.sh +0 -57
entrypoint.sh ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ echo "[entrypoint] starting up"
5
+
6
+ mkdir -p /tmp/.X11-unix
7
+ chmod 1777 /tmp/.X11-unix 2>/dev/null || true
8
+
9
+ pkill -x Xvfb 2>/dev/null || true
10
+ rm -f /tmp/.X11-unix/X99 2>/dev/null || true
11
+
12
+ echo "[entrypoint] starting Xvfb on :99"
13
+ Xvfb :99 -screen 0 1280x720x24 \
14
+ -ac \
15
+ +extension GLX \
16
+ +extension RANDR \
17
+ +render \
18
+ -noreset \
19
+ -nolisten tcp >/tmp/xvfb.log 2>&1 &
20
+
21
+ XVFB_PID=$!
22
+
23
+ cleanup() {
24
+ echo "[entrypoint] shutting down"
25
+ kill "$XVFB_PID" 2>/dev/null || true
26
+ wait "$XVFB_PID" 2>/dev/null || true
27
+ }
28
+ trap cleanup SIGTERM SIGINT EXIT
29
+
30
+ for i in $(seq 1 40); do
31
+ if xdpyinfo -display :99 >/dev/null 2>&1; then
32
+ echo "[entrypoint] display :99 is ready"
33
+ break
34
+ fi
35
+ if ! kill -0 "$XVFB_PID" >/dev/null 2>&1; then
36
+ echo "[entrypoint] Xvfb died early"
37
+ cat /tmp/xvfb.log || true
38
+ exit 1
39
+ fi
40
+ sleep 0.5
41
+ done
42
+
43
+ export DISPLAY=:99
44
+ echo "[entrypoint] DISPLAY=$DISPLAY"
45
+
46
+ exec python -u server.py
start.sh DELETED
@@ -1,57 +0,0 @@
1
- #!/bin/bash
2
- # ╔══════════════════════════════════════════════════════════════╗
3
- # β•‘ entrypoint.sh β•‘
4
- # β•‘ 1. Create /tmp/.X11-unix if missing β•‘
5
- # β•‘ 2. Start Xvfb on :99 manually (avoids pyvirtualdisplay β•‘
6
- # β•‘ permission issues when running as non-root) β•‘
7
- # β•‘ 3. Export DISPLAY=:99 β•‘
8
- # β•‘ 4. Hand off to Python server β•‘
9
- # β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
10
-
11
- set -e
12
-
13
- echo "[entrypoint] ── Starting up ──────────────────────────────"
14
-
15
- # ── 1. X11 socket directory ──────────────────────────────────
16
- # Xvfb needs this; fails silently if it doesn't exist when
17
- # running as non-root. Pre-create it so Xvfb can use it.
18
- mkdir -p /tmp/.X11-unix
19
- chmod 1777 /tmp/.X11-unix 2>/dev/null || true
20
- echo "[entrypoint] /tmp/.X11-unix ready"
21
-
22
- # ── 2. Kill any stale Xvfb ───────────────────────────────────
23
- pkill Xvfb 2>/dev/null || true
24
- rm -f /tmp/.X11-unix/X99 2>/dev/null || true
25
-
26
- # ── 3. Start Xvfb on :99 ────────────────────────────────────
27
- echo "[entrypoint] Starting Xvfb on :99 ..."
28
- Xvfb :99 -screen 0 1920x1080x24 \
29
- -ac \
30
- +extension GLX \
31
- +extension RANDR \
32
- +render \
33
- -noreset \
34
- -nolisten tcp &
35
-
36
- XVFB_PID=$!
37
- echo "[entrypoint] Xvfb PID=$XVFB_PID"
38
-
39
- # ── 4. Wait for display to be usable ─────────────────────────
40
- for i in $(seq 1 20); do
41
- if xdpyinfo -display :99 >/dev/null 2>&1; then
42
- echo "[entrypoint] βœ“ Display :99 is ready (attempt $i)"
43
- break
44
- fi
45
- sleep 0.5
46
- done
47
-
48
- # ── 5. Export display for all child processes ─────────────────
49
- export DISPLAY=:99
50
- echo "[entrypoint] DISPLAY=$DISPLAY"
51
-
52
- # ── 6. Trap signals so Xvfb dies with the container ──────────
53
- trap "echo '[entrypoint] Shutting down...'; kill $XVFB_PID 2>/dev/null; exit 0" SIGTERM SIGINT
54
-
55
- # ── 7. Launch Python server ───────────────────────────────────
56
- echo "[entrypoint] ── Launching server ────────────────────────"
57
- exec python server.py