diff --git a/check.sh b/check.sh index bbad6eb037..973302ea88 100755 --- a/check.sh +++ b/check.sh @@ -43,16 +43,39 @@ run_check() { local cmd="$3" echo "> $cmd" set +e # Disable exit-on-error - if $cmd; then # Run the command itself and check if it succeeded. + if bash -c "$cmd"; then # Run the command itself and check if it succeeded. succeeded="$succeeded $check_name" else - docker compose logs "$service" + docker compose logs --tail 30 "$service" # Just show recent logs, not all history failed="$failed $check_name" fi set -e # Re-enable exit-on-error echo # Newline } +mysql_run_check() { + container_name="$1" + mysql_probe="SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = 'root')" + run_check "${container_name}_query" "$container_name" \ + "docker compose exec -T $(printf %q "$container_name") mysql -uroot -se $(printf %q "$mysql_probe")" +} + +if should_check mysql57; then + echo "Checking MySQL 5.7 query endpoint:" + mysql_run_check mysql57 +fi + +if should_check mysql80; then + echo "Checking MySQL 8.0 query endpoint:" + mysql_run_check mysql80 +fi + +if should_check mongo; then + echo "Checking MongoDB status:" + run_check mongo_status mongo \ + "docker compose exec -T mongo mongo --eval \"db.serverStatus()\"" +fi + if should_check registrar; then echo "Checking Registrar heartbeat:" run_check registrar_heartbeat registrar \ @@ -64,15 +87,17 @@ if should_check lms; then run_check lms_heartbeat lms \ "curl --fail -L http://localhost:18000/heartbeat" - echo "Checking CMS heartbeat:" - run_check cms_heartbeat lms \ - "curl --fail -L http://localhost:18010/heartbeat" - echo "Validating LMS volume:" run_check lms_volume lms \ "make validate-lms-volume" fi +if should_check cms; then + echo "Checking CMS heartbeat:" + run_check cms_heartbeat cms \ + "curl --fail -L http://localhost:18010/heartbeat" +fi + if should_check ecommerce; then echo "Checking ecommerce health:" run_check ecommerce_heartbeat ecommerce \ diff --git a/provision.sh b/provision.sh index 0f8eb24f05..c1e1a4cc75 100755 --- a/provision.sh +++ b/provision.sh @@ -160,11 +160,7 @@ docker compose exec -T mysql80 bash -e -c "mysql -uroot mysql" < provision-mysql if needs_mongo "$to_provision_ordered"; then echo -e "${GREEN}Waiting for MongoDB...${NC}" # mongo container and mongo process/shell inside the container - until docker compose exec -T mongo mongo --eval "db.serverStatus()" &> /dev/null - do - printf "." - sleep 1 - done + ./wait-ready.sh mongo echo -e "${GREEN}MongoDB ready.${NC}" echo -e "${GREEN}Creating MongoDB users...${NC}" docker compose exec -T mongo bash -e -c "mongo" < mongo-provision.js diff --git a/wait-ready.sh b/wait-ready.sh index 1f26c0ef0c..7fb1736685 100755 --- a/wait-ready.sh +++ b/wait-ready.sh @@ -15,26 +15,10 @@ if [[ $# == 0 ]]; then exit 0 fi -function wait_db { - container_name="$1" - mysql_probe="SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = 'root')" - until docker compose exec -T "$container_name" mysql -uroot -se "$mysql_probe" &> /dev/null; do +for service_name in "$@"; do + until ./check.sh "$service_name" >/dev/null 2>&1; do printf "." >&2 sleep 1 done - echo >&2 "$container_name is ready" -} - - -for service_name in "$@"; do - case "$service_name" in - mysql*) - wait_db "$service_name" - ;; - # TODO: Add other services... - *) - echo >&2 "Unknown service: $service_name" - exit 1 - ;; - esac + echo >&2 "$service_name is ready" done