feat: add cloud deploy fallback runtime

This commit is contained in:
Codex
2026-03-23 13:25:56 +08:00
parent 3ff757e22d
commit bc04c439fb
7 changed files with 120 additions and 6 deletions

39
scripts/server_start.sh Executable file
View File

@@ -0,0 +1,39 @@
#!/usr/bin/env bash
set -euo pipefail
port="${PORT:-43210}"
data_dir="${BOSS_DATA_DIR:-.boss-data}"
data_file="${BOSS_DATA_FILE:-$data_dir/server-store.json}"
pid_file="${BOSS_PID_FILE:-$data_dir/server.pid}"
log_file="${BOSS_LOG_FILE:-$data_dir/server.log}"
mkdir -p "$data_dir"
if [[ -f "$pid_file" ]]; then
existing_pid="$(cat "$pid_file")"
if [[ -n "$existing_pid" ]] && kill -0 "$existing_pid" 2>/dev/null; then
kill "$existing_pid"
for _ in {1..20}; do
if ! kill -0 "$existing_pid" 2>/dev/null; then
break
fi
sleep 1
done
fi
rm -f "$pid_file"
fi
nohup env PORT="$port" BOSS_DATA_FILE="$data_file" node dist/server.js >>"$log_file" 2>&1 < /dev/null &
echo $! > "$pid_file"
for _ in {1..30}; do
if curl -fsS "http://127.0.0.1:${port}/api/health" >/dev/null 2>&1; then
echo "Boss server started on :${port}"
exit 0
fi
sleep 1
done
echo "Boss server failed to become healthy. Recent logs:" >&2
tail -n 80 "$log_file" >&2 || true
exit 1