-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.sh
executable file
·106 lines (88 loc) · 2.47 KB
/
manage.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
#!/bin/bash
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" || exit
# Check env file
if [[ ! -f ./.env ]]
then
printf "\e[31mEnv file not found\e[0m\n"
exit 1;
fi
# Load and check config
source ./.env
source ./util.sh
ClearLogs
if [[ $(uname -s) = MINGW* ]]; then export MSYS_NO_PATHCONV=1; fi
# ----------------------------- INTERNAL -----------------------------
DoCreateNetworkAndVolumes() {
NetworkCreate "${NETWORK_NAME}"
VolumeCreate "${COMPOSE_PROJECT_NAME}-mysql"
VolumeCreate "${COMPOSE_PROJECT_NAME}-elasticsearch"
VolumeCreate "${COMPOSE_PROJECT_NAME}-redis"
}
DoRemoveNetworkAndVolumes() {
#NetworkRemove "${NETWORK_NAME}-network"
VolumeRemove "${COMPOSE_PROJECT_NAME}-mysql"
VolumeRemove "${COMPOSE_PROJECT_NAME}-elasticsearch"
VolumeRemove "${COMPOSE_PROJECT_NAME}-redis"
}
# ----------------------------- EXEC -----------------------------
case $1 in
# -------------- UP --------------
up)
Title "Starting stack"
Confirm
DoCreateNetworkAndVolumes
ComposeUp
;;
# ------------- DOWN -------------
down)
Title "Stopping stack"
Confirm
ComposeDown
;;
# ------------- RESET ------------
reset)
Title "Resetting stack"
Warning "All data will be lost !"
Confirm
Warning "Are you really sure ?"
Confirm
ComposeDown
DoRemoveNetworkAndVolumes
sleep 5
DoCreateNetworkAndVolumes
ComposeUp
;;
# ------------- CLEAR ------------
clear)
Title "Clearing stack"
Warning "All data will be lost !"
Confirm
Warning "Are you really sure ?"
Confirm
ComposeDown
DoRemoveNetworkAndVolumes
;;
# -------------- TOOLS --------------
tools)
if [[ ! $2 =~ ^up|down$ ]]
then
printf "\e[31mExpected 'up' or 'down'\e[0m\n"
exit 1
fi
if [[ $2 == 'up' ]]
then
ToolsUp
else
ToolsDown
fi
;;
# ------------- HELP -------------
*)
Help "Usage: ./manage.sh [action] [options]
\e[0mup\e[2m Create network and volumes and start containers.
\e[0mdown\e[2m Stop containers.
\e[0mreset\e[2m Recreate volumes and restart containers.
\e[0mclear\e[2m Stop containers and destroy the network and volumes.
\e[0mtools\e[2m up|down Start or stop tools containers."
;;
esac