func Init() { // set default database dbConfig := g.Config().Database if g.Config().LogLevel == "debug" { orm.Debug = true } orm.RegisterDataBase("default", "mysql", dbConfig.Dsn, dbConfig.MaxIdle, dbConfig.MaxIdle) orm.RunSyncdb("default", false, true) }
func RefreshDesiredAgent() { d := time.Duration(g.Config().RefreshInterval) * time.Second for { refreshDesiredAgent() time.Sleep(d) } }
func main() { cfg := flag.String("c", "cfg.json", "configuration file") version := flag.Bool("v", false, "show version") flag.Parse() if *version { fmt.Println(g.VERSION) os.Exit(0) } if err := g.ParseConfig(*cfg); err != nil { log.Fatalln(err) } logger.SetLevelWithDefault(g.Config().LogLevel, "info") models.Init() db.Init() go store.RefreshDesiredAgent() go store.CleanStaleHost() addr := g.Config().Listen.Addr if "" == addr { addr = "127.0.0.1" } if 0 >= g.Config().Listen.Port { return } beego.BConfig.CopyRequestBody = true beego.BConfig.WebConfig.Session.SessionOn = true beego.BConfig.Listen.HTTPAddr = addr beego.BConfig.Listen.HTTPPort = g.Config().Listen.Port http.Start() }
func (this *ConfigController) Reload() { jsonResult := make(map[string]interface{}) if strings.HasPrefix(this.Ctx.Request.RemoteAddr, "127.0.0.1") { err := g.ParseConfig(g.ConfigFile) if nil == err { this.Data["json"] = g.Config() } else { jsonResult["message"] = err.Error() this.Data["json"] = &jsonResult } this.ServeJSON() } else { this.Ctx.WriteString("no privilege") } }