From 16aa48d9b2d9783bbb26cdda7cb9a9e68b540e8b Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 15 Oct 2020 15:14:26 -0700 Subject: [PATCH] configure-rabbitmq: Wait for RabbitMQ to start up. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes an occasional failure in ‘vagrant up --provision’. Signed-off-by: Anders Kaseorg --- scripts/setup/configure-rabbitmq | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scripts/setup/configure-rabbitmq b/scripts/setup/configure-rabbitmq index 1bef6e24fd..d537056f96 100755 --- a/scripts/setup/configure-rabbitmq +++ b/scripts/setup/configure-rabbitmq @@ -17,6 +17,20 @@ fi RABBITMQ_USERNAME=$("$(dirname "$0")/../get-django-setting" RABBITMQ_USERNAME) RABBITMQ_PASSWORD=$("$(dirname "$0")/../get-django-setting" RABBITMQ_PASSWORD) +# Wait for RabbitMQ to start up +try_ping() { + # `rabbitmqctl ping` requires 3.7.6 or newer + out="$("${rabbitmqctl[@]}" eval 'net_adm:ping(node()).')" && [ "$out" = 'pong' ] +} +retries=9 +while ! try_ping 2>/dev/null; do + sleep 1 + if ! ((retries -= 1)); then + try_ping + break + fi +done + "${rabbitmqctl[@]}" delete_user "$RABBITMQ_USERNAME" || true "${rabbitmqctl[@]}" delete_user zulip || true "${rabbitmqctl[@]}" delete_user guest || true