habitat icon indicating copy to clipboard operation
habitat copied to clipboard

Request: lifecycle hooks for before kill signal

Open gfodor opened this issue 6 years ago • 5 comments

We would like to be able to de-register our service from a load balancer when it is about to be restarted by Habitat, by running a hook before the termination signal is sent. The feature proposed in https://github.com/habitat-sh/habitat/issues/2447 is somewhat overlapping since it could be used to solve the same problem, but that solution requires the application handle it, and often it's not possible to change the application or it is the wrong separation of concerns.

Specifically, some lifecycle events which would be useful are:

  • pre-config-restart - Run before the service is sent the kill signal when it is being restarted due to a config change or file upload (ie there is no reload hook)

  • pre-upgrade-restart - Run before the service is sent the kill signal when it is being restarted due to a package upgrade

  • pre-stop - Run before the service is sent the kill signal, when it is being shut down.

  • pre-kill - Run before the service is sent the kill signal, regardless of the reason.

gfodor avatar Apr 13 '18 22:04 gfodor

Valid as of v0.57

baumanj avatar Jul 02 '18 20:07 baumanj

@gfodor Could you provide some concrete usecase examples of your proposed hooks, along the lines of "Application W could use hook X because that would allow it to do Y, which is impossible/impractical/etc. currently because Z"? Just wanting to make sure that whatever we end up implementing serves the intended purpose.

Thanks!

christophermaier avatar Jul 03 '18 23:07 christophermaier

Sure.

pre-upgrade-restart - For applications (like Erlang/Elixir applications) this is useful for preparing/performing hot code reloading, since it allows capturing a package upgrade event

pre-config-restart - Hard to think of a concrete example here, but this generally just makes sense because it's the inverse set of scenarios of the above one

pre-kill - The use case mentioned in the main ticket, this would allow the removal of the node from the load balancer and connection draining to happen before the service is killed.

pre-stop - Hard to think of a good example here, but you could imagine similar AWS-resource oriented changes that are only relevant when the service is being shut down for longer-term maintenance. For example, you could update AWS tags, drop a file for nginx to read to put up a maintenence page, etc.

gfodor avatar Jul 04 '18 00:07 gfodor

I think core/iptables would benefit from a pre-stop hook as it would allow iptables to save rules before shutting down.

qubitrenegade avatar Aug 14 '18 15:08 qubitrenegade

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We value your input and contribution. Please leave a comment if this issue still affects you.

stale[bot] avatar Aug 12 '22 00:08 stale[bot]