diff --git a/cmd/dockerd/daemon.go b/cmd/dockerd/daemon.go index 5637d275fe..3d4184b171 100644 --- a/cmd/dockerd/daemon.go +++ b/cmd/dockerd/daemon.go @@ -227,7 +227,9 @@ func (cli *daemonCLI) start(ctx context.Context) (err error) { }() // Notify that the API is active, but before daemon is set up. - preNotifyReady() + if err := preNotifyReady(); err != nil { + return err + } const otelServiceNameEnv = "OTEL_SERVICE_NAME" if _, ok := os.LookupEnv(otelServiceNameEnv); !ok { diff --git a/cmd/dockerd/daemon_freebsd.go b/cmd/dockerd/daemon_freebsd.go index ca230a22fe..d1293485a6 100644 --- a/cmd/dockerd/daemon_freebsd.go +++ b/cmd/dockerd/daemon_freebsd.go @@ -3,7 +3,8 @@ package main import "github.com/docker/docker/daemon/config" // preNotifyReady sends a message to the host when the API is active, but before the daemon is -func preNotifyReady() { +func preNotifyReady() error { + return nil } // notifyReady sends a message to the host when the server is ready to be used diff --git a/cmd/dockerd/daemon_linux.go b/cmd/dockerd/daemon_linux.go index 43f869bca6..b375459c67 100644 --- a/cmd/dockerd/daemon_linux.go +++ b/cmd/dockerd/daemon_linux.go @@ -26,7 +26,8 @@ func setPlatformOptions(conf *config.Config) error { } // preNotifyReady sends a message to the host when the API is active, but before the daemon is -func preNotifyReady() { +func preNotifyReady() error { + return nil } // notifyReady sends a message to the host when the server is ready to be used diff --git a/cmd/dockerd/daemon_windows.go b/cmd/dockerd/daemon_windows.go index bd17c1dc60..8bbbae8457 100644 --- a/cmd/dockerd/daemon_windows.go +++ b/cmd/dockerd/daemon_windows.go @@ -41,15 +41,16 @@ func setDefaultUmask() error { } // preNotifyReady sends a message to the host when the API is active, but before the daemon is -func preNotifyReady() { +func preNotifyReady() error { // start the service now to prevent timeouts waiting for daemon to start // but still (eventually) complete all requests that are sent after this if service != nil { err := service.started() if err != nil { - log.G(context.TODO()).Fatal(err) + return err } } + return nil } // notifyReady sends a message to the host when the server is ready to be used @@ -63,9 +64,6 @@ func notifyStopping() { // notifyShutdown is called after the daemon shuts down but before the process exits. func notifyShutdown(err error) { if service != nil { - if err != nil { - log.G(context.TODO()).Fatal(err) - } service.stopped(err) } } diff --git a/cmd/dockerd/docker_windows.go b/cmd/dockerd/docker_windows.go index d133bb88ca..1b17b0c36b 100644 --- a/cmd/dockerd/docker_windows.go +++ b/cmd/dockerd/docker_windows.go @@ -26,6 +26,11 @@ func runDaemon(ctx context.Context, cli *daemonCLI) error { } err = cli.start(ctx) + if service != nil { + // When running as a service, log the error, so that it's sent to + // the event-log. + log.G(ctx).Error(err) + } notifyShutdown(err) return err }