Skip to content

Commit

Permalink
Redis Persistence Storage
Browse files Browse the repository at this point in the history
  • Loading branch information
krisalay committed Aug 23, 2021
1 parent 335b846 commit 0e14b86
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Dock Utility Changelog
---
### v1.0.2
**Features**
1. Add persistence storage for Redis

**Improvements**
1. Call redis start command in redis-cli instead of duplicate run command
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ This Dock Utility provides the functionality to fork up docker services upon nee
## Prerequisites
- Docker installed in the system and accessible by non-root user

## Configurations
##### Redis
1. **Data Persistence**
If we want to persist the data in the host machine, then we can set the value of **REDIS_PERSIST_VOLUME=true** in *env* file. If its *false*, then the volume will be deleted once the container is stopped.

## Steps to use the utility
Run the following commands before using the utility
1. `make`
Expand All @@ -36,13 +41,13 @@ Stops RabbitMQ and its management plugin service.
```sh
./container redis start
```
Starts a Redis service on port 6379.
Starts a Redis service on port 6379. It creates a docker volume with the name *redis_volume* at */var/lib/docker/volumes/redis_volume/_data*. By default it will create a temporary volume, which will be removed when the redis container stops. If you want to persist data and mount that data when the redis container starts, then you can set the value **REDIS_PERSIST_VOLUME=true** in *env* file. If its *false*, then the volume will be removed once the container is stopped.

**Stop a Redis service**
```sh
./container redis stop
```
Stops Redis service.
Stops Redis service. If the value of **REDIS_PERSIST_VOLUME** is set to *true* in *env* file then the data will be stored in the host machine and can be used by any new redis container or restarting the redis container. If its *false*, then the volume will be removed once the container is stopped.

**Start a Redis CLI**
```sh
Expand Down
10 changes: 10 additions & 0 deletions common
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,14 @@ cli_log() {
script_name=${0##/*}
timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
echo "== $script_name $timestamp $1"
}

delete_volume() {
local volumeName=$1
local persistent=$2

if [ "$persistent" != true ] ; then
cli_log "Deleting volume $volumeName"
docker volume rm $volumeName
fi
}
5 changes: 3 additions & 2 deletions container
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ case "$service" in
case "$operation" in
start)
cli_log "Starting Redis Service"
docker run -d --name redis -p 6379:6379 redis:$REDIS_VERSION
docker run -d --name redis --mount source=$REDIS_VOLUME_NAME,target=/data -p 6379:6379 redis:$REDIS_VERSION --appendonly yes
;;
stop)
cli_log "Stopping Redis Service"
docker rm --force redis
delete_volume $REDIS_VOLUME_NAME $REDIS_PERSIST_VOLUME
;;
*)
cli_help "Invalid operation provided. Use either one of these: start, stop"
Expand All @@ -95,7 +96,7 @@ case "$service" in
case "$operation" in
start)
cli_log "Starting Redis CLI Service"
[ ! "$(docker ps -a | grep redis)" ] && docker run -d --name redis -p 6379:6379 redis
[ ! "$(docker ps -a | grep redis)" ] && ./container redis start
docker exec -it redis redis-cli
;;
*)
Expand Down
4 changes: 3 additions & 1 deletion env
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ ELASTICSEARCH_VERSION=7.14.0
KIBANA_VERSION=7.14.0
RABBITMQ_VERSION=3
RABBITMQ_MANAGEMENT_VERSION=3-management
REDIS_VERSION=latest
REDIS_VERSION=latest
REDIS_PERSIST_VOLUME=false
REDIS_VOLUME_NAME=redis_volume

0 comments on commit 0e14b86

Please sign in to comment.