From 677b8163128c67d6ac7b47ffff7b788d6a0e9688 Mon Sep 17 00:00:00 2001 From: Gilles Filippini <pini@debian.org> Date: Sun, 19 Mar 2023 19:26:05 +0100 Subject: [PATCH] fix: gracefully exit on sigterm The purpose is to avoid duniter database corruption on `docker stop`. Before that sigterm was ignored, causing docker instance being force-killed on `docker stop` command after the related timeout expiration. Exerpt from the `docker stop` manpage: > The main process inside the container will receive SIGTERM, and after a > grace period, SIGKILL --- release/docker/duniter.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/release/docker/duniter.sh b/release/docker/duniter.sh index d224e4524..7a8aab3ea 100755 --- a/release/docker/duniter.sh +++ b/release/docker/duniter.sh @@ -1,7 +1,20 @@ #!/bin/sh + +# Terminate gracefully on SIGTERM by propagating it to the 'node' process +sigterm () { + echo "Received SIGTERM. Terminating..." >&2 + pkill node + wait %1 +} +trap 'sigterm' TERM + +# Main cd /duniter if [ "$1" != --home ]; then set -- --home /var/lib/duniter "$@" fi -exec bin/duniter "$@" +# Launch in background and wait +# This way we can catch SIGTERM +bin/duniter "$@" & +wait %1 -- GitLab