How to make a Spring Boot application quit on tomcat failure
Since you have everything containerized, it's way simpler.
Just set up a small healthcheck endpoint with Spring Web which serves to see if the server is still running, something like:
@RestController(
public class HealtcheckController {
@Get("/monitoring")
public String getMonitoring() {
return "200: OK";
}
}
and then refer to it in the HEALTHCHECK
part of your Dockerfile
. If the server stops, then the container will be scheduled as unhealthy
and it will be restarted:
FROM ...
ENTRYPOINT ...
HEALTHCHECK localhost:8080/monitoring
If you don't want to develop anything, then you can just use any other Endpoint that you know it should successfully answer as HEALTCHECK
, but I would recommend that you have one endpoint explicitly for that.