Example #1
0
func main() {
	var filename string
	var v bool
	flag.StringVar(&filename, "cfg", "", "path to config file")
	flag.BoolVar(&v, "v", false, "show version")
	flag.Parse()

	if v {
		fmt.Println(version)
		return
	}

	cfg, err := config.Load(filename)
	if err != nil {
		log.Fatalf("[FATAL] %s. %s", version, err)
	}

	log.Printf("[INFO] Runtime config\n" + toJSON(cfg))
	log.Printf("[INFO] Version %s starting", version)
	log.Printf("[INFO] Go runtime is %s", runtime.Version())

	initRuntime(cfg)
	initMetrics(cfg)
	initBackend(cfg)
	go watchBackend()
	startAdmin(cfg)
	startListeners(cfg.Listen, cfg.Proxy.ShutdownWait, newProxy(cfg))
	registry.Default.Deregister()
}
Example #2
0
File: main.go Project: eBay/fabio
func main() {
	cfg, err := config.Load(os.Args, os.Environ())
	if err != nil {
		exit.Fatalf("[FATAL] %s. %s", version, err)
	}
	if cfg == nil {
		fmt.Println(version)
		return
	}

	log.Printf("[INFO] Runtime config\n" + toJSON(cfg))
	log.Printf("[INFO] Version %s starting", version)
	log.Printf("[INFO] Go runtime is %s", runtime.Version())

	exit.Listen(func(s os.Signal) {
		if registry.Default == nil {
			return
		}
		registry.Default.Deregister()
	})

	httpProxy := newHTTPProxy(cfg)
	tcpProxy := proxy.NewTCPSNIProxy(cfg.Proxy)

	initRuntime(cfg)
	initMetrics(cfg)
	initBackend(cfg)
	go watchBackend()
	startAdmin(cfg)
	startListeners(cfg.Listen, cfg.Proxy.ShutdownWait, httpProxy, tcpProxy)
	exit.Wait()
}
Example #3
0
func main() {
	cfg, err := config.Load()
	if err != nil {
		log.Fatalf("[FATAL] %s. %s", version, err)
	}
	if cfg == nil {
		fmt.Println(version)
		return
	}

	log.Printf("[INFO] Runtime config\n" + toJSON(cfg))
	log.Printf("[INFO] Version %s starting", version)
	log.Printf("[INFO] Go runtime is %s", runtime.Version())

	initRuntime(cfg)
	initMetrics(cfg)
	initBackend(cfg)
	go watchBackend()
	startAdmin(cfg)
	startListeners(cfg.Listen, cfg.Proxy.ShutdownWait, newProxy(cfg))
	registry.Default.Deregister()
}
Example #4
0
func main() {
	// 从配置文件中获取全局配置,并赋值给配置变量
	cfg, err := config.Load()
	if err != nil {
		exit.Fatalf("[FATAL] %s. %s", version, err)
	}
	if cfg == nil {
		fmt.Println(version)
		return
	}

	// 打印启动信息
	log.Printf("[INFO] Runtime config\n" + toJSON(cfg))
	log.Printf("[INFO] Version %s starting", version)
	log.Printf("[INFO] Go runtime is %s", runtime.Version())

	// 加上程序退出监听goroutine
	exit.Listen(func(s os.Signal) {
		if registry.Default == nil {
			return
		}
		// 从fabio移除服务注册信息
		registry.Default.Deregister()
	})

	// Proxy
	/*
		"Proxy": {
			"Strategy": "rnd",
			"Matcher": "prefix",
			"NoRouteStatus": 404,
			"MaxConn": 10000,
			"ShutdownWait": 0,
			"DialTimeout": 30000000000,
			"ResponseHeaderTimeout": 0,
			"KeepAliveTimeout": 0,
			"ReadTimeout": 0,
			"WriteTimeout": 0,
			"FlushInterval": 1000000000,
			"LocalIP": "192.168.3.101",
			"ClientIPHeader": "",
			"TLSHeader": "",
			"TLSHeaderValue": "",
			"GZIPContentTypesValue": "",
			"GZIPContentTypes": null
		    },

	*/

	// 创建HTTP代理的句柄
	httpProxy := newHTTPProxy(cfg)
	// @todo 了解业务流程
	// SNI 即 Server Name Indication 是用来改善
	// SSL(Secure Socket Layer)和TLS(Transport Layer Security)的一项特性。
	// 它允许客户端在服务器端向其发送证书之前请求服务器的域名。这对于在虚拟主机模式使用TLS是必要的。
	//
	// 即提供 HTTPS 服务, 返回 tcpSNIProxy 结构体
	tcpProxy := proxy.NewTCPSNIProxy(cfg.Proxy)

	// 初始化运行时
	/*
		"Runtime": {
			"GOGC": 800,
			"GOMAXPROCS": 4
		    },

	*/
	initRuntime(cfg)
	// 设置Metrics监控系统的配置信息,以及路由的服务注册信息
	/*
		"Metrics": {
			"Target": "",
			"Prefix": "{{clean .Hostname}}.{{clean .Exec}}",
			"Names": "{{clean .Service}}.{{clean .Host}}.{{clean .Path}}.{{clean .TargetURL.Host}}",
			"Interval": 30000000000,
			"GraphiteAddr": "",
			"StatsDAddr": "",
			"CirconusAPIKey": "",
			"CirconusAPIApp": "fabio",
			"CirconusAPIURL": "",
			"CirconusCheckID": "",
			"CirconusBrokerID": ""
		    },
	*/
	initMetrics(cfg)
	/*
		 "Registry": {
			"Backend": "consul",
			"Static": {
			    "Routes": ""
			},
			"File": {
			    "Path": ""
			},
			"Consul": {
			    "Addr": "localhost:8500",
			    "Scheme": "http",
			    "Token": "",
			    "KVPath": "/fabio/config",
			    "TagPrefix": "urlprefix-",
			    "Register": true,
			    "ServiceAddr": ":9998",
			    "ServiceName": "fabio",
			    "ServiceTags": null,
			    "ServiceStatus": [
				"passing"
			    ],
			    "CheckInterval": 1000000000,
			    "CheckTimeout": 3000000000
			}
		    },

	*/
	// 初始化注册服务的后端配置信息
	initBackend(cfg)
	// 启动后端监听服务器
	go watchBackend()

	/*
		"UI": {
			"Addr": ":9998",
			"Color": "light-green",
			"Title": ""
		    },
	*/
	// 启动管理界面
	startAdmin(cfg)

	/*
			"Listen": [
		        {
		            "Addr": ":9999",
		            "Proto": "http",
		            "ReadTimeout": 0,
		            "WriteTimeout": 0,
		            "CertSource": {
		                "Name": "",
		                "Type": "",
		                "CertPath": "",
		                "KeyPath": "",
		                "ClientCAPath": "",
		                "CAUpgradeCN": "",
		                "Refresh": 0,
		                "Header": null
		            },
		            "StrictMatch": false
		        }
		    ],

	*/
	// 启动监听,开启服务器 @todo 了解业务流程
	startListeners(cfg.Listen, cfg.Proxy.ShutdownWait, httpProxy, tcpProxy)

	//等待退出
	exit.Wait()
}