-
Notifications
You must be signed in to change notification settings - Fork 4
/
commands
executable file
·105 lines (84 loc) · 2.95 KB
/
commands
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/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
# Check if name is specified
if [[ $1 == redis:* ]]; then
if [[ -z $2 ]]; then
dokku_log_fail "You must specify an app name"
else
APP="$2"
fi
fi
REDIS_CONTAINER_NAME="redis-$APP"
REDIS_FLAG_PERSISTENCE_FILE="$DOKKU_ROOT/$APP/REDIS"
REDIS_FLAG_LINK_FILE="$DOKKU_ROOT/$APP/LINK"
REDIS_VOLUME_DIR="$DOKKU_ROOT/.redis/volume-$APP"
REDIS_CONTAINER_ID=$(docker ps | grep "$REDIS_CONTAINER_NAME" | awk '{print $1}')
case "$1" in
redis:enable)
verify_app_name $APP
dokku_log_info1 "Enabling Redis for $APP..."
touch $REDIS_FLAG_PERSISTENCE_FILE
dokku_log_info2 "Redis enabled for $APP"
dokku_log_verbose "Redis will be started on next build / deploy"
;;
redis:destroy)
if [[ ! -f $REDIS_FLAG_PERSISTENCE_FILE ]] && [[ ! -f $REDIS_FLAG_LINK_FILE ]] && [[ ! -d $REDIS_VOLUME_DIR ]] && [[ -z $REDIS_CONTAINER_ID ]] && [[ -z $(dokku config:get $APP REDIS_URL) ]]; then
dokku_log_info2 "No Redis instance / leftovers found for $APP"
exit 0
fi
if [[ -z "$2" ]]; then # <-- If not called from event
confirmed=0 # If this is called from event, cannot get input
while [[ $confirmed -eq 0 ]]
do
dokku_log_warn "WARNING: Potentially Destructive Action"
dokku_log_warn "This command will destroy the Redis instance for"
dokku_log_warn "$APP (including all volumes and data)."
dokku_log_warn "To proceed, type \"$APP\""
echo
read -p "> " app_name_verification
if [[ "$app_name_verification" != "$APP" ]]; then
dokku_log_warn "Confirmation did not match."
echo
else
confirmed=1
fi
done
fi
dokku_log_info1 "Destroying Redis for $APP..."
# Disable Redis autostart
[[ -f "$REDIS_FLAG_PERSISTENCE_FILE" ]] && rm "$REDIS_FLAG_PERSISTENCE_FILE"
# Stop the container
if [[ ! -z $REDIS_CONTAINER_ID ]]; then
docker stop $REDIS_CONTAINER_ID > /dev/null
fi
# Remove docker link
if [[ -f $REDIS_FLAG_LINK_FILE ]]; then
dokku link:delete $APP $REDIS_CONTAINER_NAME redis
fi
# Remove the container
if [[ ! -z $REDIS_CONTAINER_ID ]]; then
docker rm $REDIS_CONTAINER_ID > /dev/null
fi
# Remove persistent volume
if [[ -d $REDIS_VOLUME_DIR ]]; then
rm -rf $REDIS_VOLUME_DIR
fi
# Remove Redis autoconfiguration variable
dokku config:unset-norestart "$APP" "REDIS_URL"
dokku_log_info2 "Redis instance / volume destroyed:"
dokku_log_verbose "Application: $APP"
;;
help)
cat && cat<<EOF
redis:enable <app>, Enable Redis for an app for next build
redis:destroy <app>, Destroy Redis container and volume of an app
EOF
;;
*)
exit $DOKKU_NOT_IMPLEMENTED_EXIT
;;
esac