braintree / manners

A polite Go HTTP server that shuts down gracefully.
MIT License
997 stars 103 forks source link

How the channel would get the shutdown message? #9

Closed PavelPolyakov closed 10 years ago

PavelPolyakov commented 10 years ago

Hi,

Could you clarify for me - which way I should send the message to the server. Shutdown ?

My real goal (why I'm actually here) is to know how can I build the web server, which I can restart in the same way as apache, for example.

Like service apache2 restart

Using your concept, I think it's possible to do the "stop" operation, at least. Could you clarify how can I, from the external environment, put the message to the server.Shutdown channel?

Thanks

lionelbarrow commented 10 years ago

You can use the os/signal package to catch external signals and relay them to your server:

c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)
go func() {
    <-c
    server.Shutdown <- true
}()
PavelPolyakov commented 10 years ago

Thanks,

That's a solution, but, as I found today the os.Kill signal, actually cannot be catched: https://groups.google.com/forum/#!topic/golang-nuts/t2u-RkKbJdU