#!/bin/sh set -e # Exit immediately if a command exits with a non-zero status. # Navigate to API directory and start Node.js server in the background # It will run as 'appuser' because of USER appuser in Dockerfile echo "Starting Node.js API server..." cd /app/api node server.js & NODE_PID=$! echo "Node.js API server started with PID $NODE_PID" # Start NGINX in the foreground # It will also run as 'appuser' (master and workers, due to USER appuser and nginx.conf user directive) echo "Starting NGINX..." nginx NGINX_STATUS=$? # If nginx exits, try to kill node process if it's still running if ! kill -0 $NODE_PID > /dev/null 2>&1; then echo "Node process already stopped." else echo "Nginx exited with status $NGINX_STATUS, stopping Node.js API server..." kill $NODE_PID wait $NODE_PID || true # Wait for node to stop, ignore error if already stopped fi exit $NGINX_STATUS