diff --git a/x-pack/elastic-agent/pkg/agent/cmd/run.go b/x-pack/elastic-agent/pkg/agent/cmd/run.go index f502ef9cf49..74cf010cc66 100644 --- a/x-pack/elastic-agent/pkg/agent/cmd/run.go +++ b/x-pack/elastic-agent/pkg/agent/cmd/run.go @@ -128,12 +128,16 @@ func run(flags *globalFlags, streams *cli.IOStreams) error { } } if breakout { + if !reexecing { + logger.Info("Shutting down Elastic Agent and sending last events...") + } break } } err = app.Stop() if !reexecing { + logger.Info("Shutting down completed.") return err } rex.ShutdownComplete() diff --git a/x-pack/elastic-agent/pkg/agent/control/server/listener.go b/x-pack/elastic-agent/pkg/agent/control/server/listener.go index bf03f54e2da..7edfc7b8ee9 100644 --- a/x-pack/elastic-agent/pkg/agent/control/server/listener.go +++ b/x-pack/elastic-agent/pkg/agent/control/server/listener.go @@ -23,7 +23,7 @@ func createListener(log *logger.Logger) (net.Listener, error) { path := strings.TrimPrefix(control.Address(), "unix://") if _, err := os.Stat(path); !os.IsNotExist(err) { err = os.Remove(path) - if err != nil { + if err != nil && !os.IsNotExist(err) { log.Errorf("%s", errors.New(err, fmt.Sprintf("Failed to cleanup %s", path), errors.TypeFilesystem, errors.M("path", path))) } }