Skip to content

Commit

Permalink
Support http service graceful restart (#416)
Browse files Browse the repository at this point in the history
* support http service graceful restart

* fix dependencies
  • Loading branch information
lunny authored Dec 31, 2016
1 parent fa60cf0 commit 527c2dd
Show file tree
Hide file tree
Showing 20 changed files with 1,919 additions and 3 deletions.
26 changes: 23 additions & 3 deletions cmd/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"code.gitea.io/gitea/routers/repo"
"code.gitea.io/gitea/routers/user"

"github.com/facebookgo/grace/gracehttp"
"github.com/go-macaron/binding"
"github.com/go-macaron/cache"
"github.com/go-macaron/captcha"
Expand Down Expand Up @@ -615,10 +616,29 @@ func runWeb(ctx *cli.Context) error {
var err error
switch setting.Protocol {
case setting.HTTP:
err = http.ListenAndServe(listenAddr, m)
err = gracehttp.Serve(&http.Server{
Addr: listenAddr,
Handler: m,
})
case setting.HTTPS:
server := &http.Server{Addr: listenAddr, TLSConfig: &tls.Config{MinVersion: tls.VersionTLS10}, Handler: m}
err = server.ListenAndServeTLS(setting.CertFile, setting.KeyFile)
config := &tls.Config{
MinVersion: tls.VersionTLS10,
}
if config.NextProtos == nil {
config.NextProtos = []string{"http/1.1"}
}

config.Certificates = make([]tls.Certificate, 1)
config.Certificates[0], err = tls.LoadX509KeyPair(setting.CertFile, setting.KeyFile)
if err != nil {
log.Fatal(4, "Failed to load https cert file %s: %v", listenAddr, err)
}

err = gracehttp.Serve(&http.Server{
Addr: listenAddr,
Handler: m,
TLSConfig: config,
})
case setting.FCGI:
err = fcgi.Serve(nil, m)
case setting.UnixSocket:
Expand Down
21 changes: 21 additions & 0 deletions vendor/github.com/facebookgo/clock/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 104 additions & 0 deletions vendor/github.com/facebookgo/clock/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 527c2dd

Please sign in to comment.