monitor-ai/entrypoint.sh

38 lines
840 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
npx tsx scripts/monitor-worker.ts &
WORKER_PID=$!
# 启动 Next.js standalone server
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
# 守护循环:任一进程退出则容器退出
while true; do
if ! kill -0 $WORKER_PID 2>/dev/null; then
echo "[entrypoint] Worker process exited" >&2
exit 1
fi
if ! kill -0 $NEXT_PID 2>/dev/null; then
echo "[entrypoint] Next.js process exited" >&2
exit 1
fi
sleep 5
done