Code Monkey home page Code Monkey logo

spring-boot-graceful-shutdown's Introduction

Spring-Boot-Graceful-Shutdown-Starter

This starter expose endpoints on a spring-boot project to perform graceful shutdown. At this time, the actuator starter expose a shutdown endpoint, this shutdown is ok to destroy graceful the spring-context, but not for currents HTTP connections.

An issue is open on github : spring-projects/spring-boot#4657 To gain time, I have written a new Spring-Boot starter based on Spring-Boot actuator. When we hit a shutdown, the starter denied new http connections and wait end of currents connections.

Endpoints exposed :

  • HTTP : REST API /gracefulshutdown (with spring-boot-starter-actuator)
  • JMX (with spring-boot-starter-actuator)
  • SSH (with spring-boot-starter-remote-shell)

Note: Support only Undertow and Tomcat For security see actuator

Servlets engine supported

We support currently : Undertow and Tomcat

How it works

workflow

How to for ops

Setup

3 properties in application.properties (or application.yml)

Property Default Description
endpoints.shutdown.graceful.enabled false Activate the starter and expose endpoints
endpoints.shutdown.graceful.timeout 30 Wait "30" seconds before make a force shutdown
endpoints.shutdown.graceful.wait 30 The time before launch graceful shutdown, the health checker return OUT_OF_SERVICE

Perform shutdown (HTTP REST API)

Call /shutdowngraceful (in GET), the endpoint return the HTTP Response code 200 with a message.

Perform shutdown (JMX)

Must be documented

Perform shutdown (SSH)

If the spring-boot-starter-remote-shell is in dependencies, you can type the following command

endpoint invoke gracefulShutdownEndpoint

crash

Please refer to remote shell manual for setup and security.

Logs

Level Sample Description
INFO Mapped "{[/shutdowngraceful..." If graceful shutdown starter is enabled
INFO Shutdown performed in ?? second(s) When the shutdown is performed
INFO Graceful shutdown in progress.. We don't accept new connection... Wait after latest connections (max : ?? seconds) When we start a graceful shutdown
INFO Thread pool is empty, we stop now No active HTTP connection, we can kill
INFO We are now in OUT_OF_SERVICE mode, please wait ?? second(s) App is always alive, but the health checker return OUT_OF_SERVICE
WARN Thread pool did not shut down gracefully within ?? second(s). Proceeding with force shutdown Few HTTP connections are actives, but the timeout is exceeded, we perform a force shutdown
ERROR The await termination has been interrupted A force shutdown has been received before graceful shutdown

Health checker (HTTP RESP API)

An health checker endpoint is available to see the state of the app. The endpoint can be prefixed, see actuator doc. If the app is out of service, the response will be :

{
    "status": "OUT_OF_SERVICE",
    "gracefulHealth" : {
	    "status" : "OUT_OF_SERVICE"
	}
}

The HTTP code is 503 : Service unavailable. If all is good, you must be have a 200.

Security

The security is maintened by two points :

  • Isolate Path : /management
  • Isolate management opération on a specific port : please use management.port setting

How to for developers

Add spring-boot-starter-actuator in your pom.xml

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

Add spring-boot-starter-graceful-shutdown in your pom.xml

<dependency>
   <groupId>fr.azelart</groupId>
   <artifactId>spring-boot-starter-graceful-shutdown</artifactId>
   <version>X.X.X</version>
</dependency>

Check the latest version on repository.

Add spring-boot-starter-remote-shell in your pom.xml

It's optionnal

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-remote-shell</artifactId>
</dependency>

Setup the starter

In application.properties

# Enable the endpoint (mandatory)
endpoints.shutdown.graceful.enabled=true

# Specify the timeout before perform a force shutdown (optional)
endpoints.shutdown.graceful.timeout=15

# The timer before launch graceful shutdown, the health checker return OUT_OF_SERVICE (optional)
endpoints.shutdown.graceful.wait=15

Or application.yml

endpoints:
shutdown:
    graceful:
        enabled: true
        timeout: 15
        wait: 15

spring-boot-graceful-shutdown's People

Contributors

corentin59 avatar aafwu00 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.