fedi-feed-router/docker/production/start-app.sh
2025-08-15 02:58:14 +02:00

51 lines
No EOL
1.4 KiB
Bash

#!/bin/sh
# Create .env file if it doesn't exist
if [ ! -f /var/www/html/backend/.env ]; then
cp /var/www/html/backend/.env.example /var/www/html/backend/.env 2>/dev/null || touch /var/www/html/backend/.env
fi
# Wait for database to be ready using PHP
echo "Waiting for database..."
until php -r "
\$host = getenv('DB_HOST') ?: 'db';
\$user = getenv('DB_USERNAME') ?: 'ffr_user';
\$pass = getenv('DB_PASSWORD');
\$db = getenv('DB_DATABASE') ?: 'ffr';
try {
\$pdo = new PDO(\"mysql:host=\$host;dbname=\$db\", \$user, \$pass, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false
]);
echo 'Database ready';
exit(0);
} catch (Exception \$e) {
exit(1);
}
" 2>/dev/null; do
echo "Database not ready, waiting..."
sleep 1
done
echo "Database connection established!"
# Generate app key if not set
if ! grep -q "APP_KEY=base64:" /var/www/html/backend/.env; then
cd /var/www/html/backend && php artisan key:generate --force
fi
# Laravel optimizations for production
cd /var/www/html/backend
php artisan config:cache
php artisan route:cache
php artisan view:cache
# Run migrations
cd /var/www/html/backend
php artisan migrate --force
# Run all seeders (same as dev)
cd /var/www/html/backend
php artisan db:seed --force
# Start supervisor to manage nginx and php-fpm
supervisord -c /etc/supervisord.conf