feat: add cloud deploy fallback runtime
This commit is contained in:
39
scripts/server_start.sh
Executable file
39
scripts/server_start.sh
Executable 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
|
||||
Reference in New Issue
Block a user