Spaces:
Sleeping
Sleeping
fix: start nginx LAST so startup logs appear in HF SSE
Browse filesHF's runtime SSE only captures container output during STARTING state
(before port 7860 responds). Move nginx from first to last service so
all boot info + service status appears in the SSE stream. Also:
- Rename /logs β /api/logs (HF intercepts /logs path)
- Revert to bash entrypoint (Python wrapper didn't help)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Dockerfile +1 -1
- ubuntu-server/nginx.conf +5 -4
- ubuntu-server/start-server.sh +13 -13
Dockerfile
CHANGED
|
@@ -59,4 +59,4 @@ ENV SSH_PORT=2222
|
|
| 59 |
|
| 60 |
# Run as root (needed for: apt install persistence, bind mounts, sshd)
|
| 61 |
EXPOSE 7860
|
| 62 |
-
ENTRYPOINT ["
|
|
|
|
| 59 |
|
| 60 |
# Run as root (needed for: apt install persistence, bind mounts, sshd)
|
| 61 |
EXPOSE 7860
|
| 62 |
+
ENTRYPOINT ["/scripts/entrypoint.sh"]
|
ubuntu-server/nginx.conf
CHANGED
|
@@ -33,15 +33,16 @@ http {
|
|
| 33 |
proxy_send_timeout 86400;
|
| 34 |
}
|
| 35 |
|
| 36 |
-
# /logs β full log file (static)
|
| 37 |
-
|
|
|
|
| 38 |
default_type text/plain;
|
| 39 |
add_header Cache-Control "no-cache, no-store";
|
| 40 |
alias /var/log/huggingrun.log;
|
| 41 |
}
|
| 42 |
|
| 43 |
-
# /logs/stream β SSE real-time log stream
|
| 44 |
-
location /logs/stream {
|
| 45 |
proxy_pass http://127.0.0.1:7863/stream;
|
| 46 |
proxy_http_version 1.1;
|
| 47 |
proxy_set_header Connection "";
|
|
|
|
| 33 |
proxy_send_timeout 86400;
|
| 34 |
}
|
| 35 |
|
| 36 |
+
# /api/logs β full log file (static)
|
| 37 |
+
# Note: /logs is intercepted by HF's proxy, so we use /api/logs
|
| 38 |
+
location = /api/logs {
|
| 39 |
default_type text/plain;
|
| 40 |
add_header Cache-Control "no-cache, no-store";
|
| 41 |
alias /var/log/huggingrun.log;
|
| 42 |
}
|
| 43 |
|
| 44 |
+
# /api/logs/stream β SSE real-time log stream
|
| 45 |
+
location /api/logs/stream {
|
| 46 |
proxy_pass http://127.0.0.1:7863/stream;
|
| 47 |
proxy_http_version 1.1;
|
| 48 |
proxy_set_header Connection "";
|
ubuntu-server/start-server.sh
CHANGED
|
@@ -2,6 +2,9 @@
|
|
| 2 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 3 |
# HuggingRun Ubuntu Server: ttyd + SSH-over-WebSocket + nginx
|
| 4 |
# Port 7860 (nginx): web terminal + SSH
|
|
|
|
|
|
|
|
|
|
| 5 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 6 |
|
| 7 |
LOGFILE="/var/log/huggingrun.log"
|
|
@@ -10,20 +13,13 @@ LOGFILE="/var/log/huggingrun.log"
|
|
| 10 |
export SSH_PORT="${SSH_PORT:-2222}"
|
| 11 |
export TTYD_PORT="${TTYD_PORT:-7681}"
|
| 12 |
|
| 13 |
-
# Log to file + stdout
|
| 14 |
log() {
|
| 15 |
local msg="$*"
|
| 16 |
echo "$msg" >> "$LOGFILE"
|
| 17 |
echo "$msg"
|
| 18 |
}
|
| 19 |
|
| 20 |
-
# ββ Start nginx FIRST so HF sees port 7860 ββββββββββββββββββββββ
|
| 21 |
-
nginx -g 'daemon off;' &
|
| 22 |
-
NGINX_PID=$!
|
| 23 |
-
trap "kill $NGINX_PID 2>/dev/null; wait $NGINX_PID 2>/dev/null; exit" SIGTERM SIGINT SIGQUIT
|
| 24 |
-
|
| 25 |
-
sleep 2
|
| 26 |
-
|
| 27 |
# ββ Boot info βββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 28 |
log "========================================"
|
| 29 |
log "[ubuntu] HuggingRun Ubuntu Server"
|
|
@@ -95,7 +91,6 @@ fi
|
|
| 95 |
# ββ Process summary βββββββββββββββββββββββββββββββββββββββββββββββ
|
| 96 |
log "========================================"
|
| 97 |
log "[ubuntu] Services:"
|
| 98 |
-
log "[ubuntu] nginx PID=${NGINX_PID} 0.0.0.0:7860"
|
| 99 |
log "[ubuntu] sshd PID=${SSHD_PID} 127.0.0.1:${SSH_PORT}"
|
| 100 |
log "[ubuntu] log-streamer PID=${STREAMER_PID} 127.0.0.1:7863"
|
| 101 |
log "[ubuntu] ws-ssh-bridge PID=${BRIDGE_PID} 127.0.0.1:7862"
|
|
@@ -108,14 +103,19 @@ log "[ubuntu] All processes:"
|
|
| 108 |
ps aux --no-headers 2>/dev/null | awk '{printf "[ubuntu] %-8s PID=%-6s %s\n", $1, $2, $11}' | while IFS= read -r line; do log "$line"; done
|
| 109 |
|
| 110 |
log "[ubuntu] ββ System ready ββ"
|
| 111 |
-
log "[ubuntu] View logs: curl https://<space>.hf.space/logs"
|
| 112 |
-
log "[ubuntu] Stream SSE: curl -N https://<space>.hf.space/logs/stream"
|
| 113 |
|
| 114 |
-
# ββ Heartbeat ββββββββββββββββββ
|
| 115 |
(while true; do
|
| 116 |
sleep 60
|
| 117 |
log "[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 '?')"
|
| 118 |
done) &
|
| 119 |
|
| 120 |
-
# ββ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
wait $NGINX_PID
|
|
|
|
| 2 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 3 |
# HuggingRun Ubuntu Server: ttyd + SSH-over-WebSocket + nginx
|
| 4 |
# Port 7860 (nginx): web terminal + SSH
|
| 5 |
+
#
|
| 6 |
+
# IMPORTANT: nginx starts LAST so all startup output is visible in
|
| 7 |
+
# HF's runtime SSE (which only captures during STARTING state).
|
| 8 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 9 |
|
| 10 |
LOGFILE="/var/log/huggingrun.log"
|
|
|
|
| 13 |
export SSH_PORT="${SSH_PORT:-2222}"
|
| 14 |
export TTYD_PORT="${TTYD_PORT:-7681}"
|
| 15 |
|
| 16 |
+
# Log to file + stdout (HF captures stdout during STARTING phase)
|
| 17 |
log() {
|
| 18 |
local msg="$*"
|
| 19 |
echo "$msg" >> "$LOGFILE"
|
| 20 |
echo "$msg"
|
| 21 |
}
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
# ββ Boot info βββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 24 |
log "========================================"
|
| 25 |
log "[ubuntu] HuggingRun Ubuntu Server"
|
|
|
|
| 91 |
# ββ Process summary βββββββββββββββββββββββββββββββββββββββββββββββ
|
| 92 |
log "========================================"
|
| 93 |
log "[ubuntu] Services:"
|
|
|
|
| 94 |
log "[ubuntu] sshd PID=${SSHD_PID} 127.0.0.1:${SSH_PORT}"
|
| 95 |
log "[ubuntu] log-streamer PID=${STREAMER_PID} 127.0.0.1:7863"
|
| 96 |
log "[ubuntu] ws-ssh-bridge PID=${BRIDGE_PID} 127.0.0.1:7862"
|
|
|
|
| 103 |
ps aux --no-headers 2>/dev/null | awk '{printf "[ubuntu] %-8s PID=%-6s %s\n", $1, $2, $11}' | while IFS= read -r line; do log "$line"; done
|
| 104 |
|
| 105 |
log "[ubuntu] ββ System ready ββ"
|
|
|
|
|
|
|
| 106 |
|
| 107 |
+
# ββ Heartbeat (writes to logfile for /api/logs) ββββββββββββββββββ
|
| 108 |
(while true; do
|
| 109 |
sleep 60
|
| 110 |
log "[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 '?')"
|
| 111 |
done) &
|
| 112 |
|
| 113 |
+
# ββ Start nginx LAST β opens port 7860 β HF transitions to RUNNING ββ
|
| 114 |
+
# All output above this line is visible in HF's runtime SSE
|
| 115 |
+
# (HF only streams logs during STARTING state, before port 7860 responds)
|
| 116 |
+
log "[ubuntu] Starting nginx on 0.0.0.0:7860 (HF will mark RUNNING) ..."
|
| 117 |
+
nginx -g 'daemon off;' &
|
| 118 |
+
NGINX_PID=$!
|
| 119 |
+
log "[ubuntu] nginx started PID=${NGINX_PID}"
|
| 120 |
+
trap "kill $NGINX_PID 2>/dev/null; wait $NGINX_PID 2>/dev/null; exit" SIGTERM SIGINT SIGQUIT
|
| 121 |
wait $NGINX_PID
|