#!/bin/sh set -e echo "========================================" echo " Vollversammlung - Symfony Startup" echo "========================================" # ---------------------------- # Wait for database availability # ---------------------------- wait_for_db() { echo "Waiting for PostgreSQL to be ready..." max_tries=30 try=0 while ! nc -z db 5432 2>/dev/null; do sleep 1 try=$((try + 1)) if [ "$try" -ge "$max_tries" ]; then echo "ERROR: PostgreSQL did not become ready in time." exit 1 fi done echo "PostgreSQL is ready." } wait_for_db # ---------------------------- # Run Doctrine Migrations # ---------------------------- run_migrations() { if [ -f "bin/console" ]; then echo "Running Doctrine Migrations..." php bin/console doctrine:migrations:migrate --no-interaction --all-or-nothing || { echo "WARNING: Migration failed, continuing startup." } fi } run_migrations # ---------------------------- # Configure Mercure for logging # ---------------------------- configure_mercure() { if [ -n "${MERCURE_JWT_SECRET}" ]; then export MERCURE_PUBLISHER_JWT_KEY="${MERCURE_JWT_SECRET}" echo "Mercure Publisher JWT: configured" export MERCURE_SUBSCRIBER_JWT_KEY="${MERCURE_JWT_SECRET}" echo "Mercure Subscriber JWT: configured" else echo "WARNING: MERCURE_JWT_SECRET not set – Mercure logging may not work." fi if [ -n "${MERCURE_URL}" ]; then echo "Mercure URL: ${MERCURE_URL}" fi } configure_mercure # ---------------------------- # Clear cache for current environment # ---------------------------- clear_cache() { if [ -f "bin/console" ]; then echo "Clearing Symfony cache (env=${APP_ENV:-dev})..." php bin/console cache:clear --env="${APP_ENV:-dev}" --no-warmup || true fi } clear_cache # ---------------------------- # Start PHP-FPM or dev server # ---------------------------- echo "" echo "========================================" if [ "${Symfony_USE_DEV_SERVER:-1}" = "1" ] && [ "${APP_ENV:-dev}" = "dev" ]; then echo " Starting Symfony Dev Server on :8000" exec php bin/console server:run 0.0.0.0:8000 --no-reload else echo " Starting PHP-FPM on port 9000" exec php-fpm -F fi