Gracefully shutdown the agent on SIGTERM. Fixes #1675

Fixes #1676
This commit is contained in:
Brian Low 2014-08-29 15:11:33 -06:00 committed by Jordan Sissel
parent 2331739bb5
commit 2e800945c8
2 changed files with 14 additions and 5 deletions

View file

@ -117,8 +117,14 @@ class LogStash::Agent < Clamp::Command
end end
# Make SIGINT shutdown the pipeline. # Make SIGINT shutdown the pipeline.
trap_id = Stud::trap("INT") do sigint_id = Stud::trap("INT") do
@logger.warn(I18n.t("logstash.agent.interrupted")) @logger.warn(I18n.t("logstash.agent.sigint"))
pipeline.shutdown
end
# Make SIGTERM shutdown the pipeline.
sigterm_id = Stud::trap("TERM") do
@logger.warn(I18n.t("logstash.agent.sigterm"))
pipeline.shutdown pipeline.shutdown
end end
@ -154,7 +160,8 @@ class LogStash::Agent < Clamp::Command
return 1 return 1
ensure ensure
@log_fd.close if @log_fd @log_fd.close if @log_fd
Stud::untrap("INT", trap_id) unless trap_id.nil? Stud::untrap("INT", sigint_id) unless sigint_id.nil?
Stud::untrap("TERM", sigterm_id) unless sigterm_id.nil?
end # def execute end # def execute
def show_version def show_version

View file

@ -57,8 +57,10 @@ en:
the '-f yourlogstash.conf' flag? the '-f yourlogstash.conf' flag?
error: >- error: >-
Error: %{error} Error: %{error}
interrupted: >- sigint: >-
Interrupt received. Shutting down the pipeline. SIGINT received. Shutting down the pipeline.
sigterm: >-
SIGTERM received. Shutting down the pipeline.
configtest-flag-information: |- configtest-flag-information: |-
You may be interested in the '--configtest' flag which you can You may be interested in the '--configtest' flag which you can
use to validate logstash's configuration before you choose use to validate logstash's configuration before you choose