#!/bin/bash -eu

function wait_for_server_to_become_healthy() {
  local url=$1
  local timeout=$2
  for _ in $(seq "${timeout}"); do
    set +e
    curl -f --connect-timeout 1 "${url}" > /dev/null 2>&1
    if [ $? -eq 0 ]; then
      echo 0
      return
    fi
    set -e
    sleep 1
  done

  echo 1
}

#!/bin/bash -eu

function wait_for_server_to_become_healthy() {
  local url=$1
  local timeout=$2
  for _ in $(seq "${timeout}"); do
    set +e
    curl -f --connect-timeout 1 "${url}" > /dev/null 2>&1
    last_exit_code=$?
    if [ $last_exit_code -eq 0  ] || [ $last_exit_code -eq 22  ]; then
      echo 0
      return
    fi
    set -e
    sleep 1
  done

  echo 1
}

Update post-start script to handle go1.12 behavior
Update post-start script to handle go1.12 behavior

In go 1.12, misdirected http requests are handled differently than in
previous versions (https://golang.org/doc/go1.12#net/http). This causes
curl to return with an exit code of 22 now because of the 400 Bad Request being
returned by the golang HTTP server.

Since this is different behavior, the post-start script use to fail
to report that the server started successfully.

[#165295898](https://www.pivotaltracker.com/story/show/165295898)

Signed-off-by: Barack Karavani <d90c13280473e40d0128a7cb829e286478c028c5@pivotal.io>
