Exemplo n.º 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()
}
Exemplo n.º 2
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)

}