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.

52 lines
1.5 KiB

  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. func runFCGI(network, listenAddr string, m http.Handler) error {
  32. // This needs to handle stdin as fcgi point
  33. fcgiServer := graceful.NewServer(network, listenAddr)
  34. err := fcgiServer.ListenAndServe(func(listener net.Listener) error {
  35. return fcgi.Serve(listener, m)
  36. })
  37. if err != nil {
  38. log.Fatal("Failed to start FCGI main server: %v", err)
  39. }
  40. log.Info("FCGI Listener: %s Closed", listenAddr)
  41. return err
  42. }