Skip to content

Commit

Permalink
[Elastic Agent] Retry deamon reload during enroll (#25590) (#25718)
Browse files Browse the repository at this point in the history
[Elastic Agent] Retry deamon reload during enroll (#25590)
  • Loading branch information
michalpristas authored May 14, 2021
1 parent 9e4b8ba commit 9c86f4d
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion x-pack/elastic-agent/pkg/agent/cmd/enroll_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (c *enrollCmd) fleetServerBootstrap(ctx context.Context) (string, error) {
var agentSubproc <-chan *os.ProcessState
if agentRunning {
// reload the already running agent
err = c.daemonReload(ctx)
err = c.daemonReloadWithBackoff(ctx)
if err != nil {
return "", errors.New(err, "failed to trigger elastic-agent daemon reload", errors.TypeApplication)
}
Expand Down Expand Up @@ -322,6 +322,28 @@ func (c *enrollCmd) prepareFleetTLS() error {
return nil
}

func (c *enrollCmd) daemonReloadWithBackoff(ctx context.Context) error {
err := c.daemonReload(ctx)
if err == nil {
return nil
}

signal := make(chan struct{})
backExp := backoff.NewExpBackoff(signal, 10*time.Second, 1*time.Minute)

for i := 5; i >= 0; i-- {
backExp.Wait()
c.log.Info("Retrying to restart...")
err = c.daemonReload(ctx)
if err == nil {
break
}
}

close(signal)
return err
}

func (c *enrollCmd) daemonReload(ctx context.Context) error {
daemon := client.New()
err := daemon.Connect(ctx)
Expand Down

0 comments on commit 9c86f4d

Please sign in to comment.