-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
daemon: listeners: make systemd listener optional
On non systemd systems, the systemd-based activation is not needed at all, thus make it build-time optional. It won't be built in if the 'no_systemd' tag is set. changes v2: renamed 'nosystemd' tag to 'no_systemd' changes v3: fixed some obsolete imports use new style tags Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
- Loading branch information
Showing
3 changed files
with
73 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//go:build linux && no_systemd | ||
|
||
package listeners // import "github.com/docker/docker/daemon/listeners" | ||
|
||
import ( | ||
"crypto/tls" | ||
"errors" | ||
"net" | ||
) | ||
|
||
func listenFD(addr string, tlsConfig *tls.Config) ([]net.Listener, error) { | ||
return nil, errors.New("listenFD not implemented") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//go:build linux && !no_systemd | ||
|
||
package listeners // import "github.com/docker/docker/daemon/listeners" | ||
|
||
import ( | ||
"crypto/tls" | ||
"net" | ||
"strconv" | ||
|
||
"github.com/coreos/go-systemd/v22/activation" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// 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, tlsConfig *tls.Config) ([]net.Listener, error) { | ||
var ( | ||
err error | ||
listeners []net.Listener | ||
) | ||
// socket activation | ||
if tlsConfig != nil { | ||
listeners, err = activation.TLSListeners(tlsConfig) | ||
} else { | ||
listeners, err = activation.Listeners() | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if len(listeners) == 0 { | ||
return nil, errors.New("no sockets found via socket activation: make sure the service was started by systemd") | ||
} | ||
|
||
// default to all fds just like unix:// and tcp:// | ||
if addr == "" || addr == "*" { | ||
return listeners, nil | ||
} | ||
|
||
fdNum, err := strconv.Atoi(addr) | ||
if err != nil { | ||
return nil, errors.Errorf("failed to parse systemd fd address: should be a number: %v", addr) | ||
} | ||
fdOffset := fdNum - 3 | ||
if len(listeners) < fdOffset+1 { | ||
return nil, errors.New("too few socket activated files passed in by systemd") | ||
} | ||
if listeners[fdOffset] == nil { | ||
return nil, errors.Errorf("failed to listen on systemd activated file: fd %d", fdOffset+3) | ||
} | ||
for i, ls := range listeners { | ||
if i == fdOffset || ls == nil { | ||
continue | ||
} | ||
if err := ls.Close(); err != nil { | ||
return nil, errors.Wrapf(err, "failed to close systemd activated file: fd %d", fdOffset+3) | ||
} | ||
} | ||
return []net.Listener{listeners[fdOffset]}, nil | ||
} |