#!/bin/sh # Legacy single-container entrypoint. Kept for the existing deployment that # still runs both processes in one container; new deployments use # compose.prod.yaml, which runs the API and the web server separately. set -e echo "Running migrations..." node scripts/run-migrations.js echo "Starting API server on :3000..." node dist/server/index.js & api_pid=$! echo "Waiting for API..." until node -e "fetch('http://127.0.0.1:3000/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))" 2>/dev/null; do if ! kill -0 "$api_pid" 2>/dev/null; then echo "API process exited during startup." exit 1 fi sleep 1 done echo "Starting Next.js on :3001..." node_modules/.bin/next start -p 3001 & web_pid=$! terminate() { kill -TERM "$api_pid" "$web_pid" 2>/dev/null || true } trap terminate TERM INT # Previously the API ran unsupervised in the background: when it died the # container stayed "up" and served a frontend whose every request failed. # Exiting here lets the restart policy replace the container instead. while kill -0 "$api_pid" 2>/dev/null && kill -0 "$web_pid" 2>/dev/null; do sleep 5 done echo "A server process exited; stopping the container." terminate wait "$api_pid" "$web_pid" 2>/dev/null || true exit 1