+# Check if rabbitmq is ready by looking for a pid in it's status.
+# The function returns the status of the grep command which callers can check.
+function is_rabbitmq_ready() {
+ local -r ip=$1
+ rm -f rabbit.txt
+ ${SSH} ${ip} "sudo rabbitmqctl status" > rabbit.txt
+ grep pid rabbit.txt
+}
+
+# retry the given command ($3) until success for a number of iterations ($1)
+# sleeping ($2) between tries.
+function retry() {
+ set +e
+ local -r -i max_tries=${1}
+ local -r -i sleep_time=${2}
+ local -r cmd=${3}
+ local -i retries=1
+ local -i rc=1
+ while true; do
+ echo "retry ${cmd}: attempt: ${retries}"
+ ${cmd}
+ rc=$?
+ if ((${rc} == 0)); then
+ break;
+ else
+ if ((${retries} == ${max_tries})); then
+ break
+ else
+ ((retries++))
+ sleep ${sleep_time}
+ fi
+ fi
+ done
+ set -e
+ return ${rc}
+}
+