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 15
/
commands
executable file
·142 lines (126 loc) · 4.49 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
137
138
139
140
141
142
#!/bin/bash
set -e;
# Check if name is specified
if [[ $1 == elasticsearch:* ]]; 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
if [[ -d "$PLUGIN_PATH/dokku-link" ]]; then
echo "Found 'dokku-link/' directory but not a 'link/' directory. Did you install/clone dokku-link into the link/ directory instead? If so, please run"
echo ""
echo " mv dokku-link link"
echo ""
echo "to fix it."
else
echo "Link plugin not found..."
echo ""
echo "Did you install it from https://github.com/rlaneve/dokku-link?"
echo ""
echo "Run these commands to install it:"
echo ""
echo " cd /${PLUGIN_PATH}"
echo " sudo git clone https://github.com/rlaneve/dokku-link link"
echo " sudo dokku plugins-install"
fi
exit 1
fi
PLUGIN_NAME="elasticsearch"
CONTAINER_NAME="${PLUGIN_NAME}_${APP}"
HOST_DIR="$DOKKU_ROOT/$APP/$PLUGIN_NAME"
ENVVAR_NAME="ELASTICSEARCH_URL"
fi
case "$1" in
elasticsearch:create)
# Check if Elasticsearch container is installed
IMAGE=$(docker images | grep "jezdez/elasticsearch" | awk '{print $3}')
if [[ -z $IMAGE ]]; then
echo "Elasticsearch image not found... Did you run 'dokku plugins-install' ?"
exit 1
fi
# Stop existing container with the same persistent Elasticsearch
ID=$(docker ps | grep "$CONTAINER_NAME" | awk '{print $1}')
if [[ ! -z "$ID" ]]; then
docker stop $ID > /dev/null
fi
# Check if an existing DB volume exists
if [[ -d $HOST_DIR ]]; then
echo "-----> Reusing $CONTAINER_NAME data"
else
mkdir -p $HOST_DIR
chown -R dokku:dokku $HOST_DIR
fi
VOLUME="$HOST_DIR:/var/lib/elasticsearch"
# Launch container
docker run -v $VOLUME -name=$CONTAINER_NAME -d jezdez/elasticsearch \
/usr/local/bin/run
# Link to a potential existing app
dokku elasticsearch:link $APP $APP
echo "-----> Elasticsearch container created: $CONTAINER_NAME"
sleep 1
dokku elasticsearch:info $APP
;;
elasticsearch: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
# Remove persistent volume
if [[ -d $HOST_DIR ]]; then
rm -rf $HOST_DIR
fi
# unlink this container as "elasticsearch"
dokku link:delete "$APP" "$CONTAINER_NAME" "$PLUGIN_NAME"
dokku config:unset "$APP" $ENVVAR_NAME
echo "-----> Elasticsearch container deleted: $CONTAINER_NAME"
;;
elasticsearch:info)
ID=$(docker ps -a | grep "$CONTAINER_NAME" | awk '{print $1}')
IP=$(docker inspect $ID | grep IPAddress | cut -d '"' -f 4)
echo
echo " Host: ${IP}"
echo " Private ports: 9200, 9300"
echo
;;
elasticsearch: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}"
# link this container as "elasticsearch"
dokku link:create "$APP" "$CONTAINER_NAME" "$PLUGIN_NAME"
# 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 config:set "$APP" $ENVVAR_NAME="http://${IP}:9200"
echo "-----> $APP linked to $CONTAINER_NAME container"
fi
;;
elasticsearch:logs)
ID=$(docker ps -a | grep "$CONTAINER_NAME" | awk '{print $1}')
docker logs $ID | tail -n 100
;;
help)
cat && cat<<EOF
elasticsearch:create <app> Create a Elasticsearch container
elasticsearch:delete <app> Delete specified Elasticsearch container
elasticsearch:info <app> Display container informations
elasticsearch:link <app> <container> Link an app to a Elasticsearch container
elasticsearch:logs <app> Display last logs from Elasticsearch container
EOF
;;
esac