From 9652a2053b7169be5e98cc31042a4f10fa20b665 Mon Sep 17 00:00:00 2001 From: Josh Patterson Date: Thu, 10 Sep 2026 11:38:05 -0400 Subject: [PATCH] Stop the Zeek container gracefully zeekctl's post-terminate archives the final logs in the background and returns immediately unless StopWait is set, so the container exits and takes the archiving with it, stranding unarchived logs in /nsm/zeek/spool/tmp on every restart. Docker's default 10s grace is also too tight for the entrypoint's SIGTERM trap; overrunning it means SIGKILL and crash directories on the next start. Both are needed. StopWait alone gives the stop more work to do inside the same 10s window, which was measured ending in SIGKILL with logs stranded in the spool. disabled.sls used docker rm -f, which never delivers SIGTERM, so stop the container before removing it. Reported in discussion #16174. --- salt/zeek/defaults.yaml | 1 + salt/zeek/disabled.sls | 10 ++++++++++ salt/zeek/enabled.sls | 4 ++++ salt/zeek/soc_zeek.yaml | 12 ++++++++++++ 4 files changed, 27 insertions(+) diff --git a/salt/zeek/defaults.yaml b/salt/zeek/defaults.yaml index c68339584..24e1d8ca0 100644 --- a/salt/zeek/defaults.yaml +++ b/salt/zeek/defaults.yaml @@ -18,6 +18,7 @@ zeek: StatsLogEnable: 0 StatsLogExpireInterval: 0 StatusCmdShowAll: 0 + StopWait: 1 CrashExpireInterval: 0 SitePolicyScripts: local.zeek LogDir: /nsm/zeek/logs diff --git a/salt/zeek/disabled.sls b/salt/zeek/disabled.sls index c75cdd7b1..2025327fd 100644 --- a/salt/zeek/disabled.sls +++ b/salt/zeek/disabled.sls @@ -9,9 +9,19 @@ include: - zeek.sostatus +# Stop first so the entrypoint's SIGTERM trap can archive the final logs; docker_container.absent +# with force is a 'docker rm -f', which never delivers SIGTERM. force stays so the state still +# converges if the stop overruns. +so-zeek_stopped: + docker_container.stopped: + - name: so-zeek + - error_on_absent: False + so-zeek: docker_container.absent: - force: True + - require: + - docker_container: so-zeek_stopped so-zeek_so-status.disabled: file.comment: diff --git a/salt/zeek/enabled.sls b/salt/zeek/enabled.sls index 453990acb..ec8148e90 100644 --- a/salt/zeek/enabled.sls +++ b/salt/zeek/enabled.sls @@ -19,6 +19,10 @@ so-zeek: - restart_policy: unless-stopped - start: True - privileged: True + # Docker's default 10s grace is not enough for the entrypoint's SIGTERM trap to run + # 'zeekctl stop' and let StopWait archive the final logs. Overrunning it means SIGKILL, + # which strands those logs in spool/tmp and marks every node crashed on the next start. + - stop_timeout: 180 {% if DOCKERMERGED.containers['so-zeek'].ulimits %} - ulimits: {% for ULIMIT in DOCKERMERGED.containers['so-zeek'].ulimits %} diff --git a/salt/zeek/soc_zeek.yaml b/salt/zeek/soc_zeek.yaml index 1a12f7f5f..f1cc9e14d 100644 --- a/salt/zeek/soc_zeek.yaml +++ b/salt/zeek/soc_zeek.yaml @@ -99,6 +99,18 @@ zeek: regexFailureMessage: You must enter a whole number of days, or 0 to keep crash directories forever. helpLink: zeek advanced: True + StopWait: + description: >- + Set to 1 to make "zeekctl stop" wait for the final logs to be archived instead of + letting that finish in the background. Security Onion stops Zeek by stopping its + container, so anything still running in the background is killed when the container + exits - without this, the last logs of each run are stranded unarchived in + /nsm/zeek/spool/tmp and never reach Elasticsearch. It is read only for that reason. + regex: ^[01]$ + regexFailureMessage: You must enter 0 or 1. + helpLink: zeek + advanced: True + readonly: True MinDiskSpace: description: >- Percentage of free disk space below which ZeekControl reports a warning, or 0 to disable the check