Spaces:
Sleeping
Sleeping
fix: start nginx before boot logs so HF captures output
Browse filesHF'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>
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|