Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

feat: Unify wait-ready with check.sh; implement mongo wait #1199

Merged
merged 5 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
35 changes: 30 additions & 5 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,36 @@ run_check() {
if $cmd; then # Run the command itself and check if it succeeded.
succeeded="$succeeded $check_name"
else
docker compose logs "$service"
docker compose logs -n30 "$service"
timmc-edx marked this conversation as resolved.
Show resolved Hide resolved
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 \
Expand All @@ -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 \
Expand Down
6 changes: 1 addition & 5 deletions provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
timmc-edx marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
22 changes: 3 additions & 19 deletions wait-ready.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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