#!/bin/bash # entrypoint.sh — 同时启动 Next.js Server 和 Monitor Worker node /app/server.js & SERVER_PID=$! cd /app && node scripts/monitor-worker.js & WORKER_PID=$! cleanup() { echo "Stopping Server (PID=$SERVER_PID) and Worker (PID=$WORKER_PID)..." kill $SERVER_PID 2>/dev/null kill $WORKER_PID 2>/dev/null wait $SERVER_PID 2>/dev/null wait $WORKER_PID 2>/dev/null echo "Shutdown complete." } trap cleanup SIGTERM SIGINT # 等待任一进程退出(需要 Bash 4.3+) wait -n $SERVER_PID $WORKER_PID EXIT_CODE=$? cleanup exit $EXIT_CODE