golang--0 Offline time-type restart

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.