To run:
./gradlew bootRun
Graceful shutdown was introduced in Spring Boot 2.3.
curl localhost:8080/ping -v
128 + exit_code_value
SIGKILL (9)
- application exists without waiting with non-zero exit value 137
SIGINT (2) = Ctrl+C
- application waits for requests to finish, but finishes with non-zero exit value 130
SIGTERM (15)
- application waits for requests to finish, but finishes with non-zero exit value 143
calling curl localhost:8287/actuator/shutdown -X POST -v
- application waits for requests to finish, ends with 0 return code
K8s apps must end with status code 0 otherwise it's taken as failed shutdown.
prestop hook not possible to use because Actuator shutdown is not blocking, so sigterm is called immediately. Block on calling some url is also not possible because Spring stops accepting all connections.
./gradlew bootBuildImage
docker run docker.io/library/spring-graceful-shutdown-demo:0.0.1-SNAPSHOT
There is no fix in Spring build image.
docker build -t matejuh/spring-graceful-shutdown-demo:0.1.1 .