Skip to content

Commit

Permalink
Adjust Elastic Agent 7.17 to launch upgrade watcher version (elastic#…
Browse files Browse the repository at this point in the history
…40452)

* Adjust so 7.17 agent starts latest watcher.

* Add changelog entry.

* Fix code review.
  • Loading branch information
blakerouse authored Aug 12, 2024
1 parent b7feb3c commit 16ec28c
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Fix CVE-2023-25173 by updating github.com/containerd/containerd to v1.5.18 {pull

*Functionbeat*

*Elastic Agent*

- Fixes the issue where upgrading from 7.17 to a 8.x+ version only runs the 7.17 watcher for the latest 8.x release.

==== Bugfixes

*Affecting all Beats*
Expand Down
7 changes: 7 additions & 0 deletions x-pack/elastic-agent/pkg/agent/application/paths/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ func SetInstall(path string) {
installPath = path
}

// TopBinaryPath returns the path to the Elastic Agent binary that is inside the Top directory.
//
// This always points to the symlink that points to the latest Elastic Agent version.
func TopBinaryPath() string {
return filepath.Join(Top(), BinaryName)
}

// 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
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ func InvokeWatcher(log *logger.Logger) error {
return nil
}

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

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

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

cmd := exec.Command(homeExePath, watcherSubcommand,
func invokeCmd() *exec.Cmd {
cmd := exec.Command(paths.TopBinaryPath(), watcherSubcommand,
"--path.config", paths.Config(),
"--path.home", paths.Top(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -114,10 +113,8 @@ func (p *darwinPidProvider) piderFromCmd(ctx context.Context, name string, args
}
}

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

cmd := exec.Command(homeExePath, watcherSubcommand,
func invokeCmd() *exec.Cmd {
cmd := exec.Command(paths.TopBinaryPath(), watcherSubcommand,
"--path.config", paths.Config(),
"--path.home", paths.Top(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ package upgrade
import (
"context"
"os/exec"
"path/filepath"
"time"

"golang.org/x/sys/windows/svc/mgr"
Expand Down Expand Up @@ -62,10 +61,8 @@ func (p *pidProvider) PID(ctx context.Context) (int, error) {
return int(status.ProcessId), nil
}

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

cmd := exec.Command(homeExePath, watcherSubcommand,
func invokeCmd() *exec.Cmd {
cmd := exec.Command(paths.TopBinaryPath(), watcherSubcommand,
"--path.config", paths.Config(),
"--path.home", paths.Top(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func (u *Upgrader) Upgrade(ctx context.Context, a Action, reexecNow bool, skipVe
return nil, err
}

// InvokeWatcher invokes the watcher using the symlink that is rotated above with ChangeSymlink
if err := InvokeWatcher(u.log); err != nil {
rollbackInstall(ctx, newHash)
return nil, errors.New("failed to invoke rollback watcher", err)
Expand Down

0 comments on commit 16ec28c

Please sign in to comment.