diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 981574591628..404a86852b50 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -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* diff --git a/libbeat/service/service.go b/libbeat/service/service.go index b90b614e5bbc..4063e5e6be79 100644 --- a/libbeat/service/service.go +++ b/libbeat/service/service.go @@ -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) }() diff --git a/libbeat/tests/system/test_base.py b/libbeat/tests/system/test_base.py index 9287b661662e..10fe859bf1e1 100644 --- a/libbeat/tests/system/test_base.py +++ b/libbeat/tests/system/test_base.py @@ -3,6 +3,7 @@ import json import os import shutil +import signal import subprocess import sys import unittest @@ -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): """