#!/usr/bin/env bash

CURRENT_PATH="$(cd $(dirname $0);pwd)"

main()
{
  logger  -p local0.info "`who -m | cut -d\( -f2 |cut -d\) -f1`  ${BASH_SOURCE}; start;successfully execute ${BASH_SOURCE}"
  . /opt/oss/manager/bin/engr_profile.sh
  if [[ "$3" == "no" ]]
  then
      hkres=`python -c "import util.httpclient;client=util.httpclient.CommonHttpClient(\"127.0.0.1\",${1},True,True);print(client.get(\"${2}?mode=start\"));"`
  else
      hkres=`python -c "import util.httpclient;client=util.httpclient.CommonHttpClient(\"::1\",${1},True,True);print(client.get(\"${2}?mode=start\"));"`
  fi
  if test ${hkres:1:3} -eq 200; then
      echo "health check ok"
      return 0
  fi
  logger  -p local0.info "`who -m | cut -d\( -f2 |cut -d\) -f1` ${BASH_SOURCE}; end;successfully execute ${BASH_SOURCE}"
  return 1
}

main $*
exit $?