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.

82 lines
2.0 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 routers
  5. import (
  6. "path"
  7. "strings"
  8. "code.gitea.io/git"
  9. "code.gitea.io/gitea/models"
  10. "code.gitea.io/gitea/modules/cron"
  11. "code.gitea.io/gitea/modules/log"
  12. "code.gitea.io/gitea/modules/mailer"
  13. "code.gitea.io/gitea/modules/markdown"
  14. "code.gitea.io/gitea/modules/setting"
  15. "code.gitea.io/gitea/modules/ssh"
  16. "code.gitea.io/gitea/modules/template/highlight"
  17. macaron "gopkg.in/macaron.v1"
  18. )
  19. func checkRunMode() {
  20. switch setting.Cfg.Section("").Key("RUN_MODE").String() {
  21. case "prod":
  22. macaron.Env = macaron.PROD
  23. macaron.ColorLog = false
  24. setting.ProdMode = true
  25. default:
  26. git.Debug = true
  27. }
  28. log.Info("Run Mode: %s", strings.Title(macaron.Env))
  29. }
  30. // NewServices init new services
  31. func NewServices() {
  32. setting.NewServices()
  33. mailer.NewContext()
  34. }
  35. // GlobalInit is for global configuration reload-able.
  36. func GlobalInit() {
  37. setting.NewContext()
  38. log.Trace("Custom path: %s", setting.CustomPath)
  39. log.Trace("Log path: %s", setting.LogRootPath)
  40. models.LoadConfigs()
  41. NewServices()
  42. if setting.InstallLock {
  43. highlight.NewContext()
  44. markdown.BuildSanitizer()
  45. if err := models.NewEngine(); err != nil {
  46. log.Fatal(4, "Fail to initialize ORM engine: %v", err)
  47. }
  48. models.HasEngine = true
  49. models.LoadRepoConfig()
  50. models.NewRepoContext()
  51. // Booting long running goroutines.
  52. cron.NewContext()
  53. models.InitSyncMirrors()
  54. models.InitDeliverHooks()
  55. models.InitTestPullRequests()
  56. log.NewGitLogger(path.Join(setting.LogRootPath, "http.log"))
  57. }
  58. if models.EnableSQLite3 {
  59. log.Info("SQLite3 Supported")
  60. }
  61. if models.EnableTiDB {
  62. log.Info("TiDB Supported")
  63. }
  64. if setting.SupportMiniWinService {
  65. log.Info("Builtin Windows Service Supported")
  66. }
  67. checkRunMode()
  68. if setting.InstallLock && setting.SSH.StartBuiltinServer {
  69. ssh.Listen(setting.SSH.ListenPort)
  70. log.Info("SSH server started on :%v", setting.SSH.ListenPort)
  71. }
  72. }