graceful shutdown

Stopping a service in an orderly way: finish current work, close connections, then exit.

In more detail

It relies on the process receiving and handling SIGTERM, the polite stop request, before anything escalates to SIGKILL. For load-balanced services, draining a backend first lets it finish existing connections. Two common traps are starting the app through a shell that does not pass the signal on, and allowing less time than the app needs to finish.

Examples

In the twelve-factor app a web process stops listening, finishes its requests and exits when it receives SIGTERM, and a worker returns its job to the queue. Logging the shutdown proves it was graceful.
On SIGTERM: mark unready, wait for load balancers, drain in-flight requests, close database pools, exit with code zero.
signal.Notify(stop, syscall.SIGTERM)
<-stop
server.Shutdown(ctx)
Spring Boot: server.shutdown=graceful stops accepting new requests and waits for active ones.

Related terms

Taught in

References