mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #13559 from LK4D4/fix_systemd_listen
Treat systemd listeners as all other
This commit is contained in:
commit
1f22676fcb
2 changed files with 30 additions and 37 deletions
|
@ -96,15 +96,17 @@ func (s *Server) ServeApi(protoAddrs []string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.servers = append(s.servers, srv)
|
s.servers = append(s.servers, srv...)
|
||||||
|
|
||||||
go func(proto, addr string) {
|
for _, s := range srv {
|
||||||
logrus.Infof("Listening for HTTP on %s (%s)", proto, addr)
|
logrus.Infof("Listening for HTTP on %s (%s)", protoAddrParts[0], protoAddrParts[1])
|
||||||
if err := srv.Serve(); err != nil && strings.Contains(err.Error(), "use of closed network connection") {
|
go func(s serverCloser) {
|
||||||
|
if err := s.Serve(); err != nil && strings.Contains(err.Error(), "use of closed network connection") {
|
||||||
err = nil
|
err = nil
|
||||||
}
|
}
|
||||||
chErrors <- err
|
chErrors <- err
|
||||||
}(protoAddrParts[0], protoAddrParts[1])
|
}(s)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < len(protoAddrs); i++ {
|
for i := 0; i < len(protoAddrs); i++ {
|
||||||
|
|
|
@ -14,57 +14,48 @@ import (
|
||||||
"github.com/docker/libnetwork/portallocator"
|
"github.com/docker/libnetwork/portallocator"
|
||||||
)
|
)
|
||||||
|
|
||||||
// newServer sets up the required serverCloser and does protocol specific checking.
|
// newServer sets up the required serverClosers and does protocol specific checking.
|
||||||
func (s *Server) newServer(proto, addr string) (serverCloser, error) {
|
func (s *Server) newServer(proto, addr string) ([]serverCloser, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
l net.Listener
|
ls []net.Listener
|
||||||
)
|
)
|
||||||
switch proto {
|
switch proto {
|
||||||
case "fd":
|
case "fd":
|
||||||
ls, err := systemd.ListenFD(addr)
|
ls, err = systemd.ListenFD(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
chErrors := make(chan error, len(ls))
|
|
||||||
// We don't want to start serving on these sockets until the
|
// We don't want to start serving on these sockets until the
|
||||||
// daemon is initialized and installed. Otherwise required handlers
|
// daemon is initialized and installed. Otherwise required handlers
|
||||||
// won't be ready.
|
// won't be ready.
|
||||||
<-s.start
|
<-s.start
|
||||||
// Since ListenFD will return one or more sockets we have
|
|
||||||
// to create a go func to spawn off multiple serves
|
|
||||||
for i := range ls {
|
|
||||||
listener := ls[i]
|
|
||||||
go func() {
|
|
||||||
httpSrv := http.Server{Handler: s.router}
|
|
||||||
chErrors <- httpSrv.Serve(listener)
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
for i := 0; i < len(ls); i++ {
|
|
||||||
if err := <-chErrors; err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil, nil
|
|
||||||
case "tcp":
|
case "tcp":
|
||||||
l, err = s.initTcpSocket(addr)
|
l, err := s.initTcpSocket(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
ls = append(ls, l)
|
||||||
case "unix":
|
case "unix":
|
||||||
if l, err = sockets.NewUnixSocket(addr, s.cfg.SocketGroup, s.start); err != nil {
|
l, err := sockets.NewUnixSocket(addr, s.cfg.SocketGroup, s.start)
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
ls = append(ls, l)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("Invalid protocol format: %q", proto)
|
return nil, fmt.Errorf("Invalid protocol format: %q", proto)
|
||||||
}
|
}
|
||||||
return &HttpServer{
|
var res []serverCloser
|
||||||
|
for _, l := range ls {
|
||||||
|
res = append(res, &HttpServer{
|
||||||
&http.Server{
|
&http.Server{
|
||||||
Addr: addr,
|
Addr: addr,
|
||||||
Handler: s.router,
|
Handler: s.router,
|
||||||
},
|
},
|
||||||
l,
|
l,
|
||||||
}, nil
|
})
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) AcceptConnections(d *daemon.Daemon) {
|
func (s *Server) AcceptConnections(d *daemon.Daemon) {
|
||||||
|
|
Loading…
Reference in a new issue