From 4075c851edc3339adee8ef02bcc291e21b8a738c Mon Sep 17 00:00:00 2001 From: Ryan Hallisey Date: Wed, 11 Mar 2015 09:35:00 -0400 Subject: The wait_for function needs to be added into all the images This affects both fedora and the centos base images. Wait_for will be intregrated into kolla-common. Co-authored by: Charles Crouch Change-Id: Ide2304b787d4c3bf6fb3949f09e2cf1f450c2173 --- docker/base/kolla-common.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'docker/base') diff --git a/docker/base/kolla-common.sh b/docker/base/kolla-common.sh index 56c658c43..75058e521 100644 --- a/docker/base/kolla-common.sh +++ b/docker/base/kolla-common.sh @@ -19,6 +19,41 @@ check_required_vars() { done } +wait_for() { + local loops=${1:-""} + local sleeptime=${2:-""} + local fail_match_output=${fail_match_output:-""} + local successful_match_output=${successful_match_output:-""} + shift 2 || true + local command="$@" + + if [ -z "$loops" -o -z "$sleeptime" -o -z "$command" ]; then + echo "Incorrect call of wait_for. Refer to docs/wait-for.md for help" + fi + + local i=0 + while [ $i -lt $loops ]; do + i=$((i + 1)) + local status=0 + local output=$(eval $command 2>&1) || status=$? + if [[ -n "$successful_match_output" ]] \ + && [[ $output =~ $successful_match_output ]]; then + break + elif [[ -n "$fail_match_output" ]] \ + && [[ $output =~ $fail_match_output ]]; then + echo "Command output matched '$fail_match_output'." + continue + elif [[ -z "$successful_match_output" ]] && [[ $status -eq 0 ]]; then + break + fi + sleep $sleeptime + done + local seconds=$((loops * sleeptime)) + printf 'Timing out after %d seconds:\ncommand=%s\nOUTPUT=%s\n' \ + "$seconds" "$command" "$output" + exit 1 +} + # Exit unless we receive a successful response from corresponding OpenStack # service. check_for_os_service() { -- cgit v1.2.3