Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions docker/moodle/scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down