#!/bin/sh set -e # ── FRONTEND ────────────────────────────────────────── export FRONT_PORT=$FRONT_PORT yarn --cwd /app/frontend dev --turbo -p "$FRONT_PORT" & echo $! > /app/pids/frontend.pid # ── BACKEND ─────────────────────── yarn --cwd /app/backend start & echo $! > /app/pids/backend.pid # ── Waiting for frontend and backend ─────────────────────── echo '⌛ Waiting for frontend…' until nc -z localhost "$FRONT_PORT"; do sleep 2; done echo '✔ Frontend is up.' echo '⌛ Giving frontend a moment to compile routes...' sleep 5 # --------------------- echo '⌛ Waiting for backend…' until nc -z localhost "$BACKEND_PORT"; do sleep 2; done echo '✔ Backend is up.' # ── APP-SHELL ────────────────────────────────────────── export APP_SHELL_PORT=4000 echo '🚀 Starting app-shell…' yarn --cwd /app/app-shell start & APP_SHELL_PID=$! echo $APP_SHELL_PID > /app/pids/app-shell.pid echo '⌛ Waiting for app-shell to be ready...' until nc -z localhost "$APP_SHELL_PORT"; do sleep 2; done echo '✔ App-shell is listening on port.' sleep 10 echo '✔ App-shell is likely fully initialized.' # ── PAGE WARMING (in background) ────────────────────── ( echo '🔥 Warming specific critical pages first…' curl -L -s -o /dev/null -w "\n✔ warmed %{url_effective} %{http_code}\n" "http://localhost:${FRONT_PORT}/login" || echo "✖ skipped /login (curl failed)" curl -L -s -o /dev/null -w "\n✔ warmed %{url_effective} %{http_code}\n" "http://localhost:${FRONT_PORT}/dashboard" || echo "✖ skipped /dashboard (curl failed)" curl -L -s -o /dev/null -w "\n✔ warmed %{url_effective} %{http_code}\n" "http://localhost:${FRONT_PORT}/" || echo "✖ skipped / (curl failed)" curl -L -s -o /dev/null -w "\n✔ warmed %{url_effective} %{http_code}\n" "http://localhost:${FRONT_PORT}/users/users-list/" || echo "✖ skipped /users/users-list/ (curl failed)" curl -L -s -o /dev/null -w "\n✔ warmed %{url_effective} %{http_code}\n" "http://localhost:${FRONT_PORT}/analytics/analytics-list/" || echo "✖ skipped /analytics/analytics-list/ (curl failed)" curl -L -s -o /dev/null -w "\n✔ warmed %{url_effective} %{http_code}\n" "http://localhost:${FRONT_PORT}/courses/courses-list/" || echo "✖ skipped /courses/courses-list/ (curl failed)" curl -L -s -o /dev/null -w "\n✔ warmed %{url_effective} %{http_code}\n" "http://localhost:${FRONT_PORT}/discussion_boards/discussion_boards-list/" || echo "✖ skipped /discussion_boards/discussion_boards-list/ (curl failed)" curl -L -s -o /dev/null -w "\n✔ warmed %{url_effective} %{http_code}\n" "http://localhost:${FRONT_PORT}/enrollments/enrollments-list/" || echo "✖ skipped /enrollments/enrollments-list/ (curl failed)" curl -L -s -o /dev/null -w "\n✔ warmed %{url_effective} %{http_code}\n" "http://localhost:${FRONT_PORT}/instructors/instructors-list/" || echo "✖ skipped /instructors/instructors-list/ (curl failed)" curl -L -s -o /dev/null -w "\n✔ warmed %{url_effective} %{http_code}\n" "http://localhost:${FRONT_PORT}/students/students-list/" || echo "✖ skipped /students/students-list/ (curl failed)" curl -L -s -o /dev/null -w "\n✔ warmed %{url_effective} %{http_code}\n" "http://localhost:${FRONT_PORT}/roles/roles-list/" || echo "✖ skipped /roles/roles-list/ (curl failed)" curl -L -s -o /dev/null -w "\n✔ warmed %{url_effective} %{http_code}\n" "http://localhost:${FRONT_PORT}/permissions/permissions-list/" || echo "✖ skipped /permissions/permissions-list/ (curl failed)" echo '🚀 Warmup script finished.' ) & # ── Nginx PID 1 ────────────────── echo '🚀 Starting Nginx…' nginx -g "daemon off;" & NGINX_PID=$! trap 'kill $(jobs -p)' TERM INT wait "$NGINX_PID"