fedi-feed-router/docker/entrypoint.sh
2025-07-03 21:16:57 +02:00

63 lines
No EOL
1.9 KiB
Bash

#!/bin/sh
# Exit on any error
set -e
# Check required Lemmy environment variables
if [ -z "$LEMMY_INSTANCE" ] || [ -z "$LEMMY_USERNAME" ] || [ -z "$LEMMY_PASSWORD" ] || [ -z "$LEMMY_COMMUNITY" ]; then
echo "ERROR: Missing required Lemmy configuration variables:"
echo " LEMMY_INSTANCE=${LEMMY_INSTANCE:-'(not set)'}"
echo " LEMMY_USERNAME=${LEMMY_USERNAME:-'(not set)'}"
echo " LEMMY_PASSWORD=${LEMMY_PASSWORD:-'(not set)'}"
echo " LEMMY_COMMUNITY=${LEMMY_COMMUNITY:-'(not set)'}"
echo "Please set all required environment variables before starting the application."
exit 1
fi
# Wait for database to be ready
echo "Waiting for database connection..."
until php -r "
try {
\$pdo = new PDO('mysql:host=mysql;port=3306;dbname=' . getenv('DB_DATABASE'), getenv('DB_USERNAME'), getenv('DB_PASSWORD'));
echo 'Connected';
exit(0);
} catch (Exception \$e) {
exit(1);
}
" > /dev/null 2>&1; do
echo "Database not ready, waiting..."
sleep 5
done
echo "Database connection established."
# Run migrations on first start (web container only)
if [ "$1" = "web" ]; then
echo "Running database migrations..."
php artisan migrate --force
elif [ "$1" = "queue" ]; then
echo "Waiting for migrations to complete..."
# Wait for all migrations to actually finish running
until php artisan migrate:status 2>/dev/null | grep -c "Ran" | grep -q "7"; do
echo "Migrations still running, waiting..."
sleep 3
done
echo "All migrations completed."
echo "Waiting for database to stabilize..."
sleep 5
fi
# Execute the command based on the argument
case "$1" in
"web")
echo "Starting web server..."
exec php artisan serve --host=0.0.0.0 --port=8000
;;
"queue")
echo "Starting queue worker..."
exec php artisan queue:work --tries=3
;;
*)
echo "Usage: $0 {web|queue}"
exit 1
;;
esac