#!/bin/sh set -e # Exit on error echo "=== atBB Container Starting ===" # Start nginx echo "Starting nginx..." nginx sleep 1 # Read nginx PID from PID file if [ ! -f /tmp/nginx.pid ]; then echo "ERROR: nginx failed to start (no PID file)" exit 1 fi NGINX_PID=$(cat /tmp/nginx.pid) # Verify nginx is running if ! kill -0 $NGINX_PID 2>/dev/null; then echo "ERROR: nginx failed to start (process not running)" exit 1 fi echo "nginx started (PID: $NGINX_PID)" # Start appview (background) echo "Starting appview..." cd /app/apps/appview NODE_ENV=production node dist/index.js & APPVIEW_PID=$! sleep 2 # Verify appview started if ! kill -0 $APPVIEW_PID 2>/dev/null; then echo "ERROR: appview failed to start" kill $NGINX_PID 2>/dev/null || true exit 1 fi echo "appview started (PID: $APPVIEW_PID)" # Start web (background) echo "Starting web..." cd /app/apps/web NODE_ENV=production node dist/index.js & WEB_PID=$! sleep 2 # Verify web started if ! kill -0 $WEB_PID 2>/dev/null; then echo "ERROR: web failed to start" kill $NGINX_PID $APPVIEW_PID 2>/dev/null || true exit 1 fi echo "web started (PID: $WEB_PID)" echo "=== All services started, container ready ===" # Cleanup function for graceful shutdown cleanup() { echo "Received shutdown signal, stopping services..." kill $NGINX_PID $APPVIEW_PID $WEB_PID 2>/dev/null || true wait $NGINX_PID $APPVIEW_PID $WEB_PID 2>/dev/null || true exit 0 } # Setup signal handling trap cleanup TERM INT # Monitor processes - exit if any critical service crashes while true; do if ! kill -0 $NGINX_PID 2>/dev/null; then echo "ERROR: nginx crashed, shutting down container" cleanup fi if ! kill -0 $APPVIEW_PID 2>/dev/null; then echo "ERROR: appview crashed, shutting down container" cleanup fi if ! kill -0 $WEB_PID 2>/dev/null; then echo "ERROR: web crashed, shutting down container" cleanup fi sleep 5 done