Skip to content

Commit

Permalink
[HOPSWORKS-2800] Add utility function to check if a service is ready (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kouzant authored Nov 8, 2021
1 parent bdf5235 commit 38e66b8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
32 changes: 32 additions & 0 deletions files/default/domain_utils.sh
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 7 additions & 0 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 38e66b8

Please sign in to comment.