Skip to content

Commit

Permalink
fix(installer): Support leftover /opt/datadog-agent dir (#29443)
Browse files Browse the repository at this point in the history
  • Loading branch information
BaptisteFoy authored Sep 23, 2024
1 parent b97517a commit 06338e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/fleet/installer/service/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ func disableUnit(ctx context.Context, unit string) (err error) {
span, _ := tracer.StartSpanFromContext(ctx, "disable_unit")
defer func() { span.Finish(tracer.WithError(err)) }()
span.SetTag("unit", unit)

enabledErr := exec.CommandContext(ctx, "systemctl", "is-enabled", "--quiet", unit).Run()
if enabledErr != nil {
// unit is already disabled or doesn't exist, we can return fast
return nil
}

err = exec.CommandContext(ctx, "systemctl", "disable", unit).Run()
exitErr := &exec.ExitError{}
if !errors.As(err, &exitErr) {
Expand Down
12 changes: 12 additions & 0 deletions test/new-e2e/tests/installer/package_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,18 @@ func (s *packageAgentSuite) TestUpgrade_DisabledAgentDebRPM_to_OCI() {
s.host.Run("sudo systemctl show datadog-agent -p ExecStart | grep /opt/datadog-packages")
}

func (s *packageAgentSuite) TestInstallWithLeftoverDebDir() {
// create /opt/datadog-agent to simulate a disabled agent
s.host.Run("sudo mkdir -p /opt/datadog-agent")

// install OCI agent
s.RunInstallScript(envForceInstall("datadog-agent"))

state := s.host.State()
s.assertUnits(state, false)
s.host.Run("sudo systemctl show datadog-agent -p ExecStart | grep /opt/datadog-packages")
}

func (s *packageAgentSuite) purgeAgentDebInstall() {
pkgManager := s.host.GetPkgManager()
switch pkgManager {
Expand Down

0 comments on commit 06338e9

Please sign in to comment.