tao-shen Claude Opus 4.6 commited on
Commit
e97a432
Β·
1 Parent(s): a065584

fix: start nginx before boot logs so HF captures output

Browse files

HF's log API only streams logs after the container port is open.
Start nginx first (background), then print boot info so HF
captures it. Added heartbeat every 60s for monitoring.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. ubuntu-server/start-server.sh +21 -4
ubuntu-server/start-server.sh CHANGED
@@ -10,6 +10,17 @@ exec 2>&1
10
  export SSH_PORT="${SSH_PORT:-2222}"
11
  export TTYD_PORT="${TTYD_PORT:-7681}"
12
 
 
 
 
 
 
 
 
 
 
 
 
13
  echo "========================================"
14
  echo "[ubuntu] HuggingRun Ubuntu Server"
15
  echo "[ubuntu] $(date -u)"
@@ -69,10 +80,10 @@ fi
69
  # ── Process summary ──────────────────────────────────────────────
70
  echo "========================================"
71
  echo "[ubuntu] Services:"
 
72
  echo "[ubuntu] sshd PID=${SSHD_PID} 127.0.0.1:${SSH_PORT}"
73
  echo "[ubuntu] ws-ssh-bridge PID=${BRIDGE_PID} 127.0.0.1:7862"
74
  echo "[ubuntu] ttyd PID=${TTYD_PID} 127.0.0.1:${TTYD_PORT}"
75
- echo "[ubuntu] nginx (foreground) 0.0.0.0:7860"
76
  echo "========================================"
77
 
78
  # ── Installed packages ───────────────────────────────────────────
@@ -83,7 +94,13 @@ echo "[ubuntu] Current packages: $(dpkg-query -W -f='\n' 2>/dev/null | wc -l)"
83
  echo "[ubuntu] All processes:"
84
  ps aux --no-headers 2>/dev/null | awk '{printf "[ubuntu] %-8s PID=%-6s %s\n", $1, $2, $11}' || true
85
 
86
- # ── nginx (foreground, port 7860) ────────────────────────────────
87
- echo "[ubuntu] Starting nginx on 0.0.0.0:7860 (foreground) ..."
88
  echo "[ubuntu] ══ System ready ══"
89
- exec nginx -g 'daemon off;'
 
 
 
 
 
 
 
 
 
10
  export SSH_PORT="${SSH_PORT:-2222}"
11
  export TTYD_PORT="${TTYD_PORT:-7681}"
12
 
13
+ # ── Start nginx FIRST so HF sees port 7860 and starts capturing logs ──
14
+ nginx -g 'daemon off;' &
15
+ NGINX_PID=$!
16
+
17
+ # Forward signals to nginx for clean shutdown
18
+ trap "kill $NGINX_PID 2>/dev/null; wait $NGINX_PID 2>/dev/null; exit" SIGTERM SIGINT SIGQUIT
19
+
20
+ # Small delay to let nginx bind and HF detect the port
21
+ sleep 2
22
+
23
+ # ── Now print boot info (HF is streaming logs at this point) ──────
24
  echo "========================================"
25
  echo "[ubuntu] HuggingRun Ubuntu Server"
26
  echo "[ubuntu] $(date -u)"
 
80
  # ── Process summary ──────────────────────────────────────────────
81
  echo "========================================"
82
  echo "[ubuntu] Services:"
83
+ echo "[ubuntu] nginx PID=${NGINX_PID} 0.0.0.0:7860"
84
  echo "[ubuntu] sshd PID=${SSHD_PID} 127.0.0.1:${SSH_PORT}"
85
  echo "[ubuntu] ws-ssh-bridge PID=${BRIDGE_PID} 127.0.0.1:7862"
86
  echo "[ubuntu] ttyd PID=${TTYD_PID} 127.0.0.1:${TTYD_PORT}"
 
87
  echo "========================================"
88
 
89
  # ── Installed packages ───────────────────────────────────────────
 
94
  echo "[ubuntu] All processes:"
95
  ps aux --no-headers 2>/dev/null | awk '{printf "[ubuntu] %-8s PID=%-6s %s\n", $1, $2, $11}' || true
96
 
 
 
97
  echo "[ubuntu] ══ System ready ══"
98
+
99
+ # ── Heartbeat: periodic log so we can always see the system is alive ──
100
+ (while true; do
101
+ sleep 60
102
+ echo "[ubuntu] heartbeat: $(date -u) | load=$(cat /proc/loadavg 2>/dev/null | cut -d' ' -f1-3) | mem=$(free -h 2>/dev/null | awk '/Mem:/{print $3"/"$2}' || echo '?')"
103
+ done) &
104
+
105
+ # ── Wait for nginx (keep shell as PID 1 for signal handling) ─────
106
+ wait $NGINX_PID