#!/bin/sh set -e echo "Starting Market Data Service API container..." # Wait for database to be ready if [ -f /usr/local/bin/wait-for-db.sh ]; then /usr/local/bin/wait-for-db.sh else echo "Waiting for database using pg_isready..." host="${DB_HOST:-db}" port="${DB_PORT:-5432}" user="${DB_USER:-postgres}" max_attempts=30 attempt=0 while [ $attempt -lt $max_attempts ]; do if PGPASSWORD="${DB_PASSWORD}" pg_isready -h "$host" -p "$port" -U "$user" >/dev/null 2>&1; then echo "Database is ready!" break fi attempt=$((attempt + 1)) echo "Waiting for database... ($attempt/$max_attempts)" sleep 2 done if [ $attempt -eq $max_attempts ]; then echo "ERROR: Database failed to become ready" exit 1 fi fi # Run database migrations echo "Running database migrations..." npx sequelize-cli db:migrate || { echo "ERROR: Database migration failed" exit 1 } echo "Migrations completed successfully" # Start the application echo "Starting Node.js application..." exec "$@"