예제 #1
0
파일: listen.go 프로젝트: ycaihua/fabio
// startListeners runs one or more listeners for the handler
func startListeners(listen []config.Listen, wait time.Duration, h http.Handler) {
	for _, l := range listen {
		go listenAndServe(l, h)
	}

	// wait for shutdown signal
	<-quit

	// disable routing for all requests
	proxy.Shutdown()

	// trigger graceful shutdown
	log.Printf("[INFO] Graceful shutdown over %s", wait)
	time.Sleep(wait)
	log.Print("[INFO] Down")
}
예제 #2
0
파일: listen.go 프로젝트: hilerchyn/fabio
/*
  listen = "Listen": [
        {
            "Addr": ":9999",
            "Proto": "http",
            "ReadTimeout": 0,
            "WriteTimeout": 0,
            "CertSource": {
                "Name": "",
                "Type": "",
                "CertPath": "",
                "KeyPath": "",
                "ClientCAPath": "",
                "CAUpgradeCN": "",
                "Refresh": 0,
                "Header": null
            },
            "StrictMatch": false
        }
    ],
 通过配置信息中的 Listen 来启动不同的监听服务,根据 上面的 Proto 来启动不懂的服务器, Proto 可用的参数有 http, https, tcp+sni
*/
func startListeners(listen []config.Listen, wait time.Duration, h http.Handler, tcph proxy.TCPProxy) {
	for _, l := range listen {
		switch l.Proto {
		case "tcp+sni":
			go listenAndServeTCP(l, tcph)
		case "http", "https":
			go listenAndServeHTTP(l, h)
		default:
			panic("invalid protocol: " + l.Proto)
		}
	}

	// wait for shutdown signal
	<-quit

	// disable routing for all requests
	proxy.Shutdown()

	// trigger graceful shutdown
	log.Printf("[INFO] Graceful shutdown over %s", wait)
	time.Sleep(wait)
	log.Print("[INFO] Down")
}