Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove dead services from Consul

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

like image 777
nickcodefresh Avatar asked Feb 12 '17 08:02

nickcodefresh


1 Answers

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.

like image 149
Stanislav Avatar answered Nov 18 '22 04:11

Stanislav