-
Notifications
You must be signed in to change notification settings - Fork 18
/
bts.bat
250 lines (201 loc) · 6 KB
/
bts.bat
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
@Echo Off
Rem
Rem Copyright 2018 Bodastage Solutions
Rem
Rem Licensed under the Apache License, Version 2.0 (the "License");
Rem you may not use this file except in compliance with the License.
Rem You may obtain a copy of the License at
Rem
Rem http://www.apache.org/licenses/LICENSE-2.0
Rem
Rem Unless required by applicable law or agreed to in writing, software
Rem distributed under the License is distributed on an "AS IS" BASIS,
Rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Rem See the License for the specific language governing permissions and
Rem limitations under the License.
Rem
Rem
Rem Date 22/01/2018
Rem Author Emmanuel Robert Ssebaggala <[email protected]>
Rem Check if script is running in an elevated terminal
Rem net session >nul 2>&1
Rem If %errorLevel% == 0 (
Rem Echo Do not run as an Administrator
Rem Exit /b 1
Rem )
Rem Test if docker-machine is running
@For /F "tokens=* USEBACKQ" %%F In (`docker-machine status default 2^>Nul`) Do (
Set Status=%%F
If Not "%Status%" == "Running" (
docker-machine start default
)
)
Rem Set docker env variables . Add so that docker commands can be run from cmd
Rem Review this later.
@FOR /f "tokens=*" %%i In ('docker-machine env --shell=cmd 2^>Nul') Do @%%i
Rem application root directory
For /F %%i In ("%~dp0") Do Set BD_ROOT_DIR=%%~fi
cd %BD_ROOT_DIR%
Rem Status
Rem -------------------------
If "%~1"=="" (
Echo Boda Telecom Suite CE - Management Utility
Echo -----------------------------------------------------
Echo bts version -- Application version
Echo bts setup -- Setup application, create and start services
Echo bts start [service_name] -- Start application services
Echo bts stop [service_name] -- Stop application
Echo bts status -- See process statuses
Echo bts logs [service_name] -- See logs from containers
Echo bts images -- See images
Echo bts rm [service_name] -- Stop and remove
Echo bts create [service_name] -- Create services
Echo bts ps [service_name] -- Display running processes
Echo bts pause [service_name] -- Pause services
Echo bts unpause [service_name] -- Pause services
Echo bts exec service_name command -- Run command in service's container
Echo bts recreate -- Re-create the services. Useful when working with a version update
Echo.
Rem Echo manage upgrage -- Upgrade
Rem Echo manage list modules -- List installed modules
Echo -----------------------------------------------------
Echo Boda Telecom Suite - Community Edition
Echo Copyright 2017-2019. Bodastage Solutions. http://www.bodastage.com
)
Rem Run setup
Rem -------------------------
If "%~1"=="setup" (
Echo Running BTS-CE setup...
Echo Creating default folders...
Call create_folders.bat >Nul 2>&1
Echo.
Powershell -ExecutionPolicy ByPass -File win\Setup.ps1
)
Rem start
Rem -------------------------
If "%~1"=="start" (
Rem start machine
Rem docker-machine start > Nul
Rem docker-compose start
if Not "%~2" == "" (
docker-compose start %~2
Exit /b 0
)
docker-compose start
)
Rem Status
Rem -------------------------
If "%~1"=="status" (
docker container ls
)
Rem restart
Rem -------------------------
If "%~1"=="restart" (
docker-compose restart
)
Rem version
Rem -------------------------
If "%~1"=="version" (
Rem This duplication is intentional. Needs to be fixed though. The version is only picked on the second call!
Set /p Release=<VERSION
Set /p Release=<VERSION
Echo Version:%Release%
Echo Boda Telecom Suite - Community Edition
Echo Copyright 2017-2019. Bodastage Solutions. http://www.bodastage.com
)
Rem stop
Rem -------------------------
If "%~1"=="stop" (
if Not "%~2" == "" (
docker-compose stop %~2
Exit /b 0
)
docker-compose stop
Rem docker-machine stop
)
Rem logs
Rem -------------------------
If "%~1"=="logs" (
if Not "%~2" == "" (
docker-compose logs %~2
Exit /b 0
)
docker-compose logs
)
Rem exit /b 0
Rem images
Rem -------------------------
If "%~1"=="images" (
docker-compose images
)
Rem remove
Rem -------------------------
If "%~1"=="rm" (
if Not "%~2" == "" (
docker-compose stop %~2
docker-compose rm -f %~2
Exit /b 0
)
docker-compose stop
docker-compose rm -f
docker volume prune -f
)
Rem Create container and start service
Rem -------------------------
If "%~1"=="create" (
if Not "%~2" == "" (
docker-compose up -d %~2
Exit /b 0
)
Echo Creating default folders...
Call create_folders.bat >Nul 2>&1
docker-compose up -d
Rem Forward ports 8181,8888, 8080
docker-machine ls | findstr "virtualbox" 1>Nul 2>Nul
If %errorLevel% == 0 (
"%ProgramFiles%\Oracle\VirtualBox\VBoxManage.exe" controlvm "default" natpf1 "btsweb,tcp,,8888,,8888" 1>Nul 2>Nul
"%ProgramFiles%\Oracle\VirtualBox\VBoxManage.exe" controlvm "default" natpf1 "btsapi,tcp,,8181,,8181" 1>Nul 2>Nul
"%ProgramFiles%\Oracle\VirtualBox\VBoxManage.exe" controlvm "default" natpf1 "airflow-web,tcp,,8080,,8080" 1>Nul 2>Nul
)
)
Rem Display running processes
Rem -------------------------
If "%~1"=="ps" (
if Not "%~2" == "" (
docker-compose top %~2
Exit /b 0
)
)
Rem Pause services
Rem -------------------------
If "%~1"=="pause" (
if Not "%~2" == "" (
docker-compose pause %~2
Exit /b 0
)
docker-compose pause
)
Rem un pause services
Rem -------------------------
If "%~1"=="unpause" (
if Not "%~2" == "" (
docker-compose unpause %~2
Exit /b 0
)
docker-compose unpause
)
Rem Exec
Rem -------------------------
If "%~1"=="exec" (
if Not "%~2" == "" (
docker-compose %*
Exit /b 0
)
docker-compose unpause
)
Rem Recreate services
Rem -------------------------
If "%~1"=="recreate" (
@FOR /f "tokens=*" %%i In ('docker ps -q 2^>Nul') Do ( docker stop %%i & docker rm %%i )
bts create
)