agent: move update check out of the run method

This commit is contained in:
Frank Schroeder 2017-06-02 15:29:40 +02:00 committed by Frank Schröder
parent 96d8035adc
commit 84f5e8c3ab
1 changed files with 24 additions and 20 deletions

View File

@ -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()