From ccf9439abbc4fb9de6e509e5591f8fa17325be8b Mon Sep 17 00:00:00 2001 From: Tiago Queiroz Date: Mon, 17 Jun 2024 10:34:03 -0400 Subject: [PATCH] Only change socket path --- internal/pkg/agent/cmd/container.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/pkg/agent/cmd/container.go b/internal/pkg/agent/cmd/container.go index e42aaad4d48..c48940f67e4 100644 --- a/internal/pkg/agent/cmd/container.go +++ b/internal/pkg/agent/cmd/container.go @@ -34,6 +34,7 @@ import ( "github.com/elastic/elastic-agent/pkg/component" "github.com/elastic/elastic-agent/pkg/core/logger" "github.com/elastic/elastic-agent/pkg/core/process" + "github.com/elastic/elastic-agent/pkg/utils" "github.com/elastic/elastic-agent/version" ) @@ -771,7 +772,7 @@ func logToStderr(cfg *configuration.Configuration) { func setPaths(statePath, configPath, logsPath, socketPath string, writePaths bool) error { statePath = envWithDefault(statePath, "STATE_PATH") - if isStatePathTooLong(statePath) || statePath == "" { + if statePath == "" { statePath = defaultStateDirectory } @@ -780,8 +781,14 @@ func setPaths(statePath, configPath, logsPath, socketPath string, writePaths boo if configPath == "" { configPath = statePath } + if _, err := os.Stat(configPath); os.IsNotExist(err) { + if err := os.MkdirAll(configPath, 0755); err != nil { + return fmt.Errorf("cannot create folders for config path '%s': %w", configPath, err) + } + } + if socketPath == "" { - socketPath = fmt.Sprintf("unix://%s", filepath.Join(topPath, paths.ControlSocketName)) + socketPath = utils.SocketURLWithFallback(statePath, topPath) } // ensure that the directory and sub-directory data exists if err := os.MkdirAll(topPath, 0755); err != nil {