Get error: Unexpected response code: 400 (Invalid check: TTL must be > 0 for TTL checks) when register service with args check

Hi,
When I add args type of checks, then get error message when register service.
How can I fixed this error? thanks a lot.

$ consul services register demo-svc.json

Error registering service “demo-svc”: Unexpected response code: 400 (Invalid check: TTL must be > 0 for TTL checks)

demo-svc.json

{
  "service": {
    "name": "demo-svc",
    "tags": [
      "default"
    ],
    "Address": "demo-service.default.svc.cluster.local",
    "port": 8080,
    "checks": [
      {
        "id": "demo-args",
        "name": "args check",
        "args": ["/tmp/test.sh"],
        "interval": "10s",
        "timeout": "1s"
      }
    ] 
  }
}

/tmp/test.sh on demo-pod

#!/bin/bash
exit 0

helm-chart/values.yaml

server:
  extraConfig: |
    {
      "enable_script_checks": true,
      "enable_local_script_checks": true
    }

Hi @chiyt27,

This is a known bug in Consul. The problem is explained in detail at service script health checks not working · Issue #6923 · hashicorp/consul · GitHub.

As a workaround, you can register the service to Consul using the /agent/service/register API.

demo-svc-api-reg.json

{
  "name": "demo-svc",
  "tags": [
    "default"
  ],
  "Address": "demo-service.default.svc.cluster.local",
  "port": 8080,
  "checks": [
    {
      "id": "demo-args",
      "name": "args check",
      "args": [
        "/tmp/test.sh"
      ],
      "interval": "10s",
      "timeout": "1s"
    }
  ]
}
$ curl --request PUT --data @demo-svc-api-reg.json http://127.0.0.1:8500/v1/agent/service/register

Thanks for your reply! :blush:
I had registered my args-check success through by the API, but appear a new question.

Consul UI shows that args-check can’t find the file.

This is a picture about test.sh’s execute permission, content and using ‘exec’ to execute test.sh in pod.

demo-svc-api-reg.json
I remove the “id”: “demo-args” because the API returns ‘Request decode failed: json: unknown field “id”’.

{
  "name": "demo-svc",
  "tags": [
    "default"
  ],
  "Address": "demo-service.default.svc.cluster.local",
  "port": 8080,
  "checks": [
    {
      "name": "args check",
      "args": [
        "/tmp/test.sh"
      ],
      "interval": "10s",
      "timeout": "1s"
    }
  ]
}

How to Consul agent find the script file and execute it?

Hi @blake ,

I ref this post and try the pierresouchay’s suggest.

 "args": ["/bin/ls", "/home"],

then I got the check output is

consul

Is the script not run in my demo-service?

Hi @chiyt27,

My apologies for not clarifying this earlier. Consul health checks are run within the context of the agent that is executing them. Script checks, like the one you provided, will be run by the Consul client/server agent.

If you want to run a health check against your pod, you need to configure a network-level health check (i.e., TCP, HTTP, gRPC, etc) so that the agent can communicate with your target service.

1 Like

Hi @blake
Let me know if I understood correctly.
if I am trying to register a grpc service running in a pod having checks as [“/bin/grpc_health_probe”,“-addr=:50051”] Consul client can’t perform health check on it?

Second, I have to make my server expose an grpc health check endpoint on a port, like we do for http on “/health” endpoint and return a 200 response?

Consul supports gRPC health checks.

The other person was attempting to configure a script check for their service, with the script residing inside of their application pod instead of in a location that was accessible to the Consul agent.

The health check can be exposed on the same port as your normal service, or a separate port. The check does need to return an 200 response to be considered healthy.