1

I have a Spring Boot web application running in docker.

 <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

Even if I define an ExitCodeGenerator I cannot override the exit code

@Bean
public ExitCodeGenerator exitCodeGenerator() {
    return () -> 0;
}

@Bean
public ApplicationListener applicationListener() {

   return applicationEvent -> {
       logger.info("*** Event {}", applicationEvent);
       if (applicationEvent instanceof ExitCodeEvent) {
           logger.info("---> ExitCode={}", ((ExitCodeEvent) applicationEvent).getExitCode());
       }
    };
}

It seems that the shutdown of the application is somehow handled differently. Main reason for changing the exit code is dockers restart functionality. If I stop my application it stops with exit code 142. Default behaviour for java applications. But If I now restart docker or the server docker automatically starts the application because all containers with an exit code > 0 are started.

Thanks for your answers.

boskop
  • 609
  • 5
  • 23
  • If you don't want it to restart why don't you specify `--restart no` parameter while running the container? – Tarun Lalwani Sep 22 '17 at 09:08
  • let's say we have a litte framework about that handling. Normally we want that the containers are restarted, but not, if they have been manually stopped. I know there is also a restart policy for that, but I'd like more to exit 'properly' with exit code 0 from a docker point of view. – boskop Sep 22 '17 at 09:35
  • See if this helps? http://www.logicbig.com/tutorials/spring-framework/spring-boot/app-exit-code/, your approach and the one in article seems a bit different – Tarun Lalwani Sep 22 '17 at 12:39
  • No, this does not work for web applications, only for command line apps – boskop Oct 19 '17 at 12:01

0 Answers0