docs/restart.md
Puma provides three distinct kinds of restart operations, each for different use cases. This document describes "hot restarts" and "phased restarts." The third kind of restart operation is called "refork" and is described in the documentation for fork_worker.
To perform a "hot" restart, Puma performs an exec operation to start the process up again, so no memory is shared between the old process and the new process. As a result, it is safe to issue a restart at any place where you would manually stop Puma and start it again. In particular, it is safe to upgrade Puma itself using a hot restart.
If the new process is unable to load, it will simply exit. You should therefore run Puma under a process monitor when using it in production.
Any of the following will cause a Puma server to perform a hot restart:
puma process the SIGUSR2 signalGET request to the Puma status/control server with the path /restartpumactl restart (this uses the control server method if available, otherwise sends the SIGUSR2 signal to the process)directory option. If directory is set to symlink, this is automatically re-evaluated, so this mechanism can be used to upgrade the application.before_restart is invoked just before the server shuts down. This can be used to clean up resources (like long-lived database connections) gracefully. Since Ruby 2.0, it is not typically necessary to explicitly close file descriptors on restart. This is because any file descriptor opened by Ruby will have the FD_CLOEXEC flag set, meaning that file descriptors are closed on exec. before_restart is useful, though, if your application needs to perform any more graceful protocol-specific shutdown procedures before closing connections.Phased restarts replace all running workers in a Puma cluster. This is a useful way to upgrade the application that Puma is serving gracefully. A phased restart works by first killing an old worker, then starting a new worker, waiting until the new worker has successfully started before proceeding to the next worker. This process continues until all workers are replaced. The master process is not restarted.
Any of the following will cause a Puma server to perform a phased restart:
puma process the SIGUSR1 signalGET request to the Puma status/control server with the path /phased-restartpumactl phased-restart (this uses the control server method if available, otherwise sends the SIGUSR1 signal to the process)prune_bundler is enabled and that preload_app! is disableddirectory option. If directory is set to symlink, this is automatically re-evaluated, so this mechanism can be used to upgrade the application.before_restart is not invokedpuma itself, anything in extra_runtime_dependencies, or dependencies thereof. Upgrading other gems is safe.extra_runtime_dependencies that have native extensions or have dependencies that have native extensions (one common example is puma_worker_killer and its dependency on ffi). Workers will fail on boot during a phased restart. The underlying issue is recorded in an issue on the rubygems project. Hot restarts are your only option here if you need these dependencies.