Skip to content
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

Merged
merged 7 commits into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Add `community_id` processor for computing network flow hashes. {pull}10745[10745]
- Add output test to kafka output {pull}10834[10834]
- Add ip fields to default_field in Elasticsearch template. {pull}11035[11035]

- Gracefully shut down on SIGHUP {pull}10704[10704]

*Auditbeat*

Expand Down
15 changes: 11 additions & 4 deletions libbeat/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,19 @@ import (
func HandleSignals(stopFunction func(), cancel context.CancelFunc) {
var callback sync.Once

// On ^C or SIGTERM, gracefully stop the sniffer
// On termination signals, gracefully stop the Beat
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM)
signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
go func() {
<-sigc
logp.Debug("service", "Received sigterm/sigint, stopping")
sig := <-sigc

switch sig {
case syscall.SIGINT, syscall.SIGTERM:
logp.Debug("service", "Received sigterm/sigint, stopping")
case syscall.SIGHUP:
logp.Debug("service", "Received sighup, stopping")
}

cancel()
callback.Do(stopFunction)
}()
Expand Down
16 changes: 16 additions & 0 deletions libbeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import os
import shutil
import signal
import subprocess
import sys
import unittest
Expand All @@ -20,6 +21,21 @@ def test_base(self):
proc = self.start_beat()
self.wait_until(lambda: self.log_contains("mockbeat start running."))
proc.check_kill_and_wait()
assert self.log_contains("mockbeat stopped.")

@unittest.skipIf(sys.platform.startswith("win"), "SIGHUP is not available on Windows")
def test_sighup(self):
"""
Basic test with exiting Mockbeat because of SIGHUP
"""
self.render_config_template(
)

proc = self.start_beat()
self.wait_until(lambda: self.log_contains("mockbeat start running."))
proc.proc.send_signal(signal.SIGHUP)
proc.check_wait()
assert self.log_contains("mockbeat stopped.")

def test_no_config(self):
"""
Expand Down