Created
December 21, 2024 17:00
Revisions
-
samarpanda revised this gist
Dec 21, 2024 . 1 changed file with 2 additions and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -2,8 +2,9 @@ # Configuration ENV=local PROJECT=demo IMAGE=redis:7.4.0 CNAME=redis-$ENV-$PROJECT PORT=6379 DATA_DIR=$PWD/data -
samarpanda created this gist
Dec 21, 2024 .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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,69 @@ #!/bin/bash # Configuration ENV=local IMAGE=redis:7.4.0 CNAME=redis-$ENV-ic PORT=6379 DATA_DIR=$PWD/data # Helper function to display usage usage() { echo "Usage: $0 {start|stop|restart}" exit 1 } # Start Redis container start_redis() { echo "Starting Redis container: $CNAME" docker pull $IMAGE docker stop --time=20 $CNAME 2>/dev/null || true docker rm -f $CNAME 2>/dev/null || true if [ ! -d "$DATA_DIR" ]; then mkdir -p $DATA_DIR echo "Created data directory: $DATA_DIR" fi docker run -d \ --name $CNAME \ -p $PORT:6379 \ -v $DATA_DIR:/data \ $IMAGE redis-server --appendonly yes echo "Redis container started on port $PORT" } # Stop Redis container stop_redis() { echo "Stopping Redis container: $CNAME" docker stop --time=20 $CNAME docker rm -f $CNAME echo "Redis container stopped and removed" } # Restart Redis container restart_redis() { echo "Restarting Redis container: $CNAME" stop_redis start_redis } # Main script logic if [ "$#" -ne 1 ]; then usage fi case "$1" in start) start_redis ;; stop) stop_redis ;; restart) restart_redis ;; *) usage ;; esac exit 0