#!/bin/bash

address=<%= p("diego.rep.listen_addr").sub(/^0\.0\.0\.0:/, "localhost:") %>
start=`date +%s`
timeout=300

echo "$(date): Pinging rep..."
i=1

while [ $(( $(date +%s) - $timeout )) -lt $start ]; do
  if curl --fail --silent http://$address/ping >/dev/null 2>&1; then
    echo "$(date): Success!"
    exit 0
  fi
  echo "$(date): Attempt $i failed. Trying again..."
  i=$((i + 1))
  sleep 1
done

echo "$(date): Timed out pinging rep. Failing post-start."
exit 1

#!/bin/bash

function convert_to_seconds {
  hours_in_seconds=0
  minutes_in_seconds=0
  seconds=0

  if echo "$1" | grep -q '[0-9]\+h'; then
    hours_in_seconds=$(($(echo "$1" | grep -o '[0-9]\+h' | grep -o "[0-9]\+")*3600))
  fi

  if echo "$1" | grep -q '[0-9]\+m'; then
    minutes_in_seconds=$(($(echo "$1" | grep -o '[0-9]\+m' | grep -o "[0-9]\+")*60))
  fi

  if echo "$1" | grep -q '[0-9]\+s'; then
    seconds=$(echo "$1" | grep -o '[0-9]\+s' | grep -o "[0-9]\+")
  fi

  total_seconds=$(($hours_in_seconds + $minutes_in_seconds + $seconds))

  echo $total_seconds
}

address=<%= p("diego.rep.listen_addr").sub(/^0\.0\.0\.0:/, "localhost:") %>
start=`date +%s`
timeout=$(convert_to_seconds <%= p("diego.executor.garden_healthcheck.timeout") %>)

echo "$(date): Pinging rep..."
i=1

while [ $(( $(date +%s) - $timeout )) -lt $start ]; do
  if curl --fail --silent http://$address/ping >/dev/null 2>&1; then
    echo "$(date): Success!"
    exit 0
  fi
  echo "$(date): Attempt $i failed. Trying again..."
  i=$((i + 1))
  sleep 1
done

echo "$(date): Timed out pinging rep. Failing post-start."
exit 1

Use garden healthcheck timeout as rep timeout
Use garden healthcheck timeout as rep timeout

Signed-off-by: Mark DeLillo <cb16bf7df25dbf84b90c1f94696c8a91f946dc1d@pivotal.io>
