Пример #1
0
func (c *Conf) CheckConfigUpdate(notifyChans ...chan bool) {
	if c.proxyConfig.Global.ConfAutoload == 1 {
		for {
			//TODO sleep config by the config file
			time.Sleep(time.Second * 10)
			//log.Infof("CheckConfigUpdate checking")
			fileinfo, err := os.Stat(c.path)
			if err != nil {
				log.Errorf("CheckConfigUpdate error %s", err.Error())
				continue
			}
			if c.lastModifiedTime.Before(fileinfo.ModTime()) {
				log.Infof("CheckConfigUpdate config change and load new config")
				defaultProxyConfig := getDefaultProxyConfig()
				err = c.parseConfigFile(defaultProxyConfig)
				if err != nil {
					log.Errorf("CheckConfigUpdate error %s", err.Error())
					continue
				}
				c.lastModifiedTime = fileinfo.ModTime()
				//goroutine need mutex lock
				c.mu.Lock()
				c.proxyConfig = defaultProxyConfig
				c.mu.Unlock()
				//modify the log level when update
				log.SetLevel(log.LogLevel(conf.proxyConfig.Global.LogLevel))

				for _, notifyChan := range notifyChans {
					notifyChan <- true
				}
			}
		}

	}
}
Пример #2
0
func LoadConfig(path string) (*Conf, error) {
	fileinfo, err := os.Stat(path)
	if err != nil {
		return nil, err
	}
	conf.path = path
	defaultProxyConfig := getDefaultProxyConfig()
	err = conf.parseConfigFile(defaultProxyConfig)
	if err != nil {
		return nil, err
	}
	conf.lastModifiedTime = fileinfo.ModTime()
	conf.proxyConfig = defaultProxyConfig
	//set the log lever from base on conf
	log.SetLevel(log.LogLevel(conf.proxyConfig.Global.LogLevel))
	return &conf, err
}
Пример #3
0
func newTestServer() (*Server, error) {
	f := func() {

		path, err := tmpFile(testConfigData)
		if err != nil {
			testServer, testServerError = nil, err
			return
		}

		defer os.Remove(path) // clean up tmp file

		cfg, err := config.LoadConfig(path)
		if err != nil {
			testServer, testServerError = nil, err
			return
		}

		if err := cluster.Init(cfg); err != nil {
			testServer, testServerError = nil, err
			return
		}

		log.SetLevel(log.LogLevel(cfg.GetConfig().Global.LogLevel))
		mysql.SetLogger(log.Logger())

		testServer, err = NewServer(cfg)
		if err != nil {
			testServer, testServerError = nil, err
			return
		}

		go testServer.Serve()

		time.Sleep(1 * time.Second)
	}

	testServerOnce.Do(f)

	return testServer, testServerError
}