if ctx.IsSet("config") { | if ctx.IsSet("config") { | ||||
setting.CustomConf = ctx.String("config") | setting.CustomConf = ctx.String("config") | ||||
} | } | ||||
setting.NewConfigContext() | |||||
models.LoadModelsConfig() | |||||
setting.NewContext() | |||||
models.LoadConfigs() | |||||
models.SetEngine() | models.SetEngine() | ||||
log.Printf("Dumping local repositories...%s", setting.RepoRootPath) | log.Printf("Dumping local repositories...%s", setting.RepoRootPath) |
} | } | ||||
func setup(logPath string) { | func setup(logPath string) { | ||||
setting.NewConfigContext() | |||||
setting.NewContext() | |||||
log.NewGitLogger(filepath.Join(setting.LogRootPath, logPath)) | log.NewGitLogger(filepath.Join(setting.LogRootPath, logPath)) | ||||
if setting.DisableSSH { | if setting.DisableSSH { | ||||
os.Exit(1) | os.Exit(1) | ||||
} | } | ||||
models.LoadModelsConfig() | |||||
models.LoadConfigs() | |||||
if setting.UseSQLite3 { | |||||
if setting.UseSQLite3 || setting.UseTiDB { | |||||
workDir, _ := setting.WorkDir() | workDir, _ := setting.WorkDir() | ||||
os.Chdir(workDir) | os.Chdir(workDir) | ||||
} | } |
[mailer] | [mailer] | ||||
ENABLED = false | ENABLED = false | ||||
; Buffer length of channel, keep it as it is if you don't know what it is. | ; Buffer length of channel, keep it as it is if you don't know what it is. | ||||
SEND_BUFFER_LEN = 10 | |||||
SEND_BUFFER_LEN = 100 | |||||
; Name displayed in mail title | ; Name displayed in mail title | ||||
SUBJECT = %(APP_NAME)s | SUBJECT = %(APP_NAME)s | ||||
; Mail server | ; Mail server |
var c = cron.New() | var c = cron.New() | ||||
func NewCronContext() { | |||||
func NewContext() { | |||||
var ( | var ( | ||||
entry *cron.Entry | entry *cron.Entry | ||||
err error | err error |
} | } | ||||
} | } | ||||
func LoadModelsConfig() { | |||||
func LoadConfigs() { | |||||
sec := setting.Cfg.Section("database") | sec := setting.Cfg.Section("database") | ||||
DbCfg.Type = sec.Key("DB_TYPE").String() | DbCfg.Type = sec.Key("DB_TYPE").String() | ||||
switch DbCfg.Type { | switch DbCfg.Type { |
var mailQueue chan *Message | var mailQueue chan *Message | ||||
func NewMailerContext() { | |||||
mailQueue = make(chan *Message, setting.Cfg.Section("mailer").Key("SEND_BUFFER_LEN").MustInt(10)) | |||||
func NewContext() { | |||||
if setting.MailService == nil { | |||||
return | |||||
} | |||||
mailQueue = make(chan *Message, setting.MailService.QueueLength) | |||||
go processMailQueue() | go processMailQueue() | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// NewConfigContext initializes configuration context. | |||||
// NewContext initializes configuration context. | |||||
// NOTE: do not print any log except error. | // NOTE: do not print any log except error. | ||||
func NewConfigContext() { | |||||
func NewContext() { | |||||
workDir, err := WorkDir() | workDir, err := WorkDir() | ||||
if err != nil { | if err != nil { | ||||
log.Fatal(4, "Fail to get work directory: %v", err) | log.Fatal(4, "Fail to get work directory: %v", err) | ||||
// Mailer represents mail service. | // Mailer represents mail service. | ||||
type Mailer struct { | type Mailer struct { | ||||
QueueLength int | |||||
Name string | Name string | ||||
Host string | Host string | ||||
From string | From string | ||||
} | } | ||||
MailService = &Mailer{ | MailService = &Mailer{ | ||||
QueueLength: sec.Key("SEND_BUFFER_LEN").MustInt(100), | |||||
Name: sec.Key("NAME").MustString(AppName), | Name: sec.Key("NAME").MustString(AppName), | ||||
Host: sec.Key("HOST").String(), | Host: sec.Key("HOST").String(), | ||||
User: sec.Key("USER").String(), | User: sec.Key("USER").String(), |
// GlobalInit is for global configuration reload-able. | // GlobalInit is for global configuration reload-able. | ||||
func GlobalInit() { | func GlobalInit() { | ||||
setting.NewConfigContext() | |||||
setting.NewContext() | |||||
log.Trace("Custom path: %s", setting.CustomPath) | log.Trace("Custom path: %s", setting.CustomPath) | ||||
log.Trace("Log path: %s", setting.LogRootPath) | log.Trace("Log path: %s", setting.LogRootPath) | ||||
mailer.NewMailerContext() | |||||
models.LoadModelsConfig() | |||||
mailer.NewContext() | |||||
models.LoadConfigs() | |||||
NewServices() | NewServices() | ||||
if setting.InstallLock { | if setting.InstallLock { | ||||
} | } | ||||
models.HasEngine = true | models.HasEngine = true | ||||
cron.NewCronContext() | |||||
cron.NewContext() | |||||
models.InitDeliverHooks() | models.InitDeliverHooks() | ||||
log.NewGitLogger(path.Join(setting.LogRootPath, "http.log")) | log.NewGitLogger(path.Join(setting.LogRootPath, "http.log")) | ||||
} | } |