-
Notifications
You must be signed in to change notification settings - Fork 4
/
pre-deploy
executable file
·53 lines (45 loc) · 1.69 KB
/
pre-deploy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env bash
source "$PLUGIN_PATH/common/functions"
# Reset bash mode from importing the functions
set +exo pipefail
# Fail on equation failure
set -e
APP="$1"
REDIS_FLAG_PERSISTENCE_FILE="$DOKKU_ROOT/$APP/REDIS"
REDIS_CONTAINER_NAME="redis-$APP"
# Only start Redis if it is enabled
if [[ -f $REDIS_FLAG_PERSISTENCE_FILE ]]; then
dokku_log_info1 "Starting Redis for $APP..."
# Check if Redis container is installed
IMAGE=$(docker images | grep "redis" | awk '{print $3}')
if [[ -z $IMAGE ]]; then
dokku_log_fail "Redis image not found! Did you run 'dokku plugins-install'?"
fi
# Check if Redis is already running
ID=$(docker ps | grep "$REDIS_CONTAINER_NAME" | awk '{print $1}')
if [[ ! -z $ID ]]; then
dokku_log_verbose "Redis container already running: $REDIS_CONTAINER_NAME"
exit 0
fi
# Remove old stopped container with the same name, if it exists
ID=$(docker ps -a | grep "$REDIS_CONTAINER_NAME" | awk '{print $1}')
if [[ ! -z $ID ]]; then
ID=$(docker rm $ID)
dokku_log_info1 "Removed stale Redis container $ID"
fi
# Check if an existing DB volume exists
HOST_DIR="$DOKKU_ROOT/.redis/volume-$APP"
if [[ -d $HOST_DIR ]]; then
dokku_log_info1 "Reusing volume-$APP volume"
else
dokku_log_info1 "Creating new volume"
mkdir -p $HOST_DIR
fi
VOLUME="$HOST_DIR:/data"
# Launch container
dokku_log_info1 "Starting Redis container..."
ID=$(docker run -v $VOLUME --name $REDIS_CONTAINER_NAME -d redis redis-server --appendonly yes)
dokku_log_info2 "Redis started:"
dokku_log_verbose "Application: $APP"
dokku_log_verbose "Redis: $REDIS_CONTAINER_NAME"
fi