port-nimara-client-portal/docker-entrypoint.sh

55 lines
1.5 KiB
Bash

#!/bin/sh
set -e
echo "[Entrypoint] Starting Port Nimara Client Portal..."
# Create logs directory if it doesn't exist
mkdir -p /app/logs
# Install PM2 globally if not already installed
if ! command -v pm2 &> /dev/null; then
echo "[Entrypoint] Installing PM2..."
npm install -g pm2
fi
# Wait for dependent services to be ready
echo "[Entrypoint] Waiting for dependent services..."
# Function to check service availability
check_service() {
local service_name=$1
local service_url=$2
local max_attempts=30
local attempt=0
while [ $attempt -lt $max_attempts ]; do
if curl -s -o /dev/null -w "%{http_code}" "$service_url" | grep -E "^(2|3|4)" > /dev/null; then
echo "[Entrypoint] $service_name is ready"
return 0
fi
attempt=$((attempt + 1))
echo "[Entrypoint] Waiting for $service_name... (attempt $attempt/$max_attempts)"
sleep 2
done
echo "[Entrypoint] Warning: $service_name might not be ready after $max_attempts attempts"
return 1
}
# Check NocoDB if URL is set
if [ ! -z "$NUXT_NOCODB_URL" ]; then
check_service "NocoDB" "$NUXT_NOCODB_URL/api/v1/health" || true
fi
# Check Directus if URL is set
if [ ! -z "$NUXT_PUBLIC_DIRECTUS_URL" ]; then
check_service "Directus" "$NUXT_PUBLIC_DIRECTUS_URL/server/health" || true
fi
# Start the application with PM2
echo "[Entrypoint] Starting application with PM2..."
# Start PM2 in no-daemon mode
exec pm2-runtime start ecosystem.config.js