I have a spring webflux application running on ECS. Intent is whenever the instances scale-in or are terminated (during deployment or otherwise), the @PreDestroy
method within the Processor.java
should be executed.
On local, while running the application on IntelliJ, when the application is stopped, the @PreDestroy
annotated method is getting invoked. But it is not working when deployed on ECS.
I found various links stating that while running the application though shell script the shell absorbs the signals and does not pass it through to the application. For that, I used exec
command in entrypoint.sh
, but this is still not working.
Dockerfile
ARG OPENJDK_DIGEST
FROM openjdk:8-jre@${OPENJDK_DIGEST}
LABEL org.opencontainers.image.authors="xxxx.xxx.com"
VOLUME /tmp
ARG JAR_FILE
ARG PROFILE
ADD ${JAR_FILE} app.jar
ENV PROFILE_ENV=${PROFILE}
EXPOSE 8080
COPY entrypoint.sh /
COPY job.sh /
COPY tini-arm64 /
ENTRYPOINT ["/entrypoint.sh"]
entrypoint.sh
# Execute the Java application
exec java -Dspring.profiles.active=${PROFILE_ENV}
-XX:+UseG1GC
-Djava.security.egd=file:/dev/./urandom
-Dloader.main=com.paytmlabs.adtech.adtechdecisionengine.AdTechDecisionEngineApplication.java
-XX:CompressedClassSpaceSize=2g
-jar app.jar
Processor.java
@Slf4j
@Component
@DependsOn({"dep1", "dep2", "dep3", "dep4"})
public class AuditSinkEventProcessor extends SinkEventProcessor {
.
.
.
@PreDestroy
public void destroy() {
this.stopSink();
this.processParquetFiles(true);
}
}
Any suggestions?