From 38e66b872d36ab98135b5e9beca44d093843eb45 Mon Sep 17 00:00:00 2001 From: Antonis Kouzoupis Date: Mon, 8 Nov 2021 10:51:08 +0100 Subject: [PATCH] [HOPSWORKS-2800] Add utility function to check if a service is ready (#30) --- files/default/domain_utils.sh | 32 ++++++++++++++++++++++++++++++++ recipes/default.rb | 7 +++++++ 2 files changed, 39 insertions(+) create mode 100644 files/default/domain_utils.sh diff --git a/files/default/domain_utils.sh b/files/default/domain_utils.sh new file mode 100644 index 00000000..57d9af30 --- /dev/null +++ b/files/default/domain_utils.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +_is_service_ready () { + SERVICE=$1 + DOMAIN_NAME=$2 + MAX_ATTEMPTS=10 + if [ $# -eq 3 ] + then + MAX_ATTEMPTS=$3 + fi + echo "Checking readiness of $SERVICE <$DOMAIN_NAME>" + attempt=0 + while ! host $DOMAIN_NAME + do + ((attempt+=1)) + if [ $attempt -gt $MAX_ATTEMPTS ] + then + ! break + fi + if systemctl list-units --full -all | grep -Fq $SERVICE + then + if systemctl is-active --quiet $SERVICE + then + sleep 5 + else + ! break + fi + else + sleep 5 + fi; + done +} \ No newline at end of file diff --git a/recipes/default.rb b/recipes/default.rb index 42ae60f6..35d9b1cf 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -206,4 +206,11 @@ owner node['consul']['user'] group node['consul']['group'] mode 0755 +end + +cookbook_file "#{node['consul']['bin_dir']}/domain_utils.sh" do + source "domain_utils.sh" + owner node['consul']['user'] + group node['consul']['group'] + mode '0755' end \ No newline at end of file