#!/bin/sh set -e echo "Starting entrypoint script..." # Ensure required storage directories exist (volume may be freshly mounted) mkdir -p /app/storage/logs /app/storage/kb_uploads # Wait for Redis to be reachable before booting anything that opens a BullMQ # connection. `depends_on: condition: service_healthy` only gates a clean # `up --recreate`; it is NOT re-checked on `docker compose restart` or a # `restart: unless-stopped` bounce, so without this the app can race Docker's # DNS (EAI_AGAIN) or dial a restarted Redis container's stale IP (ECONNREFUSED). # This isn't load-bearing since legacy installs used a mounted entrypoint script # that may override this script, but it's a cost-nothing check for newer installs. # The real check is done by the application itself, but this provides a safety net. REDIS_HOST="${REDIS_HOST:-redis}" REDIS_PORT="${REDIS_PORT:-6379}" echo "Waiting for Redis at ${REDIS_HOST}:${REDIS_PORT}..." for i in $(seq 1 60); do if node -e "const net=require('net');const s=net.connect(Number(process.env.REDIS_PORT||6379),process.env.REDIS_HOST||'redis');s.on('connect',()=>{s.end();process.exit(0)});s.on('error',()=>process.exit(1));" 2>/dev/null; then echo "Redis is up and running!" break fi if [ "$i" -eq 60 ]; then echo "Timed out waiting for Redis at ${REDIS_HOST}:${REDIS_PORT}" >&2 exit 1 fi sleep 1 done # Run AdonisJS migrations echo "Running AdonisJS migrations..." node ace migration:run --force # Seed the database if needed echo "Seeding the database..." node ace db:seed # Start background workers for all queues echo "Starting background workers for all queues..." node ace queue:work --all & # Start the AdonisJS application echo "Starting AdonisJS application..." exec node bin/server.js