mirror of
https://github.com/moby/moby.git
synced 2026-01-11 10:41:43 +00:00
Merge pull request #50010 from dmcgowan/dockerd-command-daemon
Split dockerd main command to package under daemon
This commit is contained in:
1
cmd/dockerd/builtins/builtins.go
Normal file
1
cmd/dockerd/builtins/builtins.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package builtins
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
//go:generate go-winres make --arch=386,amd64,arm,arm64 --in=../../cli/winresources/dockerd/winres.json --out=../../cli/winresources/dockerd/resource
|
//go:generate go-winres make --arch=386,amd64,arm,arm64 --in=../../../cli/winresources/dockerd/winres.json --out=../../../cli/winresources/dockerd/resource
|
||||||
|
|
||||||
package main
|
package builtins
|
||||||
|
|
||||||
import _ "github.com/docker/docker/cli/winresources/dockerd"
|
import _ "github.com/docker/docker/cli/winresources/dockerd"
|
||||||
43
cmd/dockerd/main.go
Normal file
43
cmd/dockerd/main.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/moby/sys/reexec"
|
||||||
|
"github.com/moby/term"
|
||||||
|
|
||||||
|
"github.com/docker/docker/daemon/command"
|
||||||
|
|
||||||
|
_ "github.com/docker/docker/cmd/dockerd/builtins"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if reexec.Init() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
// Ignore SIGPIPE events. These are generated by systemd when journald is restarted while
|
||||||
|
// the docker daemon is not restarted and also running under systemd.
|
||||||
|
// Fixes https://github.com/docker/docker/issues/19728
|
||||||
|
signal.Ignore(syscall.SIGPIPE)
|
||||||
|
|
||||||
|
// Set terminal emulation based on platform as required.
|
||||||
|
_, stdout, stderr := term.StdStreams()
|
||||||
|
onError := func(err error) {
|
||||||
|
fmt.Fprintf(stderr, "%s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := command.NewDaemonRunner(stdout, stderr)
|
||||||
|
if err != nil {
|
||||||
|
onError(err)
|
||||||
|
}
|
||||||
|
if err := r.Run(ctx); err != nil {
|
||||||
|
onError(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"runtime"
|
"runtime"
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
//go:build linux || freebsd
|
//go:build unix
|
||||||
|
|
||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
//go:build linux || freebsd
|
//go:build unix
|
||||||
|
|
||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/docker/docker/daemon/config"
|
"github.com/docker/docker/daemon/config"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -39,10 +39,10 @@ import (
|
|||||||
buildkit "github.com/docker/docker/builder/builder-next"
|
buildkit "github.com/docker/docker/builder/builder-next"
|
||||||
"github.com/docker/docker/builder/builder-next/exporter"
|
"github.com/docker/docker/builder/builder-next/exporter"
|
||||||
"github.com/docker/docker/builder/dockerfile"
|
"github.com/docker/docker/builder/dockerfile"
|
||||||
"github.com/docker/docker/cmd/dockerd/debug"
|
|
||||||
"github.com/docker/docker/cmd/dockerd/trap"
|
|
||||||
"github.com/docker/docker/daemon"
|
"github.com/docker/docker/daemon"
|
||||||
"github.com/docker/docker/daemon/cluster"
|
"github.com/docker/docker/daemon/cluster"
|
||||||
|
"github.com/docker/docker/daemon/command/debug"
|
||||||
|
"github.com/docker/docker/daemon/command/trap"
|
||||||
"github.com/docker/docker/daemon/config"
|
"github.com/docker/docker/daemon/config"
|
||||||
"github.com/docker/docker/daemon/listeners"
|
"github.com/docker/docker/daemon/listeners"
|
||||||
"github.com/docker/docker/dockerversion"
|
"github.com/docker/docker/dockerversion"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package command
|
||||||
|
|
||||||
import "github.com/docker/docker/daemon/config"
|
import "github.com/docker/docker/daemon/config"
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
cdcgroups "github.com/containerd/cgroups/v3"
|
cdcgroups "github.com/containerd/cgroups/v3"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"runtime"
|
"runtime"
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
//go:build !windows
|
//go:build unix
|
||||||
|
|
||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
//go:build !windows
|
//go:build unix
|
||||||
|
|
||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -1,25 +1,21 @@
|
|||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"io"
|
||||||
"os/signal"
|
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"github.com/containerd/log"
|
"github.com/containerd/log"
|
||||||
"github.com/docker/docker/daemon/config"
|
"github.com/docker/docker/daemon/config"
|
||||||
"github.com/docker/docker/dockerversion"
|
"github.com/docker/docker/dockerversion"
|
||||||
"github.com/docker/docker/pkg/rootless"
|
"github.com/docker/docker/pkg/rootless"
|
||||||
"github.com/moby/buildkit/util/apicaps"
|
"github.com/moby/buildkit/util/apicaps"
|
||||||
"github.com/moby/sys/reexec"
|
|
||||||
"github.com/moby/term"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var honorXDG bool
|
var honorXDG bool
|
||||||
|
|
||||||
func newDaemonCommand() (*cobra.Command, error) {
|
func newDaemonCommand(stderr io.Writer) (*cobra.Command, error) {
|
||||||
// FIXME(thaJeztah): config.New also looks up default binary-path, but this code is also executed when running "--version".
|
// FIXME(thaJeztah): config.New also looks up default binary-path, but this code is also executed when running "--version".
|
||||||
cfg, err := config.New()
|
cfg, err := config.New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -42,7 +38,7 @@ func newDaemonCommand() (*cobra.Command, error) {
|
|||||||
}
|
}
|
||||||
if opts.Validate {
|
if opts.Validate {
|
||||||
// If config wasn't OK we wouldn't have made it this far.
|
// If config wasn't OK we wouldn't have made it this far.
|
||||||
_, _ = fmt.Fprintln(os.Stderr, "configuration OK")
|
_, _ = fmt.Fprintln(stderr, "configuration OK")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,39 +96,36 @@ func init() {
|
|||||||
honorXDG = rootless.RunningWithRootlessKit()
|
honorXDG = rootless.RunningWithRootlessKit()
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
// Runner is used to run the daemon command
|
||||||
if reexec.Init() {
|
type Runner interface {
|
||||||
return
|
Run(context.Context) error
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
// Ignore SIGPIPE events. These are generated by systemd when journald is restarted while
|
type daemonRunner struct {
|
||||||
// the docker daemon is not restarted and also running under systemd.
|
*cobra.Command
|
||||||
// Fixes https://github.com/docker/docker/issues/19728
|
}
|
||||||
signal.Ignore(syscall.SIGPIPE)
|
|
||||||
|
|
||||||
// Set terminal emulation based on platform as required.
|
func (d daemonRunner) Run(ctx context.Context) error {
|
||||||
_, stdout, stderr := term.StdStreams()
|
configureGRPCLog(ctx)
|
||||||
onError := func(err error) {
|
|
||||||
fmt.Fprintf(stderr, "%s\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// initial log formatting; this setting is updated after the daemon configuration is loaded.
|
return d.ExecuteContext(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDaemonRunner creates a new daemon runner with the given
|
||||||
|
// stdout and stderr writers.
|
||||||
|
func NewDaemonRunner(stdout, stderr io.Writer) (Runner, error) {
|
||||||
err := log.SetFormat(log.TextFormat)
|
err := log.SetFormat(log.TextFormat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
onError(err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
initLogging(stdout, stderr)
|
initLogging(stdout, stderr)
|
||||||
configureGRPCLog()
|
|
||||||
|
|
||||||
cmd, err := newDaemonCommand()
|
cmd, err := newDaemonCommand(stderr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
onError(err)
|
return nil, err
|
||||||
}
|
}
|
||||||
cmd.SetOut(stdout)
|
cmd.SetOut(stdout)
|
||||||
if err := cmd.ExecuteContext(ctx); err != nil {
|
|
||||||
onError(err)
|
return daemonRunner{cmd}, nil
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
//go:build !windows
|
//go:build unix
|
||||||
|
|
||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
// info => trace
|
// info => trace
|
||||||
// warn => debug
|
// warn => debug
|
||||||
// error => warn
|
// error => warn
|
||||||
func configureGRPCLog() {
|
func configureGRPCLog(ctx context.Context) {
|
||||||
l := log.G(context.TODO()).WithField("library", "grpc")
|
l := log.G(ctx).WithField("library", "grpc")
|
||||||
grpclog.SetLoggerV2(grpclog.NewLoggerV2(l.WriterLevel(log.TraceLevel), l.WriterLevel(log.DebugLevel), l.WriterLevel(log.WarnLevel)))
|
grpclog.SetLoggerV2(grpclog.NewLoggerV2(l.WriterLevel(log.TraceLevel), l.WriterLevel(log.DebugLevel), l.WriterLevel(log.WarnLevel)))
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
//go:build !windows
|
//go:build !windows
|
||||||
|
|
||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/cmd/dockerd/trap"
|
"github.com/docker/docker/daemon/command/trap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -17,7 +17,7 @@ import (
|
|||||||
"github.com/docker/docker/api"
|
"github.com/docker/docker/api"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/system"
|
"github.com/docker/docker/api/types/system"
|
||||||
"github.com/docker/docker/cmd/dockerd/debug"
|
"github.com/docker/docker/daemon/command/debug"
|
||||||
"github.com/docker/docker/daemon/config"
|
"github.com/docker/docker/daemon/config"
|
||||||
"github.com/docker/docker/daemon/internal/filedescriptors"
|
"github.com/docker/docker/daemon/internal/filedescriptors"
|
||||||
"github.com/docker/docker/daemon/logger"
|
"github.com/docker/docker/daemon/logger"
|
||||||
|
|||||||
Reference in New Issue
Block a user