-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathquickstart
More file actions
executable file
·197 lines (163 loc) · 5.27 KB
/
Copy pathquickstart
File metadata and controls
executable file
·197 lines (163 loc) · 5.27 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/usr/bin/env bash
export PROJECT=${PROJECT:-"demo-162"}
export NODES=${NODES:-"3"}
export VOLUMES="`pwd`/projects/${PROJECT}"
export COMMIT=${COMMIT:-"868149d56f44c1397783be356d9dae92dc570445"}
tarfile="projects/${PROJECT}/builds/mongooseim-${PROJECT}-*.tar.gz"
export MEMBER_TGZ=`ls -1r $tarfile | head -1 | xargs -n1 basename`
export XMPP_USERS=${XMPP_USERS:="20"}
export HAPROXY_CONFIG="${VOLUMES}/haproxy.cfg"
set -e
step() {
local message=$1
echo -e "\033[33m${message}\033[0m"
}
success() {
echo -e "\033[32m${1}\033[0m"
}
command() {
local command=$1
set -x
eval "$command"
{ set +x; } 2>/dev/null
}
wait_for_mongoose() {
local node=$1
for i in $(seq 1 10); do
local status=`docker exec ${node} /member/mongooseim/bin/mongooseimctl status`
if [[ "${status}" =~ MongooseIM.*is\ running ]]
then
echo "Node ${node} is running"
return
else
sleep 5
fi
done
echo "Timeout while waiting for node ${node}"
exit 1
}
build() {
step "Creating spec file"
if [ ! -d "${VOLUMES}/builds" ]; then mkdir -p "${VOLUMES}/builds"; fi
command 'echo "${PROJECT} ${COMMIT} https://github.com/esl/mongooseim" > ${VOLUMES}/builds/specs'
step "Creating builder container"
command 'make builder'
step "Starting MongooseIM build"
command 'docker exec -it ${PROJECT}-builder /build.sh'
step "Building MongooseIM image"
command 'make member.build'
step "Building HAproxy container"
command 'make haproxy.build'
step "Building graphite container"
command 'make graphite.build'
step "Cleaning builder container"
command 'make builder.destroy'
}
start() {
step "Creating DNS"
command 'make dns.create'
step "Starting DNS"
command 'make dns.start'
step "Creating graphite"
command 'make graphite.create'
step "Creating grafana"
command 'make grafana.create'
step "Creating grafana datasource"
dsfile="${VOLUMES}/datasource.json"
command "sed -e s/{{project}}/${PROJECT}/ templates/datasource.json.template \
> ${dsfile}"
command "docker cp ${dsfile} ${PROJECT}-graphite:/tmp/"
command "docker exec ${PROJECT}-graphite \
curl -X\"POST\" -H\"Content-Type: application/json\" \
http://admin:admin@${PROJECT}-grafana:3000/api/datasources \
-d @/tmp/datasource.json"
step "Uploading grafana dashboard"
command "docker cp templates/dashboard.json ${PROJECT}-graphite:/tmp/"
command "docker exec ${PROJECT}-graphite \
curl -X\"POST\" -H\"Content-Type: application/json\" \
http://admin:admin@${PROJECT}-grafana:3000/api/dashboards/db \
-d @/tmp/dashboard.json"
step "Creating MongooseIM nodes"
command "rm -rf ${VOLUMES}/${PROJECT}-mongooseim-*"
for n in $(seq 1 ${NODES}); do
step "Creating MongooseIM node ${n}"
node="${PROJECT}-mongooseim-${n}"
nodedir=${VOLUMES}/${node}
command "mkdir -p ${nodedir}"
command "sed -e 's/{{host}}/${PROJECT}-graphite/; s/{{prefix}}/mongooseim-${n}/' \
templates/app.config.template > ${nodedir}/app.config"
command "make member.create MEMBER=${node}"
wait_for_mongoose ${node}
done
step "Registering XMPP users"
for n in $(seq 1 ${XMPP_USERS}); do
command "docker exec ${PROJECT}-mongooseim-1 \
/member/mongooseim/\bin/mongooseimctl \
register user_${n} localhost password_${n}"
done
step "Preparing HAProxy config file"
command "cp templates/haproxy.cfg.template ${HAPROXY_CONFIG}"
for n in $(seq 1 ${NODES}); do
line="server mim${n} ${PROJECT}-mongooseim-${n}:5222 check fall 2"
command "sed -i -e '/{{servers}}/a\\
${line}
' ${HAPROXY_CONFIG}"
done
command "sed -i -e '/{{servers}}/d' ${HAPROXY_CONFIG}"
step "Creating HAProxy"
command "make haproxy.create"
success "You should be able to connect to MongooseIM via XMPP at \$DOCKERIP:5222."
success "The XMPP domain is \"localhost\" and there are \
predefined users user_1/password_1 to user_${XMPP_USERS}/password_${XMPP_USERS}."
success "The grafana dashboard is available at \
http://\$DOCKERIP:3000/dashboard/db/mongooseim (admin/admin)"
success "The graphite dashboard is available at http://\$DOCKERIP:8080/"
success "The HAProxy dashboard is available at \
http://\$DOCKERIP:9000/stats (admin/admin)"
}
stop() {
step "Stopping HAProxy"
command "make haproxy.destroy"
step "Stopping graphite"
command "make graphite.destroy"
step "Stopping grafana"
command "make grafana.destroy"
nodes=`docker ps --filter="name=${PROJECT}-mongooseim" --format="{{.Names}}"`
for node in $nodes
do
step "Stopping ${node}"
command "make MEMBER=${node} member.destroy"
done
step "Stopping DNS"
command "make dns.destroy"
success "OK"
}
status() {
command "docker ps --filter=\"label=${PROJECT}\""
}
usage() {
script=`basename $0`
echo "Usage: ${script} [start|stop|build|status]"
exit 1
}
if [ $# -ne 1 ]; then
usage
fi
CMD=$1
case ${CMD} in
start)
start
;;
stop)
stop
;;
build)
build
;;
status)
status
;;
*)
usage
;;
esac