示例#1
0
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)
}
示例#2
0
func RefreshDesiredAgent() {
	d := time.Duration(g.Config().RefreshInterval) * time.Second
	for {
		refreshDesiredAgent()
		time.Sleep(d)
	}
}
示例#3
0
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()
}
示例#4
0
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")
	}
}