forked from ignatisD/dockerstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dockerstack.sh
executable file
·264 lines (263 loc) · 7.34 KB
/
dockerstack.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
#!/usr/bin/env bash
if [[ ! -f ".env" ]]; then
cp .env.example .env
fi
export $(egrep -v '^#' .env | xargs)
STACK=${STACK:-dev}
if [[ ! -f "ssl/server.crt.pem" ]] || [[ ! -f "ssl/server.key.pem" ]]; then
cp ssl/default/server.bundle.pem ssl/server.bundle.pem
cp ssl/default/server.crt.pem ssl/server.crt.pem
cp ssl/default/server.key.pem ssl/server.key.pem
fi
function check() {
result=$(echo "$1" | grep "$2" | sed -n -r 's/dockerstack_[a-zA-Z0-9\-]*_[0-9].*(Up).*/\1/p')
if [[ "$result" != "Up" ]]; then
echo "Start"
else
echo "Stop"
fi
}
function dockerps() {
export status=$(docker-compose ps)
export LAMP=$(check "$status" apache2)
export MEAN=$(check "$status" nginx-node)
export MAIL=$(check "$status" mailhog)
export MYSQL=$(check "$status" mysql)
export PHPMY=$(check "$status" phpmyadmin)
export MONGO=$(check "$status" mongo)
export REDIS=$(check "$status" redis)
export MEMCA=$(check "$status" memcached)
export BEANSTA=$(check "$status" beanstalkd)
export ELAS=$(check "$status" elasticsearch)
}
dockerps
while true; do
clear
echo "==============================="
echo "= Lamp & Mean stack on Docker ="
echo "==============================="
echo "Press [q] to quit this menu"
echo ""
echo "1. $LAMP LAMP containers"
echo "2. Workspace root bash"
echo "3. Hot reload nginx conf"
echo "4. Php-fpm root bash"
echo "5. $MEAN MEAN containers"
echo "6. Node root user"
echo "7. Hot reload nginx-node conf"
echo "8. Npm start"
echo "9. Docker container list (ps)"
echo "10. Stop all containers"
echo "11. $MYSQL Mysql container"
echo "12. $PHPMY PhpMyAdmin container"
echo "13. $MAIL Mailhog container"
echo "14. $MONGO Mongo container"
echo "15. $REDIS Redis containers"
echo "16. $MEMCA Memcached container"
echo "17. $ELAS Elasticsearch container"
echo "18. $BEANSTA Beanstalkd and Beanstalkd console containers"
echo "19. composer install"
echo "20. composer dump-autoload"
echo "21. Build LAMP containers"
echo "22. Build MEAN containers"
echo "==============================="
echo "23. Deploy LAMP Stack"
echo "24. Remove LAMP Stack"
echo "25. Reload LAMP Stack"
echo "==============================="
echo "0. Edit .env file"
echo ""
echo -n "Select a number or type a command: "
read input
case "$input" in
1)
if [[ "$LAMP" != "Stop" ]]; then
docker-compose up -d mysql workspace php-fpm apache2 mailhog nginx
LAMP="Stop"
MAIL="Stop"
MYSQL="Stop"
else
docker-compose stop nginx apache2 workspace php-fpm mailhog mysql
docker-compose rm -f
LAMP="Start"
MAIL="Start"
MYSQL="Start"
fi
;;
2)
docker-compose exec workspace bash
;;
3)
docker-compose exec nginx bash -c "service nginx reload"
;;
4)
docker-compose exec php-fpm bash
;;
5)
if [[ "$MEAN" != "Stop" ]]; then
docker-compose up -d node mongo mailhog nginx-node
MEAN="Stop"
MAIL="Stop"
MONGO="Stop"
else
docker-compose stop nginx-node node mailhog mongo
docker-compose rm -f
MEAN="Start"
MAIL="Start"
MONGO="Start"
fi
;;
6)
docker-compose exec node bash
;;
7)
docker-compose exec nginx bash -c "service nginx reload"
;;
8)
x-terminal-emulator -e "docker-compose exec --user node node bash -c \"npm start\"" &
disown
;;
9)
dockerps
echo "$status"
;;
10)
docker stop $(docker ps -a -q)
docker-compose rm -f
dockerps
;;
11)
if [[ "$MYSQL" != "Stop" ]]; then
docker-compose up -d mysql
MYSQL="Stop"
else
docker-compose stop mysql
docker-compose rm -f
MYSQL="Start"
fi
;;
12)
if [[ "$PHPMY" != "Stop" ]]; then
docker-compose up -d phpmyadmin
PHPMY="Stop"
else
docker-compose stop phpmyadmin
docker-compose rm -f
PHPMY="Start"
fi
;;
13)
if [[ "$MAIL" != "Stop" ]]; then
docker-compose up -d mailhog
MAIL="Stop"
else
docker-compose stop mailhog
docker-compose rm -f
MAIL="Start"
fi
;;
14)
if [[ "$MONGO" != "Stop" ]]; then
docker-compose up -d mongo
MONGO="Stop"
else
docker-compose stop mongo
docker-compose rm -f
MONGO="Start"
fi
;;
15)
if [[ "$REDIS" != "Stop" ]]; then
docker-compose up -d redis
REDIS="Stop"
else
docker-compose stop redis
docker-compose rm -f
REDIS="Start"
fi
;;
16)
if [[ "$MEMCA" != "Stop" ]]; then
docker-compose up -d memcached
MEMCA="Stop"
else
docker-compose stop memcached
docker-compose rm -f
MEMCA="Start"
fi
;;
17)
if [[ "$ELAS" != "Stop" ]]; then
docker-compose up -d elasticsearch
ELAS="Stop"
else
docker-compose stop elasticsearch
docker-compose rm -f
ELAS="Start"
fi
;;
18)
if [[ "$BEANSTA" != "Stop" ]]; then
docker-compose up -d beanstalkd beanstalkd-console
BEANSTA="Stop"
else
docker-compose stop beanstalkd beanstalkd-console
docker-compose rm -f
BEANSTA="Start"
fi
;;
19)
if [[ "$LAMP" != "Start" ]]; then
docker-compose exec -u 1000 workspace bash -c 'composer install'
fi
;;
20)
if [[ "$LAMP" != "Start" ]]; then
docker-compose exec -u 1000 workspace bash -c 'composer dump-autoload'
fi
;;
21)
docker-compose stop
docker-compose rm -f
docker-compose build mysql workspace php-fpm apache2 mailhog nginx
dockerps
;;
22)
docker-compose stop
docker-compose rm -f
docker-compose build node mongo mailhog nginx-node
dockerps
;;
23)
export $(egrep -v '^#' .env | xargs)
docker stack deploy -c lamp-compose.yml ${STACK}
docker stack deploy -c lampsql-compose.yml ${STACK}
;;
24)
docker service rm ${STACK}_workspace ${STACK}_php-fpm ${STACK}_http ${STACK}_apache2 ${STACK}_mysql ${STACK}_mailhog ${STACK}_phpmyadmin
;;
25)
docker service rm ${STACK}_workspace ${STACK}_php-fpm ${STACK}_http ${STACK}_apache2
export $(egrep -v '^#' .env | xargs)
sleep 3
docker stack deploy -c lamp-compose.yml ${STACK}
;;
0)
if command -v gedit >/dev/null; then
gedit .env &
elif command -v nano >/dev/null; then
nano .env
else
start notepad++ .env
fi
;;
q)
exit
;;
*)
eval "$input"
echo ""
;;
esac
read -p "Continue to menu..."
done