You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

web_graceful.go 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2016 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package cmd
  5. import (
  6. "crypto/tls"
  7. "net"
  8. "net/http"
  9. "net/http/fcgi"
  10. "code.gitea.io/gitea/modules/graceful"
  11. "code.gitea.io/gitea/modules/log"
  12. )
  13. func runHTTP(network, listenAddr string, m http.Handler) error {
  14. return graceful.HTTPListenAndServe(network, listenAddr, m)
  15. }
  16. func runHTTPS(network, listenAddr, certFile, keyFile string, m http.Handler) error {
  17. return graceful.HTTPListenAndServeTLS(network, listenAddr, certFile, keyFile, m)
  18. }
  19. func runHTTPSWithTLSConfig(network, listenAddr string, tlsConfig *tls.Config, m http.Handler) error {
  20. return graceful.HTTPListenAndServeTLSConfig(network, listenAddr, tlsConfig, m)
  21. }
  22. // NoHTTPRedirector tells our cleanup routine that we will not be using a fallback http redirector
  23. func NoHTTPRedirector() {
  24. graceful.GetManager().InformCleanup()
  25. }
  26. // NoMainListener tells our cleanup routine that we will not be using a possibly provided listener
  27. // for our main HTTP/HTTPS service
  28. func NoMainListener() {
  29. graceful.GetManager().InformCleanup()
  30. }
  31. // NoInstallListener tells our cleanup routine that we will not be using a possibly provided listener
  32. // for our install HTTP/HTTPS service
  33. func NoInstallListener() {
  34. graceful.GetManager().InformCleanup()
  35. }
  36. func runFCGI(network, listenAddr string, m http.Handler) error {
  37. // This needs to handle stdin as fcgi point
  38. fcgiServer := graceful.NewServer(network, listenAddr)
  39. err := fcgiServer.ListenAndServe(func(listener net.Listener) error {
  40. return fcgi.Serve(listener, m)
  41. })
  42. if err != nil {
  43. log.Fatal("Failed to start FCGI main server: %v", err)
  44. }
  45. log.Info("FCGI Listener: %s Closed", listenAddr)
  46. return err
  47. }