Skip to content

Commit 7d65d5e

Browse files
Create CDS Archive for JVM app class pre-loading
Signed-off-by: Miranda Streeter <miranda@mirandastreeter.com>
1 parent a57bdc7 commit 7d65d5e

3 files changed

Lines changed: 26 additions & 7 deletions

File tree

Containerfile.alpine

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ COPY openvoxserver/prep_build_container.sh /
2222
RUN /prep_build_container.sh
2323

2424
################################################################################
25-
FROM base AS final
25+
FROM base AS app
2626

2727
# renovate: datasource=rubygems depName=hiera-eyaml
2828
ARG RUBYGEM_HIERA_EYAML=5.0.1
@@ -79,7 +79,7 @@ ENV AUTOSIGN=true \
7979
OPENVOXSERVER_GRAPHITE_HOST=exporter \
8080
OPENVOXSERVER_GRAPHITE_PORT=9109 \
8181
OPENVOXSERVER_HOSTNAME="" \
82-
OPENVOXSERVER_JAVA_ARGS="-Xms1024m -Xmx1024m" \
82+
OPENVOXSERVER_JAVA_ARGS="-Xms1024m -Xmx1024m -XX:SharedArchiveFile=/opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa" \
8383
OPENVOXSERVER_MAX_ACTIVE_INSTANCES=1 \
8484
OPENVOXSERVER_MAX_REQUESTS_PER_INSTANCE=0 \
8585
OPENVOXSERVER_PORT=8140 \
@@ -106,6 +106,14 @@ RUN /prep_release_container.sh
106106

107107
USER puppet:0
108108

109+
# Create a CDS archive in a stage for faster class loading.
110+
FROM app AS cds
111+
RUN OPENVOXSERVER_JAVA_ARGS="-Xms1024m -Xmx1024m -XX:ArchiveClassesAtExit=/opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa" \
112+
timeout 60 dumb-init /container-entrypoint.sh foreground || true
113+
114+
FROM app AS final
115+
COPY --from=cds /opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa /opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa
116+
109117
# k8s uses livenessProbe, startupProbe, readinessProbe and ignores HEALTHCHECK
110118
HEALTHCHECK --interval=20s --timeout=15s --retries=12 --start-period=3m CMD ["/healthcheck.sh"]
111119

Containerfile.ubuntu

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ COPY openvoxserver/prep_build_container.sh /
3131
RUN /prep_build_container.sh
3232

3333
################################################################################
34-
FROM base AS final
34+
FROM base AS app
3535

3636
# renovate: datasource=rubygems depName=hiera-eyaml
3737
ARG RUBYGEM_HIERA_EYAML=5.0.1
@@ -88,7 +88,7 @@ ENV AUTOSIGN=true \
8888
OPENVOXSERVER_GRAPHITE_HOST=exporter \
8989
OPENVOXSERVER_GRAPHITE_PORT=9109 \
9090
OPENVOXSERVER_HOSTNAME="" \
91-
OPENVOXSERVER_JAVA_ARGS="-Xms1024m -Xmx1024m" \
91+
OPENVOXSERVER_JAVA_ARGS="-Xms1024m -Xmx1024m -XX:SharedArchiveFile=/opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa" \
9292
OPENVOXSERVER_MAX_ACTIVE_INSTANCES=1 \
9393
OPENVOXSERVER_MAX_REQUESTS_PER_INSTANCE=0 \
9494
OPENVOXSERVER_PORT=8140 \
@@ -115,6 +115,14 @@ RUN /prep_release_container.sh
115115

116116
USER puppet:0
117117

118+
# Create a CDS archive in a stage for faster class loading.
119+
FROM app AS cds
120+
RUN OPENVOXSERVER_JAVA_ARGS="-Xms1024m -Xmx1024m -XX:ArchiveClassesAtExit=/opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa" \
121+
timeout 60 dumb-init /container-entrypoint.sh foreground || true
122+
123+
FROM app AS final
124+
COPY --from=cds /opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa /opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa
125+
118126
# k8s uses livenessProbe, startupProbe, readinessProbe and ignores HEALTHCHECK
119127
HEALTHCHECK --interval=20s --timeout=15s --retries=12 --start-period=3m CMD ["/healthcheck.sh"]
120128

openvoxserver/files/container-entrypoint.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,20 @@ post_execution_handler() {
8787

8888
## Sigterm Handler
8989
# shellcheck disable=SC2317 # function is called when the container receives a SIGTERM signal
90+
# We're forwarding the sigterm to the child JVM process (/usr/bin/java) instead of the
91+
# wrapper script (/opt/puppetlabs/server/apps/puppetserver/cli/apps/foreground), else it
92+
# doesn't shut down gracefully.
9093
sigterm_handler() {
9194
echoerr "Catching SIGTERM"
9295
if [ $pid -ne 0 ]; then
93-
echoerr "sigterm_handler for PID '${pid}' triggered"
96+
echoerr "sigterm_handler triggered, shutting down service"
9497
# the above if statement is important because it ensures
9598
# that the application has already started. without it you
9699
# could attempt cleanup steps if the application failed to
97100
# start, causing errors.
98101
run_custom_handler sigterm-handler
99-
kill -15 "$pid"
100-
wait "$pid"
102+
pkill -TERM -f puppet-server-release.jar
103+
while pgrep -f puppet-server-release.jar > /dev/null; do sleep 1; done
101104
post_execution_handler
102105
fi
103106
exit 143; # 128 + 15 -- SIGTERM

0 commit comments

Comments
 (0)