This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmc.sh
executable file
·215 lines (182 loc) · 5.61 KB
/
mc.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
#!/bin/bash
BASEDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
wrap_exec() {
echo "
> $@"
exec $@
}
wrap_launch() {
out=$1
shift
echo "
> $@ > $out 2>&1 &"
$@ > $out 2>&1 &
}
wrap_mvnw() {
echo "
> $@"
./mvnw $@
}
usage() {
echo "
mc.sh [--clean|--format|--native] [images|dc|jars|help]
--clean
Clean projects.
--format
Flag that triggers formatting of source code.
--native
Flag that triggers use/inclusion of native image.
Containers:
images
Action that invokes './mvnw package' with
properties set to build container images and skip tests.
If the native flag has been specified, additional properties
are set to use a container to build native images.
dc
Invoke docker-compose using files in the deploy/dc directory.
Additional command line arguments are passed to docker-compose.
If the native flag has been specified, native images will be included
in docker-compose operations.
Using jars directly:
jars
Build and package appropriate jars for all runtimes. If the
native flag has been specified, also build native images.
start
Run jars directly (java -jar ... ). If the native flag has been
specified, also start native binaries. Ports are adjusted to
match localhost expectations in mc-client.sh
list
List running monster-combat processes (started with start)
mem
Show memory used by running monster-combat processes (once, using ps)
memwatch
Monitor memory used by running monster-combat processes (using top)
stop
Stop monster-combat processes (kill)
Example invocations:
./mc.sh
Invokes ./mvnw install
./mc.sh --format
Invokes ./mvnw install process-sources
./mc.sh --native
Invokes ./mvnw install -Dnative
./mc.sh images
Invokes ./mvnw package -DskipTests -Dimages
./mc.sh --native images
Creates native Quarkus container images using a container for build.
These options are necessary to build native container images on
Windows and MacOS.
Invokes ./mvnw package -DskipTests -Dnative -Dimages
./mc.sh dc up -d
If no override file exists:
docker-compose -f ./deploy/dc/docker-compose.yml up -d
otherwise:
docker-compose -f ./deploy/dc/docker-compose.yml \\
-f ./deploy/dc/docker-compose.override.yml \\
up -d
./mc.sh --native dc up -d
If no override file exists:
docker-compose -f ./deploy/dc/docker-compose.yml \\
-f ./deploy/dc/docker-compose-native.yml \\
up -d
otherwise:
docker-compose -f ./deploy/dc/docker-compose.yml \\
-f ./deploy/dc/docker-compose-native.yml \\
-f ./deploy/dc/docker-compose.override.yml \\
up -d
"
}
# Ensure we're executing from project root directory
cd "${BASEDIR}"
format=
native=
clean=
ARGS=()
for x in "$@"; do
case "$x" in
--format)
echo "Format source"
format="process-sources "
;;
--native)
echo "Build and use native images"
native="-Dnative "
;;
--clean)
echo "Clean before compiling"
clean="clean "
;;
*)
ARGS+=("$x")
;;
esac
done
if [ ${#ARGS[@]} -eq 0 ]; then
wrap_mvnw ${clean}install ${format}${native}
fi
ACTION="${ARGS[0]}"
unset ARGS[0]
case "$ACTION" in
images)
wrap_mvnw ${clean}package -Dimages -DskipTests ${ARGS[@]}
if [ -n "$native" ]; then
wrap_mvnw ${clean}package -Dimages -DskipTests ${native}${ARGS[@]}
fi
;;
dc)
override_dc=
native_dc=
if [ -e ./deploy/dc/docker-compose.override.yml ]; then
override_dc="-f ./deploy/dc/docker-compose.override.yml"
fi
if [ -n "$native" ]; then
native_dc="-f ./deploy/dc/docker-compose-native.yml"
fi
options="-f ./deploy/dc/docker-compose.yml ${native_dc} ${override_dc}"
wrap_exec docker-compose $options ${ARGS[@]}
;;
jars)
wrap_mvnw ${clean}package
if [ -n "$native" ]; then
wrap_mvnw package ${native}
fi
;;
start)
wrap_launch out.server.spring java -Dmonster-combat -jar spring5-micrometer/target/mc-spring5-micrometer-1.0.0-exec.jar --server.port=8280
wrap_launch out.server.quarkus java -Dmonster-combat -Dquarkus.http.port=8281 -jar quarkus-micrometer/target/quarkus-app/quarkus-run.jar
wrap_launch out.server.mpmetrics java -Dmonster-combat -Dquarkus.http.port=8282 -jar quarkus-mpmetrics/target/quarkus-app/quarkus-run.jar
if [ -n "$native" ]; then
wrap_launch out.server.quarkus-native ./quarkus-micrometer/target/mc-quarkus-micrometer-1.0.0-runner -Dmonster-combat -Dquarkus.http.port=8283
wrap_launch out.server.mpmetrics-native ./quarkus-mpmetrics/target/mc-quarkus-mpmetrics-1.0.0-runner -Dmonster-combat -Dquarkus.http.port=8284
fi
;;
status|list)
wrap_exec ps -A -o pid,command | grep monster-combat | grep -v grep
;;
mem)
if top -version 2>/dev/null; then
echo "linux"
else
wrap_exec ps -A -o pid,%cpu,vsz,rss,%mem,command|egrep "MEM|monster-combat"|grep -v grep
fi
;;
memwatch)
pids=$(ps -m -o pid,command | awk '{$1=$1};1'| grep monster-combat | grep -v grep | cut -d ' ' -f1)
if top -version 2>/dev/null; then
echo "linux"
else
wrap_exec top -o pid -r -stats pid,cpu,vsize,mem,command $(printf -- '-pid %s ' ${pids})
fi
;;
stop)
pids=$(ps -A -o pid,command | awk '{$1=$1};1' | grep monster-combat | grep -v grep | cut -d ' ' -f1)
for x in $pids; do echo "stopping $x"; kill $x; done
;;
help)
usage
;;
*)
echo "Unknown: $ACTION ${ARGS[@]}"
usage
;;
esac