예제 #1
0
func zoneproxy(v *viper.Viper, dp *dialer.DialerPool) {
	var wg sync.WaitGroup

	zones := v.GetStringMap("zones")
	dp.AddByZones(zones)

	tcpproxys := v.GetStringMap("tcpproxys")
	for name, _ := range tcpproxys {
		address := v.GetString("tcpproxys." + name + ".address")
		if address == "" {
			glog.Fatalln("tcpproxys." + name + ".address must be string")
		}
		tp := tcpproxy.NewTcpProxy(name, address, dp, v)
		wg.Add(1)
		go func() {
			tp.Run()
			wg.Done()
		}()
	}

	httpproxys := v.GetStringMap("httpproxys")
	for name, _ := range httpproxys {
		address := v.GetString("httpproxys." + name + ".address")
		if address == "" {
			glog.Fatalln("httpproxys." + name + ".address must be string")
		}
		hp := httpproxy.NewHttpProxy(name, address, dp, v)
		wg.Add(1)
		go func() {
			hp.Run()
			wg.Done()
		}()
	}

	httpservers := v.GetStringMap("httpservers")
	for name, _ := range httpservers {
		address := v.GetString("httpservers." + name + ".address")
		if address == "" {
			glog.Fatalln("httpservers." + name + ".address must be string")
		}
		hs := httpserver.NewHttpServer(name, address, dp, v)
		wg.Add(1)
		go func() {
			hs.Run()
			wg.Done()
		}()
	}

	wg.Wait()
	glog.Flush()
}
예제 #2
0
func singalhandler(sig os.Signal, v *viper.Viper, dp *dialer.DialerPool) error {
	switch sig {
	case syscall.SIGHUP:
		log.Println("HUP")
		glog.Infof("got hup signal, now reloading conf\n", sig.String())
		err := v.ReadInConfig()
		if err != nil {
			glog.Infoln("Fatal error config file ", err)
			return utils.ErrReadConfig
		}
		zones := v.GetStringMap("zones")
		dp.AddByZones(zones)
	case syscall.SIGTERM:
		glog.Infoln("receive SIGTERM, exit")
		//maybe graceful stop is better:)
		os.Exit(0)
	default:
		log.Println(sig)
		glog.Infoln("not ready to process ", sig.String())
	}

	return nil
}