Graceful: Allow graceful restart for fcgi (#9112)
* Graceful: Allow graceful restart for fcgi My previous interpretation was incorrect - we do not handle sockets being passed in over stdin * Update web.gorelease/v1.15
parent
d779deef6e
commit
7523314ef8
17
cmd/web.go
17
cmd/web.go
|
@ -6,9 +6,7 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/fcgi"
|
|
||||||
_ "net/http/pprof" // Used for debugging if enabled and a web server is running
|
_ "net/http/pprof" // Used for debugging if enabled and a web server is running
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -185,20 +183,7 @@ func runWeb(ctx *cli.Context) error {
|
||||||
err = runHTTPS("tcp", listenAddr, setting.CertFile, setting.KeyFile, context2.ClearHandler(m))
|
err = runHTTPS("tcp", listenAddr, setting.CertFile, setting.KeyFile, context2.ClearHandler(m))
|
||||||
case setting.FCGI:
|
case setting.FCGI:
|
||||||
NoHTTPRedirector()
|
NoHTTPRedirector()
|
||||||
// FCGI listeners are provided as stdin - this is orthogonal to the LISTEN_FDS approach
|
err = runFCGI(listenAddr, context2.ClearHandler(m))
|
||||||
// in graceful and systemD
|
|
||||||
NoMainListener()
|
|
||||||
var listener net.Listener
|
|
||||||
listener, err = net.Listen("tcp", listenAddr)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Failed to bind %s: %v", listenAddr, err)
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
if err := listener.Close(); err != nil {
|
|
||||||
log.Fatal("Failed to stop server: %v", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
err = fcgi.Serve(listener, context2.ClearHandler(m))
|
|
||||||
case setting.UnixSocket:
|
case setting.UnixSocket:
|
||||||
NoHTTPRedirector()
|
NoHTTPRedirector()
|
||||||
err = runHTTP("unix", listenAddr, context2.ClearHandler(m))
|
err = runHTTP("unix", listenAddr, context2.ClearHandler(m))
|
||||||
|
|
|
@ -6,9 +6,12 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/fcgi"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/graceful"
|
"code.gitea.io/gitea/modules/graceful"
|
||||||
|
"code.gitea.io/gitea/modules/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func runHTTP(network, listenAddr string, m http.Handler) error {
|
func runHTTP(network, listenAddr string, m http.Handler) error {
|
||||||
|
@ -33,3 +36,17 @@ func NoHTTPRedirector() {
|
||||||
func NoMainListener() {
|
func NoMainListener() {
|
||||||
graceful.Manager.InformCleanup()
|
graceful.Manager.InformCleanup()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func runFCGI(listenAddr string, m http.Handler) error {
|
||||||
|
// This needs to handle stdin as fcgi point
|
||||||
|
fcgiServer := graceful.NewServer("tcp", listenAddr)
|
||||||
|
|
||||||
|
err := fcgiServer.ListenAndServe(func(listener net.Listener) error {
|
||||||
|
return fcgi.Serve(listener, m)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Failed to start FCGI main server: %v", err)
|
||||||
|
}
|
||||||
|
log.Info("FCGI Listener: %s Closed", listenAddr)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue