From a569405ef0ec91c77f523a198b5055cf1848ec44 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 24 Jul 2024 18:13:04 +0700 Subject: [PATCH] fix: address already in use (#845) * fix: address already in use * fix: always sleep --- DOCKER/docker-entrypoint.sh | 40 +++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/DOCKER/docker-entrypoint.sh b/DOCKER/docker-entrypoint.sh index ba612ff8f..acec50388 100755 --- a/DOCKER/docker-entrypoint.sh +++ b/DOCKER/docker-entrypoint.sh @@ -1,5 +1,30 @@ #!/bin/bash -set -e + + +# TODO: Workaround for busy port problem happening with docker restart policy +# we are trying to start a new container but previous process still not release +# the port. + +# As a workaround we are sleeping for 10 seconds after the tenderdash process +# exits with non-zero exit code. +# +# Must be fix with graceful shutdown of tenderdash process. + +got_signal=false + +# Function to handle signals and forward them to the tenderdash process +# shellcheck disable=SC2317 +_forward_signal() { + echo "Caught signal! Forwarding to tenderdash process." + got_signal=true + kill -s "$1" "$child" +} + +# Trap signals and forward them to the tenderdash process +trap '_forward_signal TERM' SIGTERM +trap '_forward_signal INT' SIGINT +trap '_forward_signal HUP' SIGHUP +trap '_forward_signal QUIT' SIGQUIT if [ ! -d "$TMHOME/config" ]; then echo "Running tenderdash init to create a single node (default) configuration for docker run." @@ -26,4 +51,15 @@ if [ ! -d "$TMHOME/config" ]; then mv "$TMHOME/config/genesis.json.new" "$TMHOME/config/genesis.json" fi -exec tenderdash "$@" +# Start tenderdash in the background +tenderdash "$@" & +child=$! +wait "$child" +exit_code=$? + +if [ $got_signal == false ] && [ $exit_code -ne 0 ] && [ "$1" == "start" ]; then + echo "Sleeping for 10 seconds as workaround for the busy port problem. See entrypoint code for details." + sleep 10 +fi + +exit $exit_code