Skip to content

Commit 1f8e754

Browse files
committed
fix: allowing --optimized to terminate gracefully
closes: #43561 Signed-off-by: Steve Hawkins <[email protected]>
1 parent 736d492 commit 1f8e754

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

quarkus/dist/src/main/content/bin/kc.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,14 @@ if [ "$PRINT_ENV" = "true" ]; then
171171
echo "Using JAVA_RUN_OPTS: $JAVA_RUN_OPTS"
172172
fi
173173

174-
eval "'$JAVA'" "$JAVA_RUN_OPTS"
175-
status=$?
174+
# trap the signals that should be forwarded to the java process
175+
trap 'status=143; while [ -z "$PID" ]; do sleep 1; done; kill -TERM $PID; wait $pid' TERM INT
176+
# run the java process in the background using the current stdin
177+
eval "{ '$JAVA' $JAVA_RUN_OPTS <&3 3<&- & } 3<&0"
178+
# obtain the pid, and await the exit status
179+
PID=$!; wait $PID; status=$?
180+
# remove the trap as signals can be directly handled
181+
trap - TERM INT
176182
# only exit code 10 means that implicit reaugmentation occurred and a relaunch is needed
177183
if [ $status = 10 ]; then
178184
JAVA_RUN_OPTS="-Dkc.config.built=true $JAVA_RUN_OPTS"

quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/StartCommandDistTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,23 @@ void noErrorSpiBuildtimeNotChanged(KeycloakDistribution dist) {
9292
cliResult.assertNoError("The following build time options");
9393
}
9494

95+
@Test
96+
@RawDistOnly(reason = "Containers are immutable")
97+
void terminateStartOptimized(KeycloakDistribution dist) {
98+
CLIResult cliResult = dist.run("build", "--db=dev-file");
99+
cliResult.assertBuild();
100+
101+
dist.setManualStop(true);
102+
cliResult = dist.run("start", "--optimized", "--http-enabled=true", "--hostname-strict=false");
103+
cliResult.assertStarted();
104+
105+
// if the child java process does not clean up, then subsequent start will fail
106+
dist.stop();
107+
108+
cliResult = dist.run("start", "--optimized", "--http-enabled=true", "--hostname-strict=false");
109+
cliResult.assertStarted();
110+
}
111+
95112
@DryRun
96113
@Test
97114
@Launch({ "--profile=dev", "start", "--db=dev-file" })

0 commit comments

Comments
 (0)