From 09e4fc97d89fab3828275f225f1a42b8f0bb400d Mon Sep 17 00:00:00 2001 From: Jusong Yu Date: Fri, 7 Jun 2024 12:49:33 +0200 Subject: [PATCH] Using s6 service ready notification instead of sleep --- .../aiida-core-base/s6-assets/init/aiida-prepare.sh | 5 ----- .../s6-assets/s6-rc.d/rabbitmq/data/check | 3 +++ .../s6-assets/s6-rc.d/rabbitmq/notification-fd | 1 + .../s6-assets/s6-rc.d/rabbitmq/run | 13 +++++++++++-- 4 files changed, 15 insertions(+), 7 deletions(-) create mode 100755 .docker/aiida-core-with-services/s6-assets/s6-rc.d/rabbitmq/data/check create mode 100644 .docker/aiida-core-with-services/s6-assets/s6-rc.d/rabbitmq/notification-fd diff --git a/.docker/aiida-core-base/s6-assets/init/aiida-prepare.sh b/.docker/aiida-core-base/s6-assets/init/aiida-prepare.sh index 30eefc3999..a9e54142fa 100755 --- a/.docker/aiida-core-base/s6-assets/init/aiida-prepare.sh +++ b/.docker/aiida-core-base/s6-assets/init/aiida-prepare.sh @@ -18,11 +18,6 @@ verdi config set warnings.development_version False # If the environment variable `SETUP_DEFAULT_AIIDA_PROFILE` is not set, set it to `true`. if [[ ${SETUP_DEFAULT_AIIDA_PROFILE:-true} == true ]] && ! verdi profile show ${AIIDA_PROFILE_NAME} &> /dev/null; then - # For the container that includes the services, this script is called as soon as the RabbitMQ startup script has - # been launched, but it can take a while for the service to come up. If ``verdi presto`` is called straight away - # it is possible it tries to connect to the service before that and it will configure the profile without a broker. - sleep 5 - # Create AiiDA profile. verdi presto \ --verbosity info \ diff --git a/.docker/aiida-core-with-services/s6-assets/s6-rc.d/rabbitmq/data/check b/.docker/aiida-core-with-services/s6-assets/s6-rc.d/rabbitmq/data/check new file mode 100755 index 0000000000..12a44bd456 --- /dev/null +++ b/.docker/aiida-core-with-services/s6-assets/s6-rc.d/rabbitmq/data/check @@ -0,0 +1,3 @@ +#!/bin/bash + +exec rabbitmq-diagnostics check_running > /dev/null diff --git a/.docker/aiida-core-with-services/s6-assets/s6-rc.d/rabbitmq/notification-fd b/.docker/aiida-core-with-services/s6-assets/s6-rc.d/rabbitmq/notification-fd new file mode 100644 index 0000000000..00750edc07 --- /dev/null +++ b/.docker/aiida-core-with-services/s6-assets/s6-rc.d/rabbitmq/notification-fd @@ -0,0 +1 @@ +3 diff --git a/.docker/aiida-core-with-services/s6-assets/s6-rc.d/rabbitmq/run b/.docker/aiida-core-with-services/s6-assets/s6-rc.d/rabbitmq/run index e5752294ff..8a35acd20f 100644 --- a/.docker/aiida-core-with-services/s6-assets/s6-rc.d/rabbitmq/run +++ b/.docker/aiida-core-with-services/s6-assets/s6-rc.d/rabbitmq/run @@ -2,5 +2,14 @@ with-contenv -foreground { s6-echo "Calling /etc/init/rabbitmq.sh" } -rabbitmq-server +foreground { s6-echo "Starting RMQ server and notifying back when the service is ready" } + + +# For the container that includes the services, aiida-prepare.sh script is called as soon as the RabbitMQ startup script has +# been launched, but it can take a while for the RMQ service to come up. If ``verdi presto`` is called straight away +# it is possible it tries to connect to the service before that and it will configure the profile without a broker. +# Here we use s6-notifyoncheck to do the polling healthy check of the readyness of RMQ service. +# +# -w 500: 500 ms between two invocations of ./data/check + +s6-notifyoncheck -w 500 rabbitmq-server