コード例 #1
0
// Init creates new listeners for the server.
// TODO: Clean up the fact that socketGroup and tlsConfig aren't always used.
func Init(proto, addr, socketGroup string, tlsConfig *tls.Config) ([]net.Listener, error) {
	ls := []net.Listener{}

	switch proto {
	case "fd":
		fds, err := listenFD(addr, tlsConfig)
		if err != nil {
			return nil, err
		}
		ls = append(ls, fds...)
	case "tcp":
		l, err := sockets.NewTCPSocket(addr, tlsConfig)
		if err != nil {
			return nil, err
		}
		ls = append(ls, l)
	case "unix":
		l, err := sockets.NewUnixSocket(addr, socketGroup)
		if err != nil {
			return nil, fmt.Errorf("can't create unix socket %s: %v", addr, err)
		}
		ls = append(ls, l)
	default:
		return nil, fmt.Errorf("invalid protocol format: %q", proto)
	}

	return ls, nil
}
コード例 #2
0
ファイル: horcrux-dv.go プロジェクト: muthu-r/horcrux
func main() {
	log.SetLevel(horcrux.LOGLEVEL)

	err := os.MkdirAll(DV_SOCK_PATH, 0700)

	VolData.volFileName = DV_WORKDIR + "/" + DV_VOL_LIST_FILE

	VolData.Volumes = make(map[string]Volume, DV_VOL_MIN)
	err = readVols()
	if err != nil {
		log.Errorf("Cannot read volume list - %v", err)
		log.Errorf("Continuing...")
	}

	defer storeVols()

	http.HandleFunc(activateEndPoint, ActivateHandler)
	for i := 0; i < len(Handles); i++ {
		Handler := Handles[i].Handler
		http.HandleFunc(Handles[i].EndPoint, func(w http.ResponseWriter, r *http.Request) {
			req, err := getDockerRequest(w, r)
			_ = req
			if err != nil {
				log.Errorf("Cannot get docker request - err %v", err)
				return
			}
			resp := Handler(req)
			if resp != nil {
				putDockerResponse(w, resp)
			}
			return
		})
	}

	handleSignals()

	//	log.WithFields(log.Fields{"Host": DV_HOST, "Port": DV_TCP_PORT}).Info("Listening...")

	log.WithFields(log.Fields{"Socket": DV_SOCK_NAME}).Info("Listening...")
	listener, err := sockets.NewUnixSocket(DV_SOCK_NAME, "docker")
	if err != nil {
		log.Errorf("dv: Cannot create unix socket %v, err %v", DV_SOCK_NAME, err)
		return
	}
	defer os.Remove(DV_SOCK_NAME)

	err = http.Serve(listener, nil)
	if err != nil {
		log.Errorf("dv: Cannot Serve on unix socket, err %v", err)
		return
	}

	//	err = http.ListenAndServe(DV_HOST+":"+DV_TCP_PORT, nil)
	//	if err != nil {
	//		log.Errorf("dv: http server error %v", err)
	//	}
	//

	return
}
コード例 #3
0
func newUnixListener(pluginName string, group string) (net.Listener, string, error) {
	path, err := fullSocketAddress(pluginName)
	if err != nil {
		return nil, "", err
	}
	listener, err := sockets.NewUnixSocket(path, group)
	if err != nil {
		return nil, "", err
	}
	return listener, path, nil
}
コード例 #4
0
ファイル: unix_listener.go プロジェクト: xytis/polyp
func newUnixListener(pluginName string, group string) (net.Listener, string, error) {
	path, err := fullSocketAddress(pluginName)
	if err != nil {
		return nil, "", err
	}
	listenFds := activation.Files(false)
	if len(listenFds) > 1 {
		return nil, "", fmt.Errorf("expected only one socket from systemd, got %d", len(listenFds))
	}
	if len(listenFds) == 1 {
		l, err := net.FileListener(listenFds[0])
		if err != nil {
			return nil, "", err
		}
		return l, path, nil
	}
	listener, err := sockets.NewUnixSocket(path, group)
	if err != nil {
		return nil, "", err
	}
	return listener, path, nil
}
コード例 #5
0
ファイル: server_unix.go プロジェクト: DaveDaCoda/docker
// newServer sets up the required HTTPServers and does protocol specific checking.
// newServer does not set any muxers, you should set it later to Handler field
func (s *Server) newServer(proto, addr string) ([]*HTTPServer, error) {
	var (
		err error
		ls  []net.Listener
	)
	switch proto {
	case "fd":
		ls, err = listenFD(addr, s.cfg.TLSConfig)
		if err != nil {
			return nil, err
		}
	case "tcp":
		l, err := s.initTCPSocket(addr)
		if err != nil {
			return nil, err
		}
		ls = append(ls, l)
	case "unix":
		l, err := sockets.NewUnixSocket(addr, s.cfg.SocketGroup)
		if err != nil {
			return nil, fmt.Errorf("can't create unix socket %s: %v", addr, err)
		}
		ls = append(ls, l)
	default:
		return nil, fmt.Errorf("Invalid protocol format: %q", proto)
	}
	var res []*HTTPServer
	for _, l := range ls {
		res = append(res, &HTTPServer{
			&http.Server{
				Addr: addr,
			},
			l,
		})
	}
	return res, nil
}