fedi-feed-router/docker/entrypoint.sh

69 lines
2.1 KiB
Bash
Raw Normal View History

2025-06-30 20:29:55 +02:00
#!/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
2025-06-30 20:29:55 +02:00
# Wait for database to be ready
2025-06-30 21:28:15 +02:00
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
2025-06-30 20:29:55 +02:00
done
2025-06-30 21:28:15 +02:00
echo "Database connection established."
2025-06-30 20:29:55 +02:00
# Run migrations on first start (web container only)
if [ "$1" = "web" ]; then
2025-06-30 21:28:15 +02:00
echo "Running database migrations..."
2025-06-30 20:29:55 +02:00
php artisan migrate --force
2025-06-30 21:28:15 +02:00
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
2025-07-02 21:10:35 +02:00
echo "Dispatching initial sync job..."
php artisan tinker --execute="App\\Jobs\\SyncChannelPostsJob::dispatchForLemmy();"
echo "Fetching initial articles..."
php artisan article:refresh
2025-06-30 20:29:55 +02:00
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..."
2025-07-02 21:10:35 +02:00
exec php artisan queue:work --tries=3 --queue=lemmy-posts,default
2025-06-30 20:29:55 +02:00
;;
*)
echo "Usage: $0 {web|queue}"
exit 1
;;
esac