Skip to content

Commit

Permalink
fix: always sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov committed Jul 24, 2024
1 parent 142dec8 commit f22e878
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions DOCKER/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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."
Expand All @@ -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

0 comments on commit f22e878

Please sign in to comment.