69 lines
4.1 KiB
Bash
Executable File
69 lines
4.1 KiB
Bash
Executable File
#!/bin/sh
|
|
set -e
|
|
|
|
# ── FRONTEND ──────────────────────────────────────────
|
|
export FRONT_PORT=${FRONT_PORT:-3001}
|
|
yarn --cwd /app/frontend dev --turbopack --turbo -p "$FRONT_PORT" &
|
|
echo $! > /app/pids/frontend.pid
|
|
|
|
# ── BACKEND ───────────────────────
|
|
export BACKEND_PORT=${BACKEND_PORT:-3000}
|
|
npm --prefix /app/backend run start &
|
|
echo $! > /app/pids/backend.pid
|
|
|
|
# ── APP-SHELL ──────────────────────────────────────────
|
|
export APP_SHELL_PORT=${APP_SHELL_PORT:-4000}
|
|
yarn --cwd /app/app-shell start &
|
|
APP_SHELL_PID=$!
|
|
echo $APP_SHELL_PID > /app/pids/app-shell.pid
|
|
|
|
echo '⌛ Waiting for backend to be ready...'
|
|
|
|
until nc -z localhost "$BACKEND_PORT"; do sleep 2; done
|
|
echo '✔ Backend is listening on port.'
|
|
|
|
sleep 10
|
|
|
|
echo '⌛ Waiting for app-shell to be ready (including Git initialization)...'
|
|
|
|
until nc -z localhost "$APP_SHELL_PORT"; do sleep 2; done
|
|
echo '✔ App-shell is fully ready and listening on port.'
|
|
|
|
echo '⌛ Waiting for frontend to be ready...'
|
|
|
|
until nc -z localhost "$FRONT_PORT"; do sleep 2; done
|
|
echo '✔ Frontend is listening on port.'
|
|
|
|
echo '⌛ Giving frontend time for initial compilation and route setup...'
|
|
sleep 30
|
|
echo '✔ Frontend is likely ready for traffic.'
|
|
|
|
# ── PAGE WARMING (in background) ──────────────────────
|
|
(
|
|
echo '🔥 Warming specific critical pages first…'
|
|
curl -m 60 --retry 5 --retry-delay 10 -L -s -o /dev/null -w "\n✔ warmed %{url_effective} %{http_code}\n" "http://localhost:${FRONT_PORT}/login" || echo "✖ skipped /login (curl failed)"
|
|
curl -m 60 --retry 5 --retry-delay 10 -L -s -o /dev/null -w "\n✔ warmed %{url_effective} %{http_code}\n" "http://localhost:${FRONT_PORT}/dashboard" || echo "✖ skipped /dashboard (curl failed)"
|
|
curl -m 60 --retry 5 --retry-delay 10 -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"
|
|
|