From 421afd5bb09d0e3645d99582cd5001bb0c742a2d Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Tue, 9 Apr 2024 21:25:32 +0200 Subject: [PATCH] properly wait for collectd exit before graphs1090 writeback on container stop --- rootfs/etc/s6-overlay/scripts/collectd | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rootfs/etc/s6-overlay/scripts/collectd b/rootfs/etc/s6-overlay/scripts/collectd index 86a2250..99d3431 100755 --- a/rootfs/etc/s6-overlay/scripts/collectd +++ b/rootfs/etc/s6-overlay/scripts/collectd @@ -35,12 +35,15 @@ done /usr/sbin/collectd -t -T -f -C /etc/collectd/collectd.conf > /dev/null 2>&1 -trap 'echo "sending SIGTERM to collectd";pkill collectd' SIGTERM SIGINT SIGHUP SIGQUIT +# pkill -P $$ will only kill children of the script, not the script itself +trap 'pkill -P $$' SIGTERM SIGINT SIGHUP SIGQUIT +# for this scheme to work, the program is started in the background -# background execution + wait is necessary for trap to work -.- #shellcheck disable=SC2016 s6wrap --quiet --prepend=collectd --timestamps --args /usr/sbin/collectd -C /etc/collectd/collectd.conf -f & -wait || true + +# the first wait exits due to the signal which is trapped, the 2nd wait actually waits for collectd to exit +wait || wait || true