|
|
@ -7,6 +7,7 @@ package routers |
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"path" |
|
|
|
"path" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
"code.gitea.io/git" |
|
|
|
"code.gitea.io/git" |
|
|
|
"code.gitea.io/gitea/models" |
|
|
|
"code.gitea.io/gitea/models" |
|
|
@ -42,6 +43,24 @@ func NewServices() { |
|
|
|
cache.NewContext() |
|
|
|
cache.NewContext() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// In case of problems connecting to DB, retry connection. Eg, PGSQL in Docker Container on Synology
|
|
|
|
|
|
|
|
func initDBEngine() (err error) { |
|
|
|
|
|
|
|
log.Info("Beginning ORM engine initialization.") |
|
|
|
|
|
|
|
for i := 0; i < setting.DBConnectRetries; i++ { |
|
|
|
|
|
|
|
log.Info("ORM engine initialization attempt #%d/%d...", i+1, setting.DBConnectRetries) |
|
|
|
|
|
|
|
if err := models.NewEngine(migrations.Migrate); err == nil { |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
} else if i == setting.DBConnectRetries-1 { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
log.Debug("ORM engine initialization attempt #%d/%d failed. Error: %v", i+1, setting.DBConnectRetries, err) |
|
|
|
|
|
|
|
log.Info("Backing off for %d seconds", int64(setting.DBConnectBackoff/time.Second)) |
|
|
|
|
|
|
|
time.Sleep(setting.DBConnectBackoff) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
models.HasEngine = true |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GlobalInit is for global configuration reload-able.
|
|
|
|
// GlobalInit is for global configuration reload-able.
|
|
|
|
func GlobalInit() { |
|
|
|
func GlobalInit() { |
|
|
|
setting.NewContext() |
|
|
|
setting.NewContext() |
|
|
@ -56,11 +75,12 @@ func GlobalInit() { |
|
|
|
if setting.InstallLock { |
|
|
|
if setting.InstallLock { |
|
|
|
highlight.NewContext() |
|
|
|
highlight.NewContext() |
|
|
|
markup.Init() |
|
|
|
markup.Init() |
|
|
|
|
|
|
|
if err := initDBEngine(); err == nil { |
|
|
|
if err := models.NewEngine(migrations.Migrate); err != nil { |
|
|
|
log.Info("ORM engine initialization successful!") |
|
|
|
log.Fatal(4, "Failed to initialize ORM engine: %v", err) |
|
|
|
} else { |
|
|
|
|
|
|
|
log.Fatal(4, "ORM engine initialization failed: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
models.HasEngine = true |
|
|
|
|
|
|
|
if err := models.InitOAuth2(); err != nil { |
|
|
|
if err := models.InitOAuth2(); err != nil { |
|
|
|
log.Fatal(4, "Failed to initialize OAuth2 support: %v", err) |
|
|
|
log.Fatal(4, "Failed to initialize OAuth2 support: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|