monitor-ai/entrypoint.sh

39 lines
947 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
set -e
# entrypoint.sh — 启动 Next.js standalone server + Monitor Worker
echo "[entrypoint] Starting monitor-ai..."
# 启动 MonitorWorker后台tsx 即时执行 TypeScript
# Worker 失败不影响 Next.js 主进程
npx tsx scripts/monitor-worker.ts &
WORKER_PID=$! || true
# 启动 Next.js standalone server
HOSTNAME=0.0.0.0 node server.js &
NEXT_PID=$!
echo "[entrypoint] Worker PID: $WORKER_PID, Next.js PID: $NEXT_PID"
# 信号处理
cleanup() {
echo "[entrypoint] Shutting down..."
kill $WORKER_PID $NEXT_PID 2>/dev/null
wait
exit 0
}
trap cleanup SIGTERM SIGINT
# 守护循环Next.js 退出则容器退出Worker 失败仅警告
while true; do
if ! kill -0 $WORKER_PID 2>/dev/null; then
echo "[entrypoint] Worker process exited (non-fatal)" >&2
WORKER_PID=0
fi
if ! kill -0 $NEXT_PID 2>/dev/null; then
echo "[entrypoint] Next.js process exited" >&2
exit 1
fi
sleep 5
done