Skip to content

Commit 9a80002

Browse files
Merge pull request #154 from MirandaStreeter/appcds
Create CDS Archive for JVM app class pre-loading
2 parents d761a1e + 02e7e3f commit 9a80002

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
@@ -54,7 +54,7 @@ COPY openvoxserver/prep_build_container.sh /
5454
RUN /prep_build_container.sh
5555

5656
################################################################################
57-
FROM base AS final
57+
FROM base AS app
5858

5959
# renovate: datasource=rubygems depName=hiera-eyaml
6060
ARG RUBYGEM_HIERA_EYAML=5.0.1
@@ -111,7 +111,7 @@ ENV AUTOSIGN=true \
111111
OPENVOXSERVER_GRAPHITE_HOST=exporter \
112112
OPENVOXSERVER_GRAPHITE_PORT=9109 \
113113
OPENVOXSERVER_HOSTNAME="" \
114-
OPENVOXSERVER_JAVA_ARGS="-Xms1024m -Xmx1024m" \
114+
OPENVOXSERVER_JAVA_ARGS="-Xms1024m -Xmx1024m -XX:SharedArchiveFile=/opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa" \
115115
OPENVOXSERVER_MAX_ACTIVE_INSTANCES=1 \
116116
OPENVOXSERVER_MAX_REQUESTS_PER_INSTANCE=0 \
117117
OPENVOXSERVER_PORT=8140 \
@@ -138,6 +138,14 @@ RUN /prep_release_container.sh
138138

139139
USER puppet:0
140140

141+
# Create a CDS archive in a stage for faster class loading.
142+
FROM app AS cds
143+
RUN OPENVOXSERVER_JAVA_ARGS="-Xms1024m -Xmx1024m -XX:ArchiveClassesAtExit=/opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa -Xlog:cds=off" \
144+
timeout --preserve-status 60 dumb-init /container-entrypoint.sh foreground || [ $? -eq 143 ]
145+
146+
FROM app AS final
147+
COPY --from=cds /opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa /opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa
148+
141149
# k8s uses livenessProbe, startupProbe, readinessProbe and ignores HEALTHCHECK
142150
HEALTHCHECK --interval=20s --timeout=15s --retries=12 --start-period=3m CMD ["/healthcheck.sh"]
143151

Containerfile.ubuntu

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

6565
################################################################################
66-
FROM base AS final
66+
FROM base AS app
6767

6868
# renovate: datasource=rubygems depName=hiera-eyaml
6969
ARG RUBYGEM_HIERA_EYAML=5.0.1
@@ -120,7 +120,7 @@ ENV AUTOSIGN=true \
120120
OPENVOXSERVER_GRAPHITE_HOST=exporter \
121121
OPENVOXSERVER_GRAPHITE_PORT=9109 \
122122
OPENVOXSERVER_HOSTNAME="" \
123-
OPENVOXSERVER_JAVA_ARGS="-Xms1024m -Xmx1024m" \
123+
OPENVOXSERVER_JAVA_ARGS="-Xms1024m -Xmx1024m -XX:SharedArchiveFile=/opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa" \
124124
OPENVOXSERVER_MAX_ACTIVE_INSTANCES=1 \
125125
OPENVOXSERVER_MAX_REQUESTS_PER_INSTANCE=0 \
126126
OPENVOXSERVER_PORT=8140 \
@@ -147,6 +147,14 @@ RUN /prep_release_container.sh
147147

148148
USER puppet:0
149149

150+
# Create a CDS archive in a stage for faster class loading.
151+
FROM app AS cds
152+
RUN OPENVOXSERVER_JAVA_ARGS="-Xms1024m -Xmx1024m -XX:ArchiveClassesAtExit=/opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa -Xlog:cds=off" \
153+
timeout --preserve-status 60 dumb-init /container-entrypoint.sh foreground || [ $? -eq 143 ]
154+
155+
FROM app AS final
156+
COPY --from=cds /opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa /opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa
157+
150158
# k8s uses livenessProbe, startupProbe, readinessProbe and ignores HEALTHCHECK
151159
HEALTHCHECK --interval=20s --timeout=15s --retries=12 --start-period=3m CMD ["/healthcheck.sh"]
152160

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)