-
Notifications
You must be signed in to change notification settings - Fork 914
Add '-deregister-on-stop' option #431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Currently registrator deregisters the service once the container dies, but in some cases that might be too late. The -deregister-on-stop option tells registrator to deregister the service once docker receives either the stop or kill commands, but before the container actually dies. This gives the service in the container a chance to clean up after itself after receiving a SIGTERM, without the chance that it will receive any new requests before it actually dies.
Sorry for raising this PR without any prior development/design discussion. I'll be happy to work with the maintainers to get this PR in good shape to merge if there are any code review comments. |
Thanks for implementing this @mcclurmc. We're facing the same problem at the moment and would love to have this feature. Our applications are deployed using Amazon EC2 Container Service (ECS). On updates, ECS will shutdown the docker container (using |
Thanks for the thumbsup, @JanAhrens. We're going to be carrying this fork until we can merge this change upstream. We've also updated |
case "kill": | ||
if *deregisterOnStop { | ||
go b.RemoveOnExit(msg.ID) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code will cause unexpected results with a command like docker kill -s=SIGHUP some-container
. docker kill
will emit a kill event regardless of the signal sent.
Here is an issue regarding the events documentation moby/moby#21331.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, @MattAitchison. So it sounds like this could still be a good addition as an option, but it shouldn't be made the default behavior. Running docker kill -s=SIGHUP
is a bit of a corner case, and I would imagine that the way many people run containers with registrator (especially inside orchestration frameworks), that this isn't something we'd need to worry about 90% of the time.
@MattAitchison, given that this option could be very useful to people who aren't sending arbitrary signals to their containers via docker kill
, which is likely the majority case, do you think this is still a valid feature request?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, we could further restrict deregistration in this case by checking whether the signal was 15, and only deregistering then. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the above suggestion, note that we can only determine the signal in Docker API version 1.22, which corresponds to Docker version 1.10, so this might not be a viable solution if we need to support previous Docker versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @MattAitchison. Do you have any additional feedback for this PR, or any replies to my comments above?
@josegonzalez: I saw that you added some labels to this PR and believe that's a good sign 😃 |
Right now im just categorizing things so that this weekend I can go through and figure out whats can be merged, is duplicate, etc. @MattAitchison I'm 👍 on requiring a new docker version as well as making this default, thoughts? |
Hi. We are trying to use consul and registrator to rewrite nginx configs using consul template. I do not think that registrator is doing what it advertises, as it is actually waiting till the container exits to deregister. This pull request would solve our issue, and make registrator work as expected for us. |
I do think that this should be the default, and not behind a flag. I can understand using a flag if people are relying on the old behavior though. |
@josegonzalez Are there any plans for a merge of this important PR? |
Would it be possible to add an option to the existing |
This change also break compatibility ?
|
Hello, any plan on this issue? We really need this feature in our project. |
Currently registrator deregisters the service once the container dies, but in some cases that might be too late. The -deregister-on-stop option tells registrator to deregister the service once docker receives either the stop or kill commands, but before the container actually dies.
This gives the service in the container a chance to clean up after itself after receiving a SIGTERM, without the chance that it will receive any new requests before it actually dies.
Note that I think this is probably a bug in the Docker events documentation, and that the intended behavior of registrator is to deregister the service as soon as Docker receives the instruction to stop the container. This would be the "kill" event, not the "die" event, which is the opposite of what the documentation says.
If my change does bring registrator inline with the intended behavior, then it might be better to make it the default behavior, and not guard it behind a flag. I only added the flag to keep this change backwards compatible.