This repository has been archived by the owner on Jan 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
commands
executable file
·136 lines (119 loc) · 4.15 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env bash
set -o pipefail; [[ $DOKKU_TRACE ]] && set -x
# Check if name is specified
if [[ $1 == memcached:* ]]; then
if [[ -z $2 ]]; then
echo "You must specify an app name"
exit 1
else
APP="$2"
# Check if app exists with the same name
if [[ -d "$DOKKU_ROOT/$APP" ]]; then
APP_EXISTS=true
else
APP_EXISTS=false
fi
fi
if [[ ! -d "$PLUGIN_PATH/link" ]]; then
echo "Link plugin not found... Did you install it from https://github.com/rlaneve/dokku-link?"
exit 1
fi
PLUGIN_NAME="memcached"
PLUGIN_ALIAS="memcache"
CONTAINER_NAME="${PLUGIN_NAME}_${APP}"
HOST_DIR="$DOKKU_ROOT/.$PLUGIN_NAME/$APP"
CONTAINER_IMAGE="jezdez/memcached"
MEMCACHE_PORT=11211
fi
case "$1" in
memcached:create)
# Check if Memcached image is installed
IMAGE=$(docker images | grep "$CONTAINER_IMAGE" | awk '{print $3}')
if [[ -z $IMAGE ]]; then
echo "Memcached image not found... Did you run 'dokku plugins-install'?"
exit 1
fi
# check for existing container with the same persistent Memcached
ID=$(docker ps -a | grep "$CONTAINER_NAME" | awk '{print $1}')
if [[ ! -z "$ID" ]]; then
echo
echo "-----> Container $CONTAINER_NAME already exist. Please use rebuild or delete command"
exit 1
fi
# Launch container
ID=$(docker run --name $CONTAINER_NAME -d $CONTAINER_IMAGE \
/usr/bin/memcached -u memcache -p $MEMCACHE_PORT -m 64 -l 0.0.0.0)
# Link to a potential existing app
dokku memcached:link $APP $APP
echo
echo "-----> Memcached container $CONTAINER_NAME created (using $CONTAINER_IMAGE)"
sleep 1
dokku memcached:info $APP
;;
memcached:rebuild)
ID=$(docker ps -a | grep "$CONTAINER_NAME" | awk '{print $1}')
if [[ ! -z "$ID" ]]; then
echo
echo "-----> Stopping & removing $CONTAINER_NAME container"
docker stop $ID > /dev/null
docker rm $ID > /dev/null
fi
dokku memcached:create $APP
;;
memcached:delete)
# Stop the container
ID=$(docker ps -a | grep "$CONTAINER_NAME" | awk '{print $1}')
if [[ ! -z $ID ]]; then
docker stop $ID > /dev/null
docker rm $ID > /dev/null
fi
dokku link:delete "$APP" "$CONTAINER_NAME" "$PLUGIN_ALIAS"
dokku config:unset "$APP" MEMCACHE_SCHEME
echo
echo "-----> Deleted Memcached container $CONTAINER_NAME"
;;
memcached:info)
ID=$(docker ps -a | grep "$CONTAINER_NAME" | awk '{print $1}')
IP=$(docker inspect $ID | grep IPAddress | cut -d '"' -f 4)
DOCKER_GATEWAY=$(docker inspect $ID | grep Gateway | awk '{ print $2 }' | tr -d ',"')
echo
echo " Host: ${IP}"
echo " Gateway: ${DOCKER_GATEWAY}"
echo " Secret port: ${MEMCACHE_PORT}"
echo
;;
memcached:link)
if $APP_EXISTS; then
# Check argument
if [[ -z $3 ]]; then
echo "You must specify a container name"
exit 1
fi
CONTAINER_NAME="${PLUGIN_NAME}_$3"
# figure out IP to set env var
ID=$(docker ps -a | grep "$CONTAINER_NAME" | awk '{print $1}')
#IP=$(docker inspect $ID | grep IPAddress | cut -d '"' -f 4)
dokku link:create "$APP" "$CONTAINER_NAME" "$PLUGIN_ALIAS"
dokku config:set "$APP" MEMCACHE_SCHEME=""
echo
echo "-----> $APP linked to $CONTAINER_NAME container"
fi
;;
memcached:logs)
ID=$(docker ps -a | grep "$CONTAINER_NAME" | awk '{print $1}')
docker logs $ID | tail -n 100
;;
help)
cat && cat<<EOF
memcached:create <app> Create a Memcached container
memcached:rebuild <app> Rebuild Memcached container of <app>
memcached:delete <app> Delete specified Memcached container
memcached:info <app> Display container informations
memcached:link <app> <container> Link an app to a Memcached container
memcached:logs <app> Display last logs from Memcached container
EOF
;;
*)
exit $DOKKU_NOT_IMPLEMENTED_EXIT
;;
esac