From 142dec82cae2ca20498f3eba9af323aca666d7c8 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 24 Jul 2024 16:28:47 +0700 Subject: [PATCH 1/2] fix: address already in use --- DOCKER/docker-entrypoint.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/DOCKER/docker-entrypoint.sh b/DOCKER/docker-entrypoint.sh index ba612ff8f..4c09fcc13 100755 --- a/DOCKER/docker-entrypoint.sh +++ b/DOCKER/docker-entrypoint.sh @@ -27,3 +27,14 @@ if [ ! -d "$TMHOME/config" ]; then fi exec tenderdash "$@" +local exit_code=$? + +# 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. Must be fix with graceful shutdown of tenderdash process. +if [ $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 $error_code From f22e878ff7960d12aef7737d458056119b12a27d Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 24 Jul 2024 17:53:54 +0700 Subject: [PATCH 2/2] fix: always sleep --- DOCKER/docker-entrypoint.sh | 41 +++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/DOCKER/docker-entrypoint.sh b/DOCKER/docker-entrypoint.sh index 4c09fcc13..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,15 +51,15 @@ if [ ! -d "$TMHOME/config" ]; then mv "$TMHOME/config/genesis.json.new" "$TMHOME/config/genesis.json" fi -exec tenderdash "$@" -local exit_code=$? +# Start tenderdash in the background +tenderdash "$@" & +child=$! +wait "$child" +exit_code=$? -# 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. Must be fix with graceful shutdown of tenderdash process. -if [ $exit_code -ne 0 ] && [ "$1" == "start" ]; then +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 $error_code +exit $exit_code