diff --git a/Makefile b/Makefile index db5859f..f1f0ad5 100644 --- a/Makefile +++ b/Makefile @@ -8,10 +8,10 @@ restart: docker compose restart install-plugins: - docker exec -it moodle-app bash /custom_scripts/setup.sh + docker exec -it moodle-app bash -c "while ! /custom_scripts/setup.sh is_moodle_installed || ! /custom_scripts/setup.sh is_moodle_healthy; do sleep 30; done; /custom_scripts/setup.sh" check-updates: - docker exec -it moodle-app bash /custom_scripts/check_updates.sh $(VERSION) + docker exec -it moodle-app bash -c "while ! /custom_scripts/setup.sh is_moodle_installed || ! /custom_scripts/setup.sh is_moodle_healthy; do sleep 30; done; /custom_scripts/check_updates.sh $(VERSION)" common-commands: docker exec -it moodle-app bash /custom_scripts/setup.sh diff --git a/docker-compose.yml b/docker-compose.yml index 87b83c4..88e0b4a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -39,7 +39,7 @@ services: mariadb: condition: service_healthy healthcheck: - test: ["CMD-SHELL", "curl -fs http://localhost:8080/login/index.php || exit 1"] + test: ["CMD-SHELL", "curl -fs http://localhost:8080/login/index.php && curl -fs http://localhost:8080/admin/index.php || exit 1"] interval: 120s timeout: 30s retries: 3 diff --git a/docker/moodle/scripts/setup.sh b/docker/moodle/scripts/setup.sh index c83fd6d..f4ca6dc 100644 --- a/docker/moodle/scripts/setup.sh +++ b/docker/moodle/scripts/setup.sh @@ -138,12 +138,50 @@ install_german_locale() { log_message "🚀 Language configuration script completed successfully!" } +# đŸšĻ Function to check if Moodle is fully installed +is_moodle_installed() { + log_message "🔄 Checking if Moodle is fully installed..." + local db_host="${MOODLE_DATABASE_HOST:-mariadb}" + local db_user="${MOODLE_DATABASE_USER:-bn_moodle}" + local db_password="${MOODLE_DATABASE_PASSWORD:-supersecure123}" + local db_name="${MOODLE_DATABASE_NAME:-bitnami_moodle}" + + local query="SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '$db_name';" + local result=$(mysql -h "$db_host" -u "$db_user" -p"$db_password" -e "$query" -s -N) + + if [[ "$result" -gt 0 ]]; then + log_message "✅ Moodle is fully installed." + return 0 + else + log_message "❌ Moodle is not fully installed yet." + return 1 + fi +} + +# đŸšĻ Function to check the health status of the Moodle service +is_moodle_healthy() { + log_message "🔄 Checking the health status of the Moodle service..." + if curl -fs http://localhost:8080/login/index.php && curl -fs http://localhost:8080/admin/index.php; then + log_message "✅ Moodle service is healthy." + return 0 + else + log_message "❌ Moodle service is not healthy yet." + return 1 + fi +} + # đŸšĻ Main script execution log_message "🏁 Starting setup script..." MOODLE_VERSION=$(grep '$release' "$MOODLE_DIR/version.php" | grep -oP '\d+\.\d+') log_message "â„šī¸ Detected Moodle version: $MOODLE_VERSION" +# Wait for Moodle to be fully installed and healthy +while ! is_moodle_installed || ! is_moodle_healthy; do + log_message "âŗ Waiting for Moodle to be fully installed and healthy..." + sleep 30 +done + install_moosh update_plugin_list filter_plugin_list