containerd: use docker/listeners to create the GRPC socket
This allows for the use of socket activation with the flag `-l fd://` and similar. The semantics are identical to Docker, but it's important to note that the semantics of the --listen flag have changed to require a proto://addr formatted string. Signed-off-by: Aleksa Sarai <asarai@suse.de>
This commit is contained in:
parent
20ef099321
commit
f88d701233
2 changed files with 19 additions and 10 deletions
|
@ -2,9 +2,9 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
@ -18,6 +18,7 @@ import (
|
||||||
"github.com/docker/containerd/api/grpc/types"
|
"github.com/docker/containerd/api/grpc/types"
|
||||||
"github.com/docker/containerd/osutils"
|
"github.com/docker/containerd/osutils"
|
||||||
"github.com/docker/containerd/supervisor"
|
"github.com/docker/containerd/supervisor"
|
||||||
|
"github.com/docker/docker/pkg/listeners"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -43,7 +44,7 @@ var daemonFlags = []cli.Flag{
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "listen,l",
|
Name: "listen,l",
|
||||||
Value: defaultGRPCEndpoint,
|
Value: defaultGRPCEndpoint,
|
||||||
Usage: "Address on which GRPC API will listen",
|
Usage: "proto://address on which the GRPC API will listen",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "runtime,r",
|
Name: "runtime,r",
|
||||||
|
@ -127,7 +128,13 @@ func daemon(context *cli.Context) error {
|
||||||
if err := sv.Start(); err != nil {
|
if err := sv.Start(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
server, err := startServer(context.String("listen"), sv)
|
// Split the listen string of the form proto://addr
|
||||||
|
listenSpec := context.String("listen")
|
||||||
|
listenParts := strings.SplitN(listenSpec, "://", 2)
|
||||||
|
if len(listenParts) != 2 {
|
||||||
|
return fmt.Errorf("bad listen address format %s, expected proto://address", listenSpec)
|
||||||
|
}
|
||||||
|
server, err := startServer(listenParts[0], listenParts[1], sv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -146,14 +153,17 @@ func daemon(context *cli.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func startServer(address string, sv *supervisor.Supervisor) (*grpc.Server, error) {
|
func startServer(protocol, address string, sv *supervisor.Supervisor) (*grpc.Server, error) {
|
||||||
if err := os.RemoveAll(address); err != nil {
|
// TODO: We should use TLS.
|
||||||
return nil, err
|
// TODO: Add an option for the SocketGroup.
|
||||||
}
|
sockets, err := listeners.Init(protocol, address, "", nil)
|
||||||
l, err := net.Listen(defaultListenType, address)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if len(sockets) != 1 {
|
||||||
|
return nil, fmt.Errorf("incorrect number of listeners")
|
||||||
|
}
|
||||||
|
l := sockets[0]
|
||||||
s := grpc.NewServer()
|
s := grpc.NewServer()
|
||||||
types.RegisterAPIServer(s, server.NewServer(sv))
|
types.RegisterAPIServer(s, server.NewServer(sv))
|
||||||
go func() {
|
go func() {
|
||||||
|
|
|
@ -20,8 +20,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultStateDir = "/run/containerd"
|
defaultStateDir = "/run/containerd"
|
||||||
defaultListenType = "unix"
|
defaultGRPCEndpoint = "unix:///run/containerd/containerd.sock"
|
||||||
defaultGRPCEndpoint = "/run/containerd/containerd.sock"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func appendPlatformFlags() {
|
func appendPlatformFlags() {
|
||||||
|
|
Loading…
Reference in a new issue