Closed PavelPolyakov closed 10 years ago
Hi Pavel,
First let's make sure you know what you're getting yourself into. goagain
is a library that performs the subtle parts of restarting a service without downtime. If you do not need this then stop reading and just use System V init as you mentioned above.
If it is a zero-downtime restart you're after then step one is to make your application stop gracefully. In Go, this typically means closing your net.Listener
and waiting either until some timeout or until all active connections have been closed. This latter sort of bookkeeping is typically handled by a sync.WaitGroup
.
Once you have a service that can stop gracefully you can use goagain
to restart without downtime as illustrated in https://github.com/rcrowley/goagain/blob/master/example/single/main.go. To initiate a zero-downtime restart you send SIGUSR2
to the process. It then forks and reexecutes. In the child, goagain
picks up the inherited file descriptor and begins accepting connections. At that point the child is functional and it sends SIGQUIT
to the parent to stop it gracefully. After the parent exits the child is reparented to init
and the restart is complete. This works well with System V init but is incompatible with Upstart and similar init
implementations.
Does that help?
Thanks Richard,
It has helped. The key thing is, that it isn's stated anywhere (or was not clear for me), what we should send to init the restart.
Now I see that it is the SIGUSR2 signal which starts the show. The same signal is the initiator for the another strategy - the "double" strategy, am I understand right?
Thanks
Yes, the Double
strategy is more complicated in order to attempt to support Upstart and the like. It's very experimental but you do the same thing: send SIGUSR2
.
Hi,
Could you point me the direction how can I build the service which would support the "restart" operation?
The big goal of mine, is to develop an application which I would be able to restart using the command like
service apache2 restart
This case, when I have new binary uploaded, the new entity would be the updated application (am I right?)As I understand the "goagain" is something I can use for this purpose. But I'm a bit lost about how should I use it.
I run the "single" example - I tried to kill it, to interrupt it, but neither operation has lead to the fact that the application was restarted.
Thanks