This is a created article in which the information may have evolved or changed.
In Hacker news see with Go to achieve Zero-downtime restarts, meaning is probably zero offline time type restart, very early know nginx can easily do smooth restart, always want to use go to achieve such a function. Looked at its code implementation, so with this blog post.
The project name is Goagain, address in: Https://github.com/rcrowley/goagain. The project is a class library, the package, which can be easily restarted by adding the package in the Go Development program.
The Goagain will monitor 2 system signals, one for Sigterm, and the program will stop running when the signal is received. Another signal is SIGUSR2, the behavior of receiving this signal is that the current process, that is, the parent process will create a new child process, and then the parent process to save the PID to an environment variable named goagain_ppid; when the child process starts, it retrieves the GOAGAIN_PPID variable, To determine if the program is to be restarted, this variable closes the parent process to achieve a smooth restart.
In the Goagain project there is an example where we can build our own programs as needed. I personally tested the example, can run, the effect is good. Here is the effect.
Posted please specify from: Geton