diff --git a/Containerfile.alpine b/Containerfile.alpine index cd3ae56..1f24fa0 100644 --- a/Containerfile.alpine +++ b/Containerfile.alpine @@ -54,7 +54,7 @@ COPY openvoxserver/prep_build_container.sh / RUN /prep_build_container.sh ################################################################################ -FROM base AS final +FROM base AS app # renovate: datasource=rubygems depName=hiera-eyaml ARG RUBYGEM_HIERA_EYAML=5.0.1 @@ -111,7 +111,7 @@ ENV AUTOSIGN=true \ OPENVOXSERVER_GRAPHITE_HOST=exporter \ OPENVOXSERVER_GRAPHITE_PORT=9109 \ OPENVOXSERVER_HOSTNAME="" \ - OPENVOXSERVER_JAVA_ARGS="-Xms1024m -Xmx1024m" \ + OPENVOXSERVER_JAVA_ARGS="-Xms1024m -Xmx1024m -XX:SharedArchiveFile=/opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa" \ OPENVOXSERVER_MAX_ACTIVE_INSTANCES=1 \ OPENVOXSERVER_MAX_REQUESTS_PER_INSTANCE=0 \ OPENVOXSERVER_PORT=8140 \ @@ -138,6 +138,14 @@ RUN /prep_release_container.sh USER puppet:0 +# Create a CDS archive in a stage for faster class loading. +FROM app AS cds +RUN OPENVOXSERVER_JAVA_ARGS="-Xms1024m -Xmx1024m -XX:ArchiveClassesAtExit=/opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa -Xlog:cds=off" \ + timeout --preserve-status 60 dumb-init /container-entrypoint.sh foreground || [ $? -eq 143 ] + +FROM app AS final +COPY --from=cds /opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa /opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa + # k8s uses livenessProbe, startupProbe, readinessProbe and ignores HEALTHCHECK HEALTHCHECK --interval=20s --timeout=15s --retries=12 --start-period=3m CMD ["/healthcheck.sh"] diff --git a/Containerfile.ubuntu b/Containerfile.ubuntu index 7a93a71..c13d361 100644 --- a/Containerfile.ubuntu +++ b/Containerfile.ubuntu @@ -63,7 +63,7 @@ COPY openvoxserver/prep_build_container.sh / RUN /prep_build_container.sh ################################################################################ -FROM base AS final +FROM base AS app # renovate: datasource=rubygems depName=hiera-eyaml ARG RUBYGEM_HIERA_EYAML=5.0.1 @@ -120,7 +120,7 @@ ENV AUTOSIGN=true \ OPENVOXSERVER_GRAPHITE_HOST=exporter \ OPENVOXSERVER_GRAPHITE_PORT=9109 \ OPENVOXSERVER_HOSTNAME="" \ - OPENVOXSERVER_JAVA_ARGS="-Xms1024m -Xmx1024m" \ + OPENVOXSERVER_JAVA_ARGS="-Xms1024m -Xmx1024m -XX:SharedArchiveFile=/opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa" \ OPENVOXSERVER_MAX_ACTIVE_INSTANCES=1 \ OPENVOXSERVER_MAX_REQUESTS_PER_INSTANCE=0 \ OPENVOXSERVER_PORT=8140 \ @@ -147,6 +147,14 @@ RUN /prep_release_container.sh USER puppet:0 +# Create a CDS archive in a stage for faster class loading. +FROM app AS cds +RUN OPENVOXSERVER_JAVA_ARGS="-Xms1024m -Xmx1024m -XX:ArchiveClassesAtExit=/opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa -Xlog:cds=off" \ + timeout --preserve-status 60 dumb-init /container-entrypoint.sh foreground || [ $? -eq 143 ] + +FROM app AS final +COPY --from=cds /opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa /opt/puppetlabs/server/apps/puppetserver/puppetserver.jsa + # k8s uses livenessProbe, startupProbe, readinessProbe and ignores HEALTHCHECK HEALTHCHECK --interval=20s --timeout=15s --retries=12 --start-period=3m CMD ["/healthcheck.sh"] diff --git a/openvoxserver/files/container-entrypoint.sh b/openvoxserver/files/container-entrypoint.sh index cb43f7f..aed8448 100755 --- a/openvoxserver/files/container-entrypoint.sh +++ b/openvoxserver/files/container-entrypoint.sh @@ -87,17 +87,20 @@ post_execution_handler() { ## Sigterm Handler # shellcheck disable=SC2317 # function is called when the container receives a SIGTERM signal +# We're forwarding the sigterm to the child JVM process (/usr/bin/java) instead of the +# wrapper script (/opt/puppetlabs/server/apps/puppetserver/cli/apps/foreground), else it +# doesn't shut down gracefully. sigterm_handler() { echoerr "Catching SIGTERM" if [ $pid -ne 0 ]; then - echoerr "sigterm_handler for PID '${pid}' triggered" + echoerr "sigterm_handler triggered, shutting down service" # the above if statement is important because it ensures # that the application has already started. without it you # could attempt cleanup steps if the application failed to # start, causing errors. run_custom_handler sigterm-handler - kill -15 "$pid" - wait "$pid" + pkill -TERM -f puppet-server-release.jar + while pgrep -f puppet-server-release.jar > /dev/null; do sleep 1; done post_execution_handler fi exit 143; # 128 + 15 -- SIGTERM