Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service + httpserver + graceful shutdown #59

Open
dryaf opened this issue Apr 7, 2016 · 3 comments
Open

service + httpserver + graceful shutdown #59

dryaf opened this issue Apr 7, 2016 · 3 comments

Comments

@dryaf
Copy link

dryaf commented Apr 7, 2016

Hi,

I'd like to use "service" with my webservice.
I use https://github.com/facebookgo/grace for graceful shutdown.
-> server waits until connections are closed so no data gets lost.

This only works when I change your code to not being async.

// Program structures.
//  Define Start and Stop methods.
type program struct {

}

func (p *program) Start(s service.Service) error {
        //go p.run()
    //return nil
    return gracehttp.Serve(e.Routes().Server("0.0.0.0:3000"))
}

func (p *program) Stop(s service.Service) error {
    // Any work in Stop should be quick, usually a few seconds at most.
    logger.Info("I'm Stopping!")
    return nil
}

Does it have to be async? Will I have problems using "service"?

best
ps: govendor is great! Saved my sanity today :)

@dryaf dryaf changed the title server + httpserver + graceful shutdown service + httpserver + graceful shutdown Apr 7, 2016
@kardianos
Copy link
Owner

I integrated something similar for a PR for Caddy. However I've never looked closely at facebook's grace. It might be possible to integrate, but I'll need to look into how grace works. Feel free to also describe how it works too.

@kardianos
Copy link
Owner

I don't have time today to look into this, but you may be instersted in the Caddy patch which supported a hot reload: caddyserver/caddy#588

@dryaf
Copy link
Author

dryaf commented Apr 11, 2016

Well I tested the code I posted here. And the gracefull shutdown works. Though maybe not being async in your code isn't a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants