summaryrefslogtreecommitdiffstats
path: root/cmd/web.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2016-12-31 09:00:33 +0800
committerGitHub <noreply@github.com>2016-12-31 09:00:33 +0800
commit527c2dd6651bc7beed12acd48b22ac69c0bf337e (patch)
treeaf8ddc6ea8c23e5b88f47ad15fd016686f3c213b /cmd/web.go
parentfa60cf0ea422e3a7ae75dd689485f75acb1b3110 (diff)
downloadgitea-527c2dd6651bc7beed12acd48b22ac69c0bf337e.tar.gz
gitea-527c2dd6651bc7beed12acd48b22ac69c0bf337e.zip
Support http service graceful restart (#416)
* support http service graceful restart * fix dependencies
Diffstat (limited to 'cmd/web.go')
-rw-r--r--cmd/web.go26
1 files changed, 23 insertions, 3 deletions
diff --git a/cmd/web.go b/cmd/web.go
index 7dfd19d640..ecaf74daaa 100644
--- a/cmd/web.go
+++ b/cmd/web.go
@@ -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"
@@ -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: