Пример #1
0
func main() {

	runtime.GOMAXPROCS(runtime.NumCPU())

	flag.Parse()

	if len(*configFile) == 0 {
		log.Fatal("must use a config file")
		os.Exit(1)
	}

	cfg, err := config.LoadConfig(*configFile)
	if err != nil {
		log.Fatal(err.Error())
		os.Exit(1)
	}

	if err = cluster.Init(cfg); err != nil {
		log.Fatal(err.Error())
		os.Exit(1)
	}

	mysql.SetLogger(log.Logger())

	sc := make(chan os.Signal, 1)
	signal.Notify(sc,
		syscall.SIGHUP,
		syscall.SIGINT,
		syscall.SIGTERM,
		syscall.SIGQUIT)

	var svr *proxy.Server
	svr, err = proxy.NewServer(cfg)
	if err != nil {
		log.Fatal(err.Error())
		os.Exit(1)
	}

	go func() {
		http.ListenAndServe(":11888", nil)
	}()

	go func() {
		sig := <-sc
		log.Infof("Got signal [%d] to exit.", sig)
		svr.Close()
	}()

	svr.Serve()
}
Пример #2
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
}
Пример #3
0
func main() {

	runtime.GOMAXPROCS(runtime.NumCPU())
	runtime.SetBlockProfileRate(1)
	os.Setenv("GOGC", "100")
	log.SetOutputByName(*logFile)
	flag.Parse() //parse tue input argument
	println(*logFile)
	println(*configFile)

	if len(*configFile) == 0 {
		log.Fatal("must use a config file")
		os.Exit(1)
	}

	cfg, err := config.LoadConfig(*configFile)
	if err != nil {
		log.Fatal(err.Error())
		os.Exit(1)
	}

	if err = cluster.Init(cfg); err != nil {
		log.Fatal(err.Error())
		os.Exit(1)
	}

	mysql.SetLogger(log.Logger())

	go func() {
		err := cluster.DisasterControl()
		if err != nil {
			log.Warn(err)
		}
	}()
	go func() {
		// log.info("start checking config file")
		cfg.CheckConfigUpdate(cluster.NotifyChan)
	}()

	sc := make(chan os.Signal, 1)
	Restart := make(chan os.Signal, 1)
	signal.Notify(Restart, syscall.SIGUSR1)
	signal.Notify(sc, syscall.SIGQUIT,
		syscall.SIGHUP,
		syscall.SIGINT,
		syscall.SIGTERM)

	var svr *proxy.Server
	svr, err = proxy.NewServer(cfg)
	if err != nil {
		log.Fatal(err.Error())
		os.Exit(1)
	}

	//port for go pprof Debug
	go func() {
		http.ListenAndServe(":11888", nil)
	}()

	go func() {
		select {
		case sig := <-sc:
			log.Infof("Got signal [%d] to exit.", sig)
			svr.Close()
		case sig := <-Restart:
			log.Infof("Got signal [%d] to Restart.", sig)
			svr.Restart()
		}
	}()

	svr.Serve()
	os.Exit(0)

}