#!/bin/bash set -e # Initialize MariaDB data directory if needed if [ ! -d "/var/lib/mysql/mysql" ]; then mysql_install_db --user=mysql --datadir=/var/lib/mysql fi # Start MariaDB in background mysqld_safe --user=mysql & # Wait for MariaDB to be ready echo "Waiting for MariaDB..." for i in $(seq 1 60); do if mysqladmin ping --silent 2>/dev/null; then echo "MariaDB is ready." break fi sleep 1 done # Create database and user mysql -u root <<'EOF' CREATE DATABASE IF NOT EXISTS firefly; CREATE USER IF NOT EXISTS 'firefly'@'127.0.0.1' IDENTIFIED BY 'secret_firefly_password'; CREATE USER IF NOT EXISTS 'firefly'@'localhost' IDENTIFIED BY 'secret_firefly_password'; GRANT ALL PRIVILEGES ON firefly.* TO 'firefly'@'127.0.0.1'; GRANT ALL PRIVILEGES ON firefly.* TO 'firefly'@'localhost'; FLUSH PRIVILEGES; EOF # Load data if tables don't exist yet TABLE_COUNT=$(mysql -u root -N -e "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='firefly';" 2>/dev/null || echo "0") if [ "$TABLE_COUNT" -lt "10" ]; then echo "Loading initial database..." mysql -u root firefly < /initdb/001-firefly.sql mysql -u root firefly < /initdb/002-seed.sql echo "Database loaded." fi # Background task: fix storage permissions after entrypoint creates dirs (sleep 15 && chown -R www-data:www-data /var/www/html/storage) & # Run the Firefly entrypoint as PID 1 replacement exec docker-php-serversideup-entrypoint /init