Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: address already in use #845

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 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,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
Loading