Remove dead services from Consul

nickcodefresh picture nickcodefresh · Feb 12, 2017 · Viewed 7.1k times · Source

We have a number of Spring Boot applications that register themselves with Consul (via Spring Cloud Consul). If I stop those applications via docker-compose stop myservice then they de-register themselves correctly and disappear from Consul.

If I use docker-compose kill myservice then the deregistration doesn't happen. I understand that on a UNIX system it's impossible to catch the SIGKILL event, so there's no way to force the de-registration.

What we're therefore seeing is services in Consul that never removed (marked as critical but still visible in the UI). Is there a way to force Consul to refresh what's registered, so that the dead services are removed?

Thanks

Nick

Answer

Stanislav picture Stanislav · Feb 13, 2017

It seems, that you have to use Consul HTTP API and manually deregister unavailable services. API gives you 2 different ways to deregister some service, the first one via agent endpoint like so

curl -v -X PUT http://%CONSUL_IP%:8500/v1/agent/service/deregister/<ServiceID>

and the second via catalog. Unfortunately in both cases you have to make http-request manually.