Skip to content

Commit

Permalink
Merge pull request #38 from hummingbot/fix/multiple_gateway_containers
Browse files Browse the repository at this point in the history
(fix) create multiple containers with same image
  • Loading branch information
fengtality authored Feb 21, 2023
2 parents 1c32ca8 + 67df35b commit ee64503
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions docker/gateway-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ then
GATEWAY_TAG="latest"
fi

# Check if container with same version already exists
if docker ps -a | grep "hummingbot/gateway:$GATEWAY_TAG"; then
echo
echo "A Gateway container with the same version '$GATEWAY_TAG' already exists on this machine."
echo "Remove the existing version by running 'docker rm <container-name>' before creating a new one."
echo "Aborting..."
exit
fi

# Ask the user for the name of the new Gateway instance
read -p "Enter a name for your new Gateway instance (default = \"gateway\") >>> " INSTANCE_NAME
Expand Down Expand Up @@ -66,13 +58,26 @@ prompt_passphrase
GMT_OFFSET=$(date +%z)

# Check available open port for Gateway
PORT=15888
LIMIT=$((PORT+1000))
while [[ $PORT -le LIMIT ]]
GATEWAY_PORT=15888
LIMIT=$((GATEWAY_PORT+1000))
while [[ $GATEWAY_PORT -le LIMIT ]]
do
if [[ $(netstat -nat | grep "$GATEWAY_PORT") ]]; then
# check another port
((GATEWAY_PORT = GATEWAY_PORT + 1))
else
break
fi
done

# Check available open port for Gateway docs
DOCS_PORT=8080
LIMIT=$((DOCS_PORT+1000))
while [[ $DOCS_PORT -le LIMIT ]]
do
if [[ $(netstat -nat | grep "$PORT") ]]; then
if [[ $(netstat -nat | grep "$DOCS_PORT") ]]; then
# check another port
((PORT = PORT + 1))
((DOCS_PORT = DOCS_PORT + 1))
else
break
fi
Expand All @@ -89,7 +94,8 @@ printf "%30s %5s\n" "Hummingbot instance ID:" "$HUMMINGBOT_INSTANCE_ID"
printf "%30s %5s\n" "Gateway conf path:" "$CONF_FOLDER"
printf "%30s %5s\n" "Gateway log path:" "$LOGS_FOLDER"
printf "%30s %5s\n" "Gateway certs path:" "$CERTS_FOLDER"
printf "%30s %5s\n" "Gateway port:" "$PORT"
printf "%30s %5s\n" "Gateway port:" "$GATEWAY_PORT"
printf "%30s %5s\n" "Gateway docs port:" "$DOCS_PORT"
echo

prompt_existing_certs_path () {
Expand Down Expand Up @@ -149,8 +155,8 @@ create_instance () {
# Launch a new instance of gateway
docker run \
--name $INSTANCE_NAME \
-p $PORT:$PORT \
-p 8080:8080 \
-p $GATEWAY_PORT:15888 \
-p $DOCS_PORT:8080 \
-v $CONF_FOLDER:/usr/src/app/conf \
-v $LOGS_FOLDER:/usr/src/app/logs \
-v $CERTS_FOLDER:/usr/src/app/certs \
Expand Down

0 comments on commit ee64503

Please sign in to comment.