ruby / rake

A make-like build utility for Ruby.
https://ruby.github.io/rake
MIT License
2.32k stars 614 forks source link

Handle for SIGTERM #561

Open shayonj opened 2 months ago

shayonj commented 2 months ago

In containerized workloads, it's common to receive a SIGTERM signal when a pod or task is shutting down. Currently, when this occurs, the rake task throws a SignalException and returns a status code of 1. This behavior can be misinterpreted by container orchestration systems (like Fargate, Kubernetes, etc.) as an error, rather than a graceful exit.

This PR proposes that, when a SIGTERM signal is received by a rake task, it should return an exit code of 143. This exit code is the standard response for a SIGTERM, indicating a proper shutdown was acknowledged and handled gracefully.

I only added this for SIGTERM, but should be extensive for other handlers too if needed in future.

Related: https://github.com/ruby/rake/issues/272