From a57e945db1a41945b5ee778ee5c9b8f7de6d2016 Mon Sep 17 00:00:00 2001 From: Christoph Wurm Date: Tue, 12 Feb 2019 19:12:24 +0000 Subject: [PATCH 1/7] Gracefully shut down on SIGHUP. --- libbeat/service/service.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/libbeat/service/service.go b/libbeat/service/service.go index b90b614e5bbc..0e6c8c48f46a 100644 --- a/libbeat/service/service.go +++ b/libbeat/service/service.go @@ -44,10 +44,17 @@ func HandleSignals(stopFunction func(), cancel context.CancelFunc) { // On ^C or SIGTERM, gracefully stop the sniffer 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) }() From a07cec9c964e7dc6a6d343af69fad4abae99ef54 Mon Sep 17 00:00:00 2001 From: Christoph Wurm Date: Fri, 1 Mar 2019 17:27:49 +0000 Subject: [PATCH 2/7] Add test. --- libbeat/tests/system/test_base.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libbeat/tests/system/test_base.py b/libbeat/tests/system/test_base.py index 9287b661662e..0eb6c977b4d4 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): """ From 51e1d4344465a080c635544829183e27c6a3f960 Mon Sep 17 00:00:00 2001 From: Christoph Wurm Date: Fri, 1 Mar 2019 17:29:04 +0000 Subject: [PATCH 3/7] Comment. --- libbeat/service/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libbeat/service/service.go b/libbeat/service/service.go index 0e6c8c48f46a..4063e5e6be79 100644 --- a/libbeat/service/service.go +++ b/libbeat/service/service.go @@ -42,7 +42,7 @@ 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, syscall.SIGHUP) go func() { From 1ce0c34ea7a21e359ab88bfd8aa5e25d540c1445 Mon Sep 17 00:00:00 2001 From: Christoph Wurm Date: Fri, 1 Mar 2019 17:30:34 +0000 Subject: [PATCH 4/7] Changelog --- CHANGELOG.next.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 981574591628..a090adc264c0 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -240,6 +240,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - 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* From e6aaede8296949ede8c80a785cedf950e9950e34 Mon Sep 17 00:00:00 2001 From: Christoph Wurm Date: Tue, 5 Mar 2019 15:58:18 +0000 Subject: [PATCH 5/7] Add missing parenthesis. --- libbeat/tests/system/test_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libbeat/tests/system/test_base.py b/libbeat/tests/system/test_base.py index 0eb6c977b4d4..b90440f7aa4b 100644 --- a/libbeat/tests/system/test_base.py +++ b/libbeat/tests/system/test_base.py @@ -23,7 +23,7 @@ def test_base(self): proc.check_kill_and_wait() assert self.log_contains("mockbeat stopped.") - @unittest.skipIf(sys.platform.startswith("win"), "SIGHUP is not available on Windows"' + @unittest.skipIf(sys.platform.startswith("win"), "SIGHUP is not available on Windows"') def test_sighup(self): """ Basic test with exiting Mockbeat because of SIGHUP From 0dc34ff9cfb7fcd94485f52aa9eb1f196758f159 Mon Sep 17 00:00:00 2001 From: Christoph Wurm Date: Wed, 6 Mar 2019 14:22:33 +0000 Subject: [PATCH 6/7] Fix quote. --- libbeat/tests/system/test_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libbeat/tests/system/test_base.py b/libbeat/tests/system/test_base.py index b90440f7aa4b..10fe859bf1e1 100644 --- a/libbeat/tests/system/test_base.py +++ b/libbeat/tests/system/test_base.py @@ -23,7 +23,7 @@ def test_base(self): proc.check_kill_and_wait() assert self.log_contains("mockbeat stopped.") - @unittest.skipIf(sys.platform.startswith("win"), "SIGHUP is not available on Windows"') + @unittest.skipIf(sys.platform.startswith("win"), "SIGHUP is not available on Windows") def test_sighup(self): """ Basic test with exiting Mockbeat because of SIGHUP From 463369c16e0e38826bcdb8d8c6c07128b5919d32 Mon Sep 17 00:00:00 2001 From: Christoph Wurm Date: Wed, 13 Mar 2019 14:51:18 +0000 Subject: [PATCH 7/7] Changelog --- CHANGELOG.next.asciidoc | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index a090adc264c0..404a86852b50 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -239,7 +239,6 @@ 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*