|
@@ -11,19 +11,22 @@ import (
|
|
|
"github.com/Sirupsen/logrus"
|
|
|
"github.com/coreos/go-systemd/activation"
|
|
|
"github.com/docker/go-connections/sockets"
|
|
|
- "github.com/docker/libnetwork/portallocator"
|
|
|
)
|
|
|
|
|
|
// Init creates new listeners for the server.
|
|
|
-func Init(proto, addr, socketGroup string, tlsConfig *tls.Config) (ls []net.Listener, err error) {
|
|
|
+// 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":
|
|
|
- ls, err = listenFD(addr, tlsConfig)
|
|
|
+ fds, err := listenFD(addr, tlsConfig)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
+ ls = append(ls, fds...)
|
|
|
case "tcp":
|
|
|
- l, err := initTCPSocket(addr, tlsConfig)
|
|
|
+ l, err := sockets.NewTCPSocket(addr, tlsConfig)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -38,7 +41,7 @@ func Init(proto, addr, socketGroup string, tlsConfig *tls.Config) (ls []net.List
|
|
|
return nil, fmt.Errorf("invalid protocol format: %q", proto)
|
|
|
}
|
|
|
|
|
|
- return
|
|
|
+ return ls, nil
|
|
|
}
|
|
|
|
|
|
// listenFD returns the specified socket activated files as a slice of
|
|
@@ -89,34 +92,3 @@ func listenFD(addr string, tlsConfig *tls.Config) ([]net.Listener, error) {
|
|
|
}
|
|
|
return []net.Listener{listeners[fdOffset]}, nil
|
|
|
}
|
|
|
-
|
|
|
-// allocateDaemonPort ensures that there are no containers
|
|
|
-// that try to use any port allocated for the docker server.
|
|
|
-// TODO: Move this outside pkg/listeners since it's Docker-specific, and requires
|
|
|
-// libnetwork which increases the dependency tree quite drastically.
|
|
|
-func allocateDaemonPort(addr string) error {
|
|
|
- host, port, err := net.SplitHostPort(addr)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
-
|
|
|
- intPort, err := strconv.Atoi(port)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
-
|
|
|
- var hostIPs []net.IP
|
|
|
- if parsedIP := net.ParseIP(host); parsedIP != nil {
|
|
|
- hostIPs = append(hostIPs, parsedIP)
|
|
|
- } else if hostIPs, err = net.LookupIP(host); err != nil {
|
|
|
- return fmt.Errorf("failed to lookup %s address in host specification", host)
|
|
|
- }
|
|
|
-
|
|
|
- pa := portallocator.Get()
|
|
|
- for _, hostIP := range hostIPs {
|
|
|
- if _, err := pa.RequestPort(hostIP, "tcp", intPort); err != nil {
|
|
|
- return fmt.Errorf("failed to allocate daemon listening port %d (err: %v)", intPort, err)
|
|
|
- }
|
|
|
- }
|
|
|
- return nil
|
|
|
-}
|