Commit 6b497a21 authored by Administrator's avatar Administrator

Update 1 files via Son of Anton

parent 9c247613
...@@ -5,47 +5,52 @@ echo "=========================================" ...@@ -5,47 +5,52 @@ echo "========================================="
echo " THE CLUB ERP — Container Starting" echo " THE CLUB ERP — Container Starting"
echo "=========================================" echo "========================================="
# ── Wait for MySQL to be ready ──
echo "Waiting for MySQL at ${DB_HOST}:${DB_PORT}..."
MAX_TRIES=30
COUNT=0
until mysql -h"${DB_HOST}" -P"${DB_PORT}" -u"${DB_USER}" -p"${DB_PASS}" -e "SELECT 1" &>/dev/null; do
COUNT=$((COUNT + 1))
if [ $COUNT -ge $MAX_TRIES ]; then
echo "MySQL not ready after ${MAX_TRIES} attempts. Aborting."
exit 1
fi
echo " Attempt ${COUNT}/${MAX_TRIES}..."
sleep 2
done
echo "MySQL is ready!"
# ── Create database if it doesn't exist ──
echo "Ensuring database '${DB_NAME}' exists..."
mysql -h"${DB_HOST}" -P"${DB_PORT}" -u"${DB_USER}" -p"${DB_PASS}" -e \
"CREATE DATABASE IF NOT EXISTS \`${DB_NAME}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
echo "Database ready!"
# ── Generate .env from environment variables ── # ── Generate .env from environment variables ──
ENV_FILE="/var/www/html/.env" ENV_FILE="/var/www/html/.env"
cat > "$ENV_FILE" <<EOF cat > "$ENV_FILE" <<ENVEOF
APP_URL=${APP_URL:-http://localhost} APP_URL=${APP_URL:-http://localhost}
APP_DEBUG=${APP_DEBUG:-true} APP_DEBUG=${APP_DEBUG:-true}
APP_ENV=${APP_ENV:-local} APP_ENV=${APP_ENV:-local}
DB_HOST=${DB_HOST:-localhost} DB_HOST=${DB_HOST:-localhost}
DB_PORT=${DB_PORT:-3306} DB_PORT=${DB_PORT:-3306}
DB_NAME=${DB_NAME:-the_club_erp} DB_NAME=${DB_NAME:-the_club_erp}
DB_USER=${DB_USER:-root} DB_USER=${DB_USER:-root}
DB_PASS=${DB_PASS:-} DB_PASS=${DB_PASS:-}
SMS_PROVIDER=${SMS_PROVIDER:-} SMS_PROVIDER=${SMS_PROVIDER:-}
SMS_API_KEY=${SMS_API_KEY:-} SMS_API_KEY=${SMS_API_KEY:-}
SMS_SENDER_ID=${SMS_SENDER_ID:-} SMS_SENDER_ID=${SMS_SENDER_ID:-}
EOF ENVEOF
chown www-data:www-data "$ENV_FILE" chown www-data:www-data "$ENV_FILE"
echo ".env generated!" echo ".env generated!"
# ── Wait for MySQL using PHP (avoids shell escaping issues) ──
echo "Waiting for MySQL..."
MAX_TRIES=30
COUNT=0
until php -r "
\$h='${DB_HOST}'; \$P='${DB_PORT}'; \$u='${DB_USER}'; \$p='${DB_PASS}';
try { new PDO(\"mysql:host=\$h;port=\$P\", \$u, \$p); echo 'OK'; exit(0); }
catch(Exception \$e) { exit(1); }
" 2>/dev/null; do
COUNT=$((COUNT + 1))
if [ $COUNT -ge $MAX_TRIES ]; then
echo "MySQL not ready after ${MAX_TRIES} attempts. Starting Apache anyway..."
exec apache2-foreground
fi
echo " Attempt ${COUNT}/${MAX_TRIES}..."
sleep 2
done
echo "MySQL is ready!"
# ── Create database if needed (using PHP) ──
echo "Ensuring database '${DB_NAME}' exists..."
php -r "
\$h='${DB_HOST}'; \$P='${DB_PORT}'; \$u='${DB_USER}'; \$p='${DB_PASS}'; \$d='${DB_NAME}';
\$pdo = new PDO(\"mysql:host=\$h;port=\$P\", \$u, \$p);
\$pdo->exec(\"CREATE DATABASE IF NOT EXISTS \\\`\$d\\\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci\");
echo 'Database ready!';
"
# ── Run Migrations ── # ── Run Migrations ──
echo "=========================================" echo "========================================="
echo "Running Migrations..." echo "Running Migrations..."
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment