Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
- Reduce log level for listener cleanup to debug {pull}25274[25274]
- Delay the restart of application when a status report of failure is given {pull}25339[25339]
- Don't log when upgrade capability doesn't apply {pull}25386[25386]
- Fixed issue when unversioned home is set and invoked watcher failing with ENOENT {issue}25371[25371]

==== New features

Expand Down
11 changes: 6 additions & 5 deletions x-pack/elastic-agent/pkg/agent/application/paths/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func Home() string {
if unversionedHome {
return topPath
}
return versionedHome(topPath)
return VersionedHome(topPath)
}

// IsVersionHome returns true if the Home path is versioned based on build.
Expand Down Expand Up @@ -134,6 +134,11 @@ func SetLogs(path string) {
logsPath = path
}

// VersionedHome returns a versioned path based on a TopPath and used commit.
func VersionedHome(base string) string {
return filepath.Join(base, "data", fmt.Sprintf("elastic-agent-%s", release.ShortCommit()))
}

// initialTop returns the initial top-level path for the binary
//
// When nested in top-level/data/elastic-agent-${hash}/ the result is top-level/.
Expand Down Expand Up @@ -163,7 +168,3 @@ func insideData(exePath string) bool {
expectedPath := filepath.Join("data", fmt.Sprintf("elastic-agent-%s", release.ShortCommit()))
return strings.HasSuffix(exePath, expectedPath)
}

func versionedHome(base string) string {
return filepath.Join(base, "data", fmt.Sprintf("elastic-agent-%s", release.ShortCommit()))
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ func InvokeWatcher(log *logger.Logger) error {
return nil
}

cmd := invokeCmd()
versionedHome := paths.VersionedHome(paths.Top())
cmd := invokeCmd(versionedHome)
defer func() {
if cmd.Process != nil {
log.Debugf("releasing watcher %v", cmd.Process.Pid)
Expand Down
4 changes: 2 additions & 2 deletions x-pack/elastic-agent/pkg/agent/application/upgrade/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ func (p *noopPidProvider) Name() string { return "noop" }

func (p *noopPidProvider) PID(ctx context.Context) (int, error) { return 0, nil }

func invokeCmd() *exec.Cmd {
homeExePath := filepath.Join(paths.Home(), agentName)
func invokeCmd(topPath string) *exec.Cmd {
homeExePath := filepath.Join(topPath, agentName)

cmd := exec.Command(homeExePath, watcherSubcommand,
"--path.config", paths.Config(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ func (p *darwinPidProvider) piderFromCmd(ctx context.Context, name string, args
}
}

func invokeCmd() *exec.Cmd {
homeExePath := filepath.Join(paths.Home(), agentName)
func invokeCmd(topPath string) *exec.Cmd {
homeExePath := filepath.Join(topPath, agentName)

cmd := exec.Command(homeExePath, watcherSubcommand,
"--path.config", paths.Config(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func (p *pidProvider) PID(ctx context.Context) (int, error) {
return int(status.ProcessId), nil
}

func invokeCmd() *exec.Cmd {
homeExePath := filepath.Join(paths.Home(), agentName)
func invokeCmd(topPath string) *exec.Cmd {
homeExePath := filepath.Join(topPath, agentName)

cmd := exec.Command(homeExePath, watcherSubcommand,
"--path.config", paths.Config(),
Expand Down