-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Libbeat] Gracefully shut down on SIGHUP #10704
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend putting some tests in place from the system tests to send in a SIGHUP. This way it gets tested on multiple OSes and we can make sure nothing unusual is happening upstream the Go runtimes signal handling (it has some builtin handlers).
libbeat/service/service.go
Outdated
@@ -44,10 +44,17 @@ func HandleSignals(stopFunction func(), cancel context.CancelFunc) { | |||
|
|||
// On ^C or SIGTERM, gracefully stop the sniffer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, but this comment is now out of date (and has been for a while). Perhaps: // On termination signals, gracefully stop the Beat
Even if it was not intended for that, In any case I think it is fine to merge this by now, I agree that we should handle this signal in some way. |
Good call, I've added a system test that sends |
SIGHUP
is sent to a process if the user's terminal is disconnected. It is one of the five termination signals. Currently, Beats is going to terminate suddenly, i.e. the log will cut off, no shutdown actions are going to be run, etc.As we handle more and more state (e.g. writing state to
beat.db
files) it becomes more important to gracefully shutdown in "less than ideal" situations. Beats should probably not be run directly from a terminal or a terminal multiplexer, but it probably happens, and if so the consequences of a network disconnect or clumsy fingers (I forget the number of times I've hit the wrong key when using shortcuts in tmux/screen) should not be severe if we can help it.This change catches
SIGHUP
as it already doesSIGINT/SIGTERM
and runs the usual shutdown actions. This can include waiting for a period of time specified using theshutdown_timeout
option Filebeat and Packetbeat support.I thought we might want to exit with a non-zero exit code if we receive this unexpected signal, but I don't see a good way to specifiy the exit code in Libbeat at the moment.