Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fish 10015 design graceful shutdown of docker images #7158

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ebed6b1
FISH-10015 : Graceful shutdown for server-full
luiseufrasio Jan 9, 2025
af059bc
FISH-10015 : Wait Payara Process before finish the container
luiseufrasio Jan 14, 2025
8b43034
FISH-10015 : Adding a log to verify SIGTERM was captured by hook
luiseufrasio Jan 14, 2025
6e34baf
FISH-10015 : Using tini in micro image
luiseufrasio Jan 14, 2025
3d68652
FISH-10015 : Fixing jar copy
luiseufrasio Jan 14, 2025
14b1522
FISH-10015 : complete path for entrypoint.sh
luiseufrasio Jan 14, 2025
c8032e0
FISH-10015 : apk instead of apt-get
luiseufrasio Jan 14, 2025
d81ce9a
FISH-10015 : rm removed
luiseufrasio Jan 14, 2025
651f4ce
FISH-10015 : installing tini separately
luiseufrasio Jan 14, 2025
643fadd
FISH-10015 : waiting micro shutdown
luiseufrasio Jan 14, 2025
cd1a914
FISH-10015 : typo removed
luiseufrasio Jan 14, 2025
6e0c893
FISH-10015 : trying to debug
luiseufrasio Jan 14, 2025
dff3a83
FISH-10015 : killTerm being passed to java process
luiseufrasio Jan 14, 2025
4a23b31
FISH-10015 : removing the debug args
luiseufrasio Jan 15, 2025
d217109
FISH-10015 : copyrigths added
luiseufrasio Jan 15, 2025
c476db9
FISH-10015 : -jar payara-micro.jar back, accidentally removed
luiseufrasio Jan 15, 2025
8231114
FISH-10015 : waiting $child
luiseufrasio Jan 15, 2025
144e8f3
Update appserver/extras/payara-micro/payara-micro-core/src/main/java/…
luiseufrasio Jan 17, 2025
fb974b2
FISH-10015 : adding and flushing log: Payara micro Stopped
luiseufrasio Jan 17, 2025
41b52f2
FISH-10015 : messages suggested by @fturizo
luiseufrasio Jan 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
# Copyright (c) 2023 Payara Foundation and/or its affiliates. All rights reserved.
# Copyright (c) 2023-2025 Payara Foundation and/or its affiliates. All rights reserved.
#
# The contents of this file are subject to the terms of either the GNU
# General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -52,6 +52,9 @@ ENV PAYARA_DIR=${HOME_DIR} \
MEM_MAX_RAM_PERCENTAGE="70.0" \
MEM_XSS="512k"

# Add Tini
RUN apk add --no-cache tini

RUN true \
&& mkdir -p "${HOME_DIR}" \
&& addgroup --gid 1000 payara \
Expand All @@ -69,5 +72,5 @@ WORKDIR ${HOME_DIR}
COPY --chown=payara:payara maven/bin/* ${SCRIPT_DIR}/
COPY --chown=payara:payara maven/artifacts/payara-micro.jar .

ENTRYPOINT ["/bin/sh", "entrypoint.sh"]
CMD ["--deploymentDir","/opt/payara/deployments"]
ENTRYPOINT ["tini", "--", "/opt/payara/entrypoint.sh"]
CMD ["--deploymentDir", "/opt/payara/deployments"]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
# Copyright (c) 2023 Payara Foundation and/or its affiliates. All rights reserved.
# Copyright (c) 2023-2025 Payara Foundation and/or its affiliates. All rights reserved.
#
# The contents of this file are subject to the terms of either the GNU
# General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -39,4 +39,14 @@

set -e

exec java -XX:MaxRAMPercentage=${MEM_MAX_RAM_PERCENTAGE} -Xss${MEM_XSS} -XX:+UseContainerSupport ${JVM_ARGS} -jar payara-micro.jar "$@"
# Doing a Graceful Shutdown before container stops
trap 'echo "Stopping Payara-Micro...";
kill -TERM "$child" 2>/dev/null;
wait $child;
echo "Payara-Micro stopped. Exiting gracefully";' SIGTERM
luiseufrasio marked this conversation as resolved.
Show resolved Hide resolved

exec java -XX:MaxRAMPercentage=${MEM_MAX_RAM_PERCENTAGE} -Xss${MEM_XSS} -XX:+UseContainerSupport ${JVM_ARGS} -jar payara-micro.jar "$@" &
child=$!

# Wait Payara-Micro Process before finish the container
wait $child
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
# Copyright (c) 2023-2024 Payara Foundation and/or its affiliates. All rights reserved.
# Copyright (c) 2023-2025 Payara Foundation and/or its affiliates. All rights reserved.
#
# The contents of this file are subject to the terms of either the GNU
# General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -111,5 +111,4 @@ RUN true \
${PAYARA_DIR}/glassfish/domains/${DOMAIN_NAME}/logs \
&& true

ENTRYPOINT ["tini", "--"]
CMD "${SCRIPT_DIR}/entrypoint.sh"
ENTRYPOINT ["tini", "--", "/opt/payara/scripts/entrypoint.sh"]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
################################################################################
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
# Copyright (c) 2023 Payara Foundation and/or its affiliates. All rights reserved.
# Copyright (c) 2023-2025 Payara Foundation and/or its affiliates. All rights reserved.
#
# The contents of this file are subject to the terms of either the GNU
# General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -47,4 +47,13 @@ for f in ${SCRIPT_DIR}/init_* ${SCRIPT_DIR}/init.d/*; do
echo
done

exec ${SCRIPT_DIR}/startInForeground.sh $PAYARA_ARGS
# Doing a Graceful Shutdown before container stops
trap 'echo "Received SIGTERM. Stopping Payara..."; ${PAYARA_DIR}/bin/asadmin --user=${ADMIN_USER} --passwordfile=${PASSWORD_FILE} stop-domain ${DOMAIN_NAME} &
luiseufrasio marked this conversation as resolved.
Show resolved Hide resolved
pid=$!; wait $pid;
echo "Payara stopped. Exiting gracefully";' SIGTERM
luiseufrasio marked this conversation as resolved.
Show resolved Hide resolved

exec ${SCRIPT_DIR}/startInForeground.sh $PAYARA_ARGS &
payara_pid=$!

# Wait Payara Process before finish the container
wait $payara_pid
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) [2016-2023] Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) [2016-2025] Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -1746,7 +1746,7 @@ private void deployAll() throws GlassFishException {

private void addShutdownHook() {
Runtime.getRuntime().addShutdownHook(new Thread(
"GlassFish Shutdown Hook") {
"Micro Shutdown Hook") {
luiseufrasio marked this conversation as resolved.
Show resolved Hide resolved
@Override
public void run() {
try {
Expand Down