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 6098a4f0cd
commit bb5cc0173f
2 changed files with 14 additions and 5 deletions

View file

@ -117,8 +117,14 @@ class LogStash::Agent < Clamp::Command
end
# Make SIGINT shutdown the pipeline.
trap_id = Stud::trap("INT") do
@logger.warn(I18n.t("logstash.agent.interrupted"))
sigint_id = Stud::trap("INT") do
@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
end
@ -154,7 +160,8 @@ class LogStash::Agent < Clamp::Command
return 1
ensure
@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
def show_version

View file

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