: ${HEALTHCHECK_CURL_MAX_TIME:=10}
: ${HEALTHCHECK_CURL_USER_AGENT:=curl-healthcheck}
: ${HEALTHCHECK_CURL_WRITE_OUT:='\n%{http_code} %{remote_ip}:%{remote_port} %{time_total} seconds\n'}

healthcheck_curl () {
  curl -q --fail \
    --max-time "${HEALTHCHECK_CURL_MAX_TIME}" \
    --user-agent "${HEALTHCHECK_CURL_USER_AGENT}" \
    --write-out "${HEALTHCHECK_CURL_WRITE_OUT}" \
    "$@" || return 1
}

healthcheck_port () {
  process=$1
  shift 1

  port_args=()
  for arg in "$@"; do
    port_args+=("-i" "tcp:${arg}")
  done
  lsof +c0 -nP "${port_args[@]}" | awk '{print $1}' | grep -q "^${process}$"
}

get_config_val () {
  crudini --get "$1" "$2" "$3" 2> /dev/null || echo "$4"
}

: ${HEALTHCHECK_CURL_MAX_TIME:=10}
: ${HEALTHCHECK_CURL_USER_AGENT:=curl-healthcheck}
: ${HEALTHCHECK_CURL_WRITE_OUT:='\n%{http_code} %{remote_ip}:%{remote_port} %{time_total} seconds\n'}

healthcheck_curl () {
  curl -q --fail \
    --max-time "${HEALTHCHECK_CURL_MAX_TIME}" \
    --user-agent "${HEALTHCHECK_CURL_USER_AGENT}" \
    --write-out "${HEALTHCHECK_CURL_WRITE_OUT}" \
    "$@" || return 1
}

healthcheck_port () {
  process=$1

  # ss truncate command name to 15 characters and this behaviour
  # cannot be diabled
  if [ ${#process} -gt 15 ] ; then
    process=${process:0:15}
  fi

  shift 1
  args=$@
  ports=${args// /|}
  ss -ntp | awk '{print $5,"-",$6}' | egrep ":($ports)" | grep "$process"
}

get_config_val () {
  crudini --get "$1" "$2" "$3" 2> /dev/null || echo "$4"
}

Fix port health check false negatives
Fix port health check false negatives

Most of the opened port health checks are failing because containers
are not run under root user. This patch makes it to avoid use of lsof
so that all containers are checked correctly on opened ports.

Closes-bug: #1714077
Co-Authored-By: Derek Higgins <8c59507062293b84c8c2d9036bfc924374412bb1@redhat.com>
Change-Id: I01389ce87f81486fd887d71e6816df76276011e0
