echo"[INIT] Waiting for MySQL at ${DB_HOST:-srv-captain--mysql-db}:${DB_PORT:-3306}..."
echo"[INIT] Waiting for MySQL at ${DB_HOST}:${DB_PORT}..."
MAX_TRIES=30
MAX_TRIES=60
COUNT=0
COUNT=0
until mysql-h"${DB_HOST:-srv-captain--mysql-db}"-P"${DB_PORT:-3306}"-u"${DB_USER:-root}"-p"${DB_PASS:-Alarcade123#}"-e"SELECT 1" &>/dev/null;do
until mysqladmin ping -h"${DB_HOST}"-P"${DB_PORT}"-u"${DB_USER}"-p"${DB_PASS}"--skip-ssl--silent 2>/dev/null;do
COUNT=$((COUNT+1))
COUNT=$((COUNT+1))
if[$COUNT-ge$MAX_TRIES];then
if[$COUNT-ge$MAX_TRIES];then
echo"[ERROR] MySQL not available after ${MAX_TRIES} attempts. Starting Apache anyway..."
echo"[ERROR] MySQL not available after ${MAX_TRIES} attempts. Starting Apache anyway..."
break
break
fi
fi
echo"[INIT] MySQL not ready yet (attempt $COUNT/$MAX_TRIES)..."
echo"[INIT] MySQL not ready (attempt $COUNT/$MAX_TRIES)..."
sleep 2
sleep 2
done
done
echo"[INIT] MySQL is available."
echo"[INIT] MySQL is available."
# ─── Run Schema ───
# ─── Ensure Database Exists ───
DB_NAME="${DB_NAME:-al_arcade_hr}"
mysql -h"${DB_HOST}"-P"${DB_PORT}"-u"${DB_USER}"-p"${DB_PASS}"--skip-ssl\
DB_EXISTS=$(mysql -h"${DB_HOST:-srv-captain--mysql-db}"-P"${DB_PORT:-3306}"-u"${DB_USER:-root}"-p"${DB_PASS:-Alarcade123#}"-se"SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA='${DB_NAME}'" 2>/dev/null ||echo"0")
-e"CREATE DATABASE IF NOT EXISTS \`${DB_NAME}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" 2>/dev/null ||true
if["$DB_EXISTS"="0"]||[-z"$DB_EXISTS"];then
# ─── Check if schema needs to be imported ───
echo"[INIT] Database empty or not found. Running schema..."
mysql -h"${DB_HOST:-srv-captain--mysql-db}"-P"${DB_PORT:-3306}"-u"${DB_USER:-root}"-p"${DB_PASS:-Alarcade123#}" < /var/www/html/database/schema.sql 2>&1 ||echo"[WARN] Schema import had warnings"
-se"SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA='${DB_NAME}'" 2>/dev/null ||echo"0")
echo"[INIT] Schema imported."
if["$TABLE_COUNT"="0"]||[-z"$TABLE_COUNT"];then
echo"[INIT] Database empty. Running schema..."
mysql -h"${DB_HOST}"-P"${DB_PORT}"-u"${DB_USER}"-p"${DB_PASS}"--skip-ssl\
< /var/www/html/database/schema.sql 2>&1 ||echo"[WARN] Schema import had warnings"
# Seed data
if[-f /var/www/html/database/seed.sql ];then
if[-f /var/www/html/database/seed.sql ];then
echo"[INIT] Running seed SQL..."
echo"[INIT] Running seed SQL..."
mysql -h"${DB_HOST:-srv-captain--mysql-db}"-P"${DB_PORT:-3306}"-u"${DB_USER:-root}"-p"${DB_PASS:-Alarcade123#}""${DB_NAME}" < /var/www/html/database/seed.sql 2>&1 ||echo"[WARN] Seed had warnings"
mysql -h"${DB_HOST}"-P"${DB_PORT}"-u"${DB_USER}"-p"${DB_PASS}"--skip-ssl"${DB_NAME}"\
< /var/www/html/database/seed.sql 2>&1 ||echo"[WARN] Seed had warnings"
fi
fi
# Run PHP seed
if[-f /var/www/html/cli/seed.php ];then
if[-f /var/www/html/cli/seed.php ];then
echo"[INIT] Running PHP seed..."
echo"[INIT] Running PHP seed..."
php /var/www/html/cli/seed.php 2>&1 ||echo"[WARN] PHP seed had errors"
php /var/www/html/cli/seed.php 2>&1 ||echo"[WARN] PHP seed had errors"
<bodyclass="error-page"><divclass="error-container"><h1>404</h1><p>Page not found.</p><ahref="/dashboard"class="btn btn-primary">Go Home</a></div></body></html>
<html><head><title>500 Server Error</title><linkrel="stylesheet"href="/assets/css/app.css"></head>
<html>
<bodyclass="error-page"><divclass="error-container"><h1>500</h1><p>Internal server error.</p><ahref="/dashboard"class="btn btn-primary">Go Home</a></div></body></html>