|
1 | 1 | [[web.graceful-shutdown]]
|
2 | 2 | = Graceful Shutdown
|
3 | 3 |
|
4 |
| -Graceful shutdown is supported with all four embedded web servers (Jetty, Reactor Netty, Tomcat, and Undertow) and with both reactive and servlet-based web applications. |
| 4 | +Graceful shutdown is enabled by default with all four embedded web servers (Jetty, Reactor Netty, Tomcat, and Undertow) and with both reactive and servlet-based web applications. |
5 | 5 | It occurs as part of closing the application context and is performed in the earliest phase of stopping `SmartLifecycle` beans.
|
6 | 6 | This stop processing uses a timeout which provides a grace period during which existing requests will be allowed to complete but no new requests will be permitted.
|
7 | 7 |
|
| 8 | +To configure the timeout period, configure the configprop:spring.lifecycle.timeout-per-shutdown-phase[] property, as shown in the following example: |
| 9 | + |
| 10 | +[configprops,yaml] |
| 11 | +---- |
| 12 | +spring: |
| 13 | + lifecycle: |
| 14 | + timeout-per-shutdown-phase: "20s" |
| 15 | +---- |
| 16 | + |
| 17 | +NOTE: Graceful shutdown with Tomcat requires Tomcat 9.0.33 or later. |
| 18 | + |
| 19 | +IMPORTANT: Shutdown in your IDE may be immediate rather than graceful if it does not send a proper `SIGTERM` signal. |
| 20 | +See the documentation of your IDE for more details. |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +[[web.graceful-shutdown.rejecting-requests-during-the-grace-period]] |
| 25 | +== Rejecting Requests During the Grace Period |
| 26 | + |
8 | 27 | The exact way in which new requests are not permitted varies depending on the web server that is being used.
|
9 | 28 | Implementations may stop accepting requests at the network layer, or they may return a response with a specific HTTP status code or HTTP header.
|
10 | 29 | The use of persistent connections can also change the way that requests stop being accepted.
|
11 | 30 |
|
12 |
| -TIP: To learn about more the specific method used with your web server, see the `shutDownGracefully` API documentation for javadoc:org.springframework.boot.web.embedded.tomcat.TomcatWebServer#shutDownGracefully(org.springframework.boot.web.server.GracefulShutdownCallback)[], javadoc:org.springframework.boot.web.embedded.netty.NettyWebServer#shutDownGracefully(org.springframework.boot.web.server.GracefulShutdownCallback)[], javadoc:org.springframework.boot.web.embedded.jetty.JettyWebServer#shutDownGracefully(org.springframework.boot.web.server.GracefulShutdownCallback)[] or javadoc:org.springframework.boot.web.embedded.undertow.UndertowWebServer#shutDownGracefully(org.springframework.boot.web.server.GracefulShutdownCallback)[]. |
| 31 | +TIP: To learn more about the specific method used with your web server, see the `shutDownGracefully` API documentation for javadoc:org.springframework.boot.web.embedded.tomcat.TomcatWebServer#shutDownGracefully(org.springframework.boot.web.server.GracefulShutdownCallback)[], javadoc:org.springframework.boot.web.embedded.netty.NettyWebServer#shutDownGracefully(org.springframework.boot.web.server.GracefulShutdownCallback)[], javadoc:org.springframework.boot.web.embedded.jetty.JettyWebServer#shutDownGracefully(org.springframework.boot.web.server.GracefulShutdownCallback)[] or javadoc:org.springframework.boot.web.embedded.undertow.UndertowWebServer#shutDownGracefully(org.springframework.boot.web.server.GracefulShutdownCallback)[]. |
13 | 32 |
|
14 | 33 | Jetty, Reactor Netty, and Tomcat will stop accepting new requests at the network layer.
|
15 | 34 | Undertow will accept new connections but respond immediately with a service unavailable (503) response.
|
16 | 35 |
|
17 |
| -NOTE: Graceful shutdown with Tomcat requires Tomcat 9.0.33 or later. |
18 | 36 |
|
19 |
| -To enable graceful shutdown, configure the configprop:server.shutdown[] property, as shown in the following example: |
20 | 37 |
|
21 |
| -[configprops,yaml] |
22 |
| ----- |
23 |
| -server: |
24 |
| - shutdown: "graceful" |
25 |
| ----- |
| 38 | +[[web.graceful-shutdown.disabling-graceful-shutdown]] |
| 39 | +== Disabling Graceful Shutdown |
26 | 40 |
|
27 |
| -To configure the timeout period, configure the configprop:spring.lifecycle.timeout-per-shutdown-phase[] property, as shown in the following example: |
| 41 | +To disable graceful shutdown, configure the configprop:server.shutdown[] property, as shown in the following example: |
28 | 42 |
|
29 | 43 | [configprops,yaml]
|
30 | 44 | ----
|
31 |
| -spring: |
32 |
| - lifecycle: |
33 |
| - timeout-per-shutdown-phase: "20s" |
| 45 | +server: |
| 46 | + shutdown: "immediate" |
34 | 47 | ----
|
35 |
| - |
36 |
| -IMPORTANT: Using graceful shutdown with your IDE may not work properly if it does not send a proper `SIGTERM` signal. |
37 |
| -See the documentation of your IDE for more details. |
|
0 commit comments