mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-06 21:51:33 +00:00
@@ -10,8 +10,10 @@ import (
|
||||
|
||||
"github.com/docker/docker/daemon"
|
||||
"github.com/docker/docker/pkg/sockets"
|
||||
"github.com/docker/docker/pkg/systemd"
|
||||
"github.com/docker/libnetwork/portallocator"
|
||||
|
||||
systemdActivation "github.com/coreos/go-systemd/activation"
|
||||
systemdDaemon "github.com/coreos/go-systemd/daemon"
|
||||
)
|
||||
|
||||
// newServer sets up the required serverClosers and does protocol specific checking.
|
||||
@@ -22,7 +24,7 @@ func (s *Server) newServer(proto, addr string) ([]serverCloser, error) {
|
||||
)
|
||||
switch proto {
|
||||
case "fd":
|
||||
ls, err = systemd.ListenFD(addr)
|
||||
ls, err = listenFD(addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -65,7 +67,7 @@ func (s *Server) AcceptConnections(d *daemon.Daemon) {
|
||||
// Tell the init daemon we are accepting requests
|
||||
s.daemon = d
|
||||
s.registerSubRouter()
|
||||
go systemd.SdNotify("READY=1")
|
||||
go systemdDaemon.SdNotify("READY=1")
|
||||
// close the lock so the listeners start accepting connections
|
||||
select {
|
||||
case <-s.start:
|
||||
@@ -110,3 +112,34 @@ func getContainersByNameDownlevel(w http.ResponseWriter, s *Server, namevar stri
|
||||
}
|
||||
return writeJSON(w, http.StatusOK, containerJSONRaw)
|
||||
}
|
||||
|
||||
// listenFD returns the specified socket activated files as a slice of
|
||||
// net.Listeners or all of the activated files if "*" is given.
|
||||
func listenFD(addr string) ([]net.Listener, error) {
|
||||
// socket activation
|
||||
listeners, err := systemdActivation.Listeners(false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if listeners == nil || len(listeners) == 0 {
|
||||
return nil, fmt.Errorf("No sockets found")
|
||||
}
|
||||
|
||||
// default to all fds just like unix:// and tcp://
|
||||
if addr == "" {
|
||||
addr = "*"
|
||||
}
|
||||
|
||||
fdNum, _ := strconv.Atoi(addr)
|
||||
fdOffset := fdNum - 3
|
||||
if (addr != "*") && (len(listeners) < int(fdOffset)+1) {
|
||||
return nil, fmt.Errorf("Too few socket activated files passed in")
|
||||
}
|
||||
|
||||
if addr == "*" {
|
||||
return listeners, nil
|
||||
}
|
||||
|
||||
return []net.Listener{listeners[fdOffset]}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user