fedi-feed-router/docker/build/entrypoint.sh

51 lines
1.6 KiB
Bash
Raw Normal View History

2025-07-05 01:10:54 +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
# Wait for database to be ready
echo "Waiting for database connection..."
until php /docker/wait-for-db.php > /dev/null 2>&1; do
echo "Database not ready, waiting..."
sleep 5
done
echo "Database connection established."
# Wait for Redis to be ready
echo "Waiting for Redis connection..."
until php /docker/wait-for-redis.php > /dev/null 2>&1; do
echo "Redis not ready, waiting..."
sleep 2
done
echo "Redis connection established."
# Substitute environment variables in .env file
echo "Configuring environment variables..."
envsubst < .env > .env.tmp && mv .env.tmp .env
# Run migrations and initial setup
echo "Running database migrations..."
php artisan migrate --force
echo "Dispatching initial sync job..."
php artisan tinker --execute="App\\Jobs\\SyncChannelPostsJob::dispatchForLemmy();"
# Start all services in single container
echo "Starting web server, scheduler, and Horizon..."
php artisan schedule:work &
php artisan horizon &
php artisan serve --host=0.0.0.0 --port=8000 &
# Wait for any process to exit
wait