SIGTERM and SIGKILLHere's a quick overview of SIGTERM and SIGKILL:
SIGTERM: Termination request signal. The process can still run after receiving this.SIGKILL: Forced termination. The process can no longer run.Graceful shutdown means that a process or the like closes the acceptance of new work, processes the work in process to the point where it is in process, and then finishes it safely. The image is "stores".
When a kill occurs, the system may be in a half-finished state or the data may be inconsistent. Graceful shutdown is a protective measure to prevent this from happening.
For example, considering the graceful shutdown of an HTTP server as an example, when the HTTP server enters the termination phase, it will not accept new requests, but the existing requests will be terminated after returning a proper response.
Docker, Kubernetes, etc. should send a SIGTERM signal after sending aSIGTERM signal so that the application can be gracefully shut down, and then after a certain grace period, if it still does not terminate, send a SIGKILL to force it to terminate. It has become.
SIGTERM to SIGKILL such as Docker and KubernetesThe grace period depends on the system. The grace period for each system is listed below. Please refer to it when implementing Graceful Shutdown.
docker stop
SIGTERM and after 10 seconds send SIGKILL if the process remains.-t and --time options.docker-compose stop and docker-compose down.docker kill
SIGKILLdocker rm -f, docker-compose kill.SIGTERM and after 30 seconds send SIGKILL if the process remains.Systemd
SIGTERM → 90 seconds later SIGKILLUpstart
SIGTERM → 5 seconds later SIGKILLSysvinit
SIGTERM → 5 seconds later SIGKILLRecommended Posts