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?