Skip to content

Commit

Permalink
support http service graceful restart
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Dec 30, 2016
1 parent 42904cb commit 3bbbab3
Show file tree
Hide file tree
Showing 5 changed files with 278 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
186 changes: 186 additions & 0 deletions vendor/github.com/facebookgo/grace/gracehttp/http.go

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

30 changes: 30 additions & 0 deletions vendor/github.com/facebookgo/grace/license

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

33 changes: 33 additions & 0 deletions vendor/github.com/facebookgo/grace/patents

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

6 changes: 6 additions & 0 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@
"revision": "57eb5e1fc594ad4b0b1dbea7b286d299e0cb43c2",
"revisionTime": "2015-12-24T04:54:52Z"
},
{
"checksumSHA1": "al8G84fPO2HjlLiCGyZZqBVDTI0=",
"path": "github.com/facebookgo/grace/gracehttp",
"revision": "053ab5d25436faedf3fe76fbf3da797c8c27c659",
"revisionTime": "2015-08-07T21:49:31Z"
},
{
"checksumSHA1": "qTJizMr1DBhDTZiRNmC+khEClz8=",
"path": "github.com/go-macaron/bindata",
Expand Down

0 comments on commit 3bbbab3

Please sign in to comment.