From 1023b66e47958c2120cd0c6ba6faa6b0d3280b1c Mon Sep 17 00:00:00 2001 From: Siddharth More Date: Tue, 28 Nov 2023 14:04:06 -0800 Subject: [PATCH] update create redis-cluster shell script --- inabox/create-redis-cluster.sh | 42 +++++++++++++++------------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/inabox/create-redis-cluster.sh b/inabox/create-redis-cluster.sh index b1eac939c7..560df673f5 100755 --- a/inabox/create-redis-cluster.sh +++ b/inabox/create-redis-cluster.sh @@ -1,31 +1,25 @@ #!/bin/bash -set -e -REDIS_CLUSTER_ID="test-eigenda-redis-cluster" -REDIS_PORT="6379" -AWS_REGION="us-east-1" +# Specify the Redis Docker image version +REDIS_IMAGE="redis:latest" -# Check if the Redis cluster already exists -function redis_cluster_exists() { - aws elasticache describe-cache-clusters --region $AWS_REGION | grep -q $REDIS_CLUSTER_ID - return $? -} +# Specify the Redis container name +REDIS_CONTAINER_NAME="test-eigenda-redis-cluster" -# Start Redis service using LocalStack -function create_redis_cluster() { - aws elasticache create-cache-cluster \ - --cache-cluster-id $REDIS_CLUSTER_ID \ - --engine redis \ - --cache-node-type cache.t2.micro \ - --num-cache-nodes 1 \ - --port $REDIS_PORT \ - --region $AWS_REGION -} +# Specify the port to be used for Redis +REDIS_PORT="6379" -# Check if Redis cluster exists and create it if it does not -if redis_cluster_exists; then - echo "Redis cluster $REDIS_CLUSTER_ID already exists." +# Check if the Redis container is already running +if [ $(docker ps -q -f name="$REDIS_CONTAINER_NAME") ]; then + echo "Redis container ($REDIS_CONTAINER_NAME) is already running." else - echo "Creating Redis cluster $REDIS_CLUSTER_ID." - create_redis_cluster + # Check if the Redis container exists but is stopped + if [ $(docker ps -aq -f name="$REDIS_CONTAINER_NAME") ]; then + # Start the existing Redis container + docker start "$REDIS_CONTAINER_NAME" + else + # Run a new Redis container + docker run --name "$REDIS_CONTAINER_NAME" -p "$REDIS_PORT:$REDIS_PORT" -d "$REDIS_IMAGE" + fi + echo "Redis server started and available on port $REDIS_PORT" fi