godaddy / terminus

Graceful shutdown and Kubernetes readiness / liveness checks for any Node.js HTTP applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Listen for multiple signals

mkyrilov opened this issue · comments

Greetings.

I have recently started using this library and I'm liking it very much. It makes the application a whole lot cleaner.

I think that a useful enhancement would be the ability to listen for multiple signals and trigger the cleanup mechanisms on any of the signals specified.

I make this suggestion because of my recent experience, which was the following:
In a production setting, I agree that listening just for SIGTERM is probably sufficient.
However during development, I just kill my application using control + c which sends SIGINT.
Now to cater for this was simple enough. Based on an environment variable, at start up, I am able to give Terminus the appropriate signal to listen for (SIGINT or SIGTERM).
Next I added Nodemon to my application, for use during development only. For those unfamiliar with Nodemon, it simply restarts your application when it detects a file change. Nodemon achieves this by sending a SIGUSR2. (their docs on this).
With this setup, the application needs to listen for at least SIGINT and SIGUSR2 in order for Nodemon to allow the application to cleanup properly before restarting it, and for the same to happen when control + c is used to kill the application.

I think that the above scenario is a pretty common setup used during development and it would be nice to be able to cater for similar scenarios without jumping through too many hoops (Eg. based on environment variables, do something "special" to make it all work). I also can't think of any downsides for the application cleanup logic to be triggered on multiple signals.

So if this is deemed to be a good idea, I am happy to attempt an implementation of this.

Thank you.

added in #57