-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update create redis-cluster shell script
- Loading branch information
Siddharth More
authored and
Siddharth More
committed
Nov 28, 2023
1 parent
ce20a53
commit 1023b66
Showing
1 changed file
with
18 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |