-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.sh
executable file
·459 lines (333 loc) · 6.47 KB
/
cli.sh
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
#!/usr/bin/env bash
HOSTS_DIR=hosts
CONTAINER_DIR=containers
CONTAINER_NAME="grundstein/legung"
NGINX_DIR=$CONTAINER_DIR/nginx
REDIS_DIR=$CONTAINER_DIR/redis
POSTGRES_DIR=$CONTAINER_DIR/postgres
GITLAB_DIR=$CONTAINER_DIR/gitlab
MONGO_DIR=$CONTAINER_DIR/mongodb
MAGIC_DIR=$CONTAINER_DIR/magic
REDMINE_DIR=$CONTAINER_DIR/redmine
BACKUP_DIR=../backups
source ./bin/tasks.sh
# general
function install() {
./bin/install.sh
}
function deploy() {
env
build
run
}
function env() {
./bin/create_env.sh
}
function build() {
redis-build
postgres-build
gitlab-build
redmine-build
# magic-build
nginx-build
}
function run() {
redis-run
postgres-run
gitlab-run
redmine-run
# magic-run
nginx-run
}
function network() {
docker network create \
--driver bridge \
--subnet 172.18.0.0/24 \
user-defined
}
function clean() {
echo-start "clean"
rm -f ./**/ENV.sh
echo-finished "clean"
}
function ps() {
docker ps
}
function stop() {
echo-start "stopping containers"
postgres-stop
redis-stop
nginx-stop
gitlab-stop
redmine-stop
echo-finished "stopping containers"
}
function backup() {
stop
echo-start "creating backup"
mkdir -p $BACKUP_DIR
echo "start copying files"
tar -cf ../backups/backup-$(date +\%Y-\%m-\%d-\%H-\%M-\%S).tar ../data/
echo-finished "backup finished"
run
# sleep 30
# nginx
}
function create-crontab() {
echo-start "create crontab"
CRONTAB_FILE=$PWD/crontab.txt
rm -f $CRONTAB_FILE
echo "23 05 * * * \"make -C ${PWD} backup\" > /dev/null" >> $CRONTAB_FILE
crontab $CRONTAB_FILE
echo-finished "create crontab"
}
function status() {
echo-start "status"
container-status
# magic-status
echo-finished "status"
}
function container-status() {
echo-start "container-status"
loop-dirs ./containers status
echo-finished "container-status"
}
function container-update() {
echo-start "container-update"
loop-dirs ./containers update
echo-finished "container-update"
}
function magic-status() {
echo-start "magic-status"
root_dir=./containers/magic
make -C $root_dir status
hosts_dir=$root_dir/hosts
loop-dirs $hosts_dir status
echo-finished "magic-status"
}
function magic-update() {
echo-start "magic-update"
root_dir=./containers/magic
make -C $root_dir update
hosts_dir=$root_dir/hosts
loop-dirs $hosts_dir update
echo-finished "magic-update"
}
function update() {
echo-start "update"
container-update
# magic-update
echo-finished "update"
}
# POSTGRES tasks
function postgres() {
postgres-build
postgres-run
postgres-logs
}
function postgres-build() {
make -C $POSTGRES_DIR build
}
function postgres-run() {
make -C $POSTGRES_DIR run
}
function postgres-logs() {
make -C $POSTGRES_DIR logs
}
function postgres-debug() {
make -C $POSTGRES_DIR debug
}
function postgres-rm() {
make -C $POSTGRES_DIR remove
}
function postgres-stop() {
make -C $POSTGRES_DIR stop
}
# REDIS tasks
function redis() {
redis-build
redis-run
redis-logs
}
function redis-build() {
make -C $REDIS_DIR build
}
function redis-run() {
make -C $REDIS_DIR run
}
function redis-logs() {
make -C $REDIS_DIR logs
}
function redis-debug() {
make -C $REDIS_DIR debug
}
function redis-rm() {
make -C $REDIS_DIR remove
}
function redis-stop() {
make -C $REDIS_DIR stop
}
# GITLAB tasks
function gitlab() {
gitlab-run
gitlab-logs
}
function gitlab-run() {
make -C $GITLAB_DIR run
}
function gitlab-build() {
make -C $GITLAB_DIR build
}
function gitlab-debug() {
make -C $GITLAB_DIR debug
}
function gitlab-logs() {
make -C $GITLAB_DIR logs
}
function gitlab-rm() {
make -C $GITLAB_DIR remove
}
function gitlab-stop() {
make -C $GITLAB_DIR stop
}
function gitlab-backup() {
make -C $GITLAB_DIR backup
}
# REDMINE tasks
function redmine() {
redmine-run
redmine-logs
}
function redmine-run() {
make -C $REDMINE_DIR run
}
function redmine-build() {
make -C $REDMINE_DIR build
}
function redmine-debug() {
make -C $REDMINE_DIR debug
}
function redmine-logs() {
make -C $REDMINE_DIR logs
}
function redmine-rm() {
make -C $REDMINE_DIR remove
}
function redmine-stop() {
make -C $REDMINE_DIR stop
}
function redmine-backup() {
make -C $REDMINE_DIR backup
}
# NGINX tasks
function nginx() {
nginx-build
nginx-run
nginx-logs
}
function nginx-build() {
make -C $NGINX_DIR build
}
function nginx-run() {
make -C $NGINX_DIR run
}
function nginx-logs() {
cd ${NGINX_DIR}; ./cli.sh logs
}
function nginx-debug() {
make -C $NGINX_DIR debug
}
function nginx-rm() {
make -C $NGINX_DIR remove
}
function nginx-clean() {
make -C $NGINX_DIR clean
}
function nginx-stop() {
make -C $NGINX_DIR stop
}
# MAGIC tasks
function magic() {
magic-build
magic-run
}
function magic-run() {
make -C $MAGIC_DIR run
}
function magic-build() {
make -C $MAGIC_DIR build
}
function magic-rm() {
make -C $MAGIC_DIR remove
}
function magic-stop() {
make -C $MAGIC_DIR stop
}
# help output
function help() {
echo "\
GrundSteinLegung V0.0.1 Help
Usage
make TASK
deploy - runs and builds all containers
build - builds all containers
run - runs all containers
ps - show all running containers
env - generates environment vars for all containers
stop - stop all containers
TASKS:
postgres redis gitlab magic nginx
Usage:
make TASK
example make nginx
SUBTASKS:
Usage:
make TASK-SUBTASK
example make nginx-build
run - run the container
build - build the container
debug - drop into a container bash
log - tail the container logs
HELP TASKS
help - this help text
some container provide additional tasks,
see the help tasks for more info:
help-postgres - postgres cli help
help-redis - redis cli help
help-gitlab - gitlab cli help
help-magic - magic cli help
help-nginx - nginx cli help \
"
}
function help-postgres() {
./postgres/cli.sh help
}
function help-redis() {
./redis/cli.sh help
}
function help-gitlab() {
./gitlab/cli.sh help
}
function help-nginx() {
./nginx/cli.sh help
}
function help-magic() {
./magic/cli.sh help
}
function remote-backup() {
ssh -p 2222 [email protected] "cd /root/grundstein.legung && make backup"
}
function remote-retrieve() {
scp -P 2222 [email protected]:`ssh -p 2222 [email protected] ls -dAprt /root/backups/* | tail -n 1` ../backups/
}
function remote-unpack() {
tar xvf `ls -dAprt ../backups/* | tail -n 1` -C ../
}
if [ $1 ]
then
function=$1
shift
$function $@
else
help $@
fi