diff --git a/command/agent/command.go b/command/agent/command.go index d639ac452b..2b389bc4f2 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -465,6 +465,29 @@ func (cmd *Command) checkpointResults(results *checkpoint.CheckResponse, err err } } +func (cmd *Command) startupUpdateCheck(config *Config) { + version := config.Version + if config.VersionPrerelease != "" { + version += fmt.Sprintf("-%s", config.VersionPrerelease) + } + updateParams := &checkpoint.CheckParams{ + Product: "consul", + Version: version, + } + if !config.DisableAnonymousSignature { + updateParams.SignatureFile = filepath.Join(config.DataDir, "checkpoint-signature") + } + + // Schedule a periodic check with expected interval of 24 hours + checkpoint.CheckInterval(updateParams, 24*time.Hour, cmd.checkpointResults) + + // Do an immediate check within the next 30 seconds + go func() { + time.Sleep(lib.RandomStagger(30 * time.Second)) + cmd.checkpointResults(checkpoint.Check(updateParams)) + }() +} + // startupJoin is invoked to handle any joins specified to take place at start time func (cmd *Command) startupJoin(agent *Agent, cfg *Config) error { if len(cfg.StartJoin) == 0 { @@ -633,26 +656,7 @@ func (cmd *Command) Run(args []string) int { // Setup update checking if !config.DisableUpdateCheck { - version := config.Version - if config.VersionPrerelease != "" { - version += fmt.Sprintf("-%s", config.VersionPrerelease) - } - updateParams := &checkpoint.CheckParams{ - Product: "consul", - Version: version, - } - if !config.DisableAnonymousSignature { - updateParams.SignatureFile = filepath.Join(config.DataDir, "checkpoint-signature") - } - - // Schedule a periodic check with expected interval of 24 hours - checkpoint.CheckInterval(updateParams, 24*time.Hour, cmd.checkpointResults) - - // Do an immediate check within the next 30 seconds - go func() { - time.Sleep(lib.RandomStagger(30 * time.Second)) - cmd.checkpointResults(checkpoint.Check(updateParams)) - }() + cmd.startupUpdateCheck(config) } defer agent.Shutdown()