# Instead of checking for a file, we now poll the database directly.
# We use an 'until' loop. This will continue to run as long as the command
# The presence of the 'version' record in the config table is the true
# fails (returns a non-zero exit code). It will only stop when the mysql
# indicator that the initial installation has successfully completed.
# command is 100% successful, which guarantees the database is fully installed.
echo" -> Waiting for Moodle first-time installation to complete..."
echo" -> Waiting for Moodle first-time installation to complete..."
timeout=300 # 5 minute timeout
timeout=300 # 5 minute timeout
while! docker exec"$DB_CONTAINER_NAME" mysql -u root -p"$DB_ROOT_PASSWORD""$DB_NAME"-e"SELECT * FROM mdl_config WHERE name = 'version';" | grep-q"version";do
until docker exec"$DB_CONTAINER_NAME" mysql -u root -p"$DB_ROOT_PASSWORD""$DB_NAME"-e"SELECT 1 FROM mdl_config WHERE name = 'version' LIMIT 1;"> /dev/null 2>&1
do
timeout=$((timeout-5))
timeout=$((timeout-5))
if[$timeout-le 0 ];then
if[$timeout-le 0 ];then
echo"❌ ERROR: Moodle installation timed out after 5 minutes."
echo"❌ ERROR: Moodle installation timed out after 5 minutes."
...
@@ -55,7 +56,6 @@ while ! docker exec "$DB_CONTAINER_NAME" mysql -u root -p"$DB_ROOT_PASSWORD" "$D
...
@@ -55,7 +56,6 @@ while ! docker exec "$DB_CONTAINER_NAME" mysql -u root -p"$DB_ROOT_PASSWORD" "$D
done
done
echo"✅ Moodle installation complete (database version found)."
echo"✅ Moodle installation complete (database version found)."