Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a startup delay to the autoupdater, to avoid interfering with critical work #695

Merged
merged 4 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func runLauncher(ctx context.Context, cancel func(), opts *launcher.Options) err
MirrorURL: opts.MirrorServerURL,
NotaryPrefix: opts.NotaryPrefix,
HTTPClient: httpClient,
InitialDelay: opts.AutoupdateInitialDelay,
SigChannel: sigChannel,
}

Expand Down
64 changes: 33 additions & 31 deletions cmd/launcher/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ func parseOptions(args []string) (*launcher.Options, error) {
_ = flagset.String("config", "", "config file to parse options from (optional)")

// Autoupdate options
flAutoupdate = flagset.Bool("autoupdate", false, "Whether or not the osquery autoupdater is enabled (default: false)")
flNotaryServerURL = flagset.String("notary_url", autoupdate.DefaultNotary, "The Notary update server (default: https://notary.kolide.co)")
flMirrorURL = flagset.String("mirror_url", autoupdate.DefaultMirror, "The mirror server for autoupdates (default: https://dl.kolide.co)")
flAutoupdateInterval = flagset.Duration("autoupdate_interval", 1*time.Hour, "The interval to check for updates (default: once every hour)")
flUpdateChannel = flagset.String("update_channel", "stable", "The channel to pull updates from (options: stable, beta, nightly)")
flNotaryPrefix = flagset.String("notary_prefix", autoupdate.DefaultNotaryPrefix, "The prefix for Notary path that contains the collections (default: kolide/)")
flAutoupdate = flagset.Bool("autoupdate", false, "Whether or not the osquery autoupdater is enabled (default: false)")
flNotaryServerURL = flagset.String("notary_url", autoupdate.DefaultNotary, "The Notary update server (default: https://notary.kolide.co)")
flMirrorURL = flagset.String("mirror_url", autoupdate.DefaultMirror, "The mirror server for autoupdates (default: https://dl.kolide.co)")
flAutoupdateInterval = flagset.Duration("autoupdate_interval", 1*time.Hour, "The interval to check for updates (default: once every hour)")
flUpdateChannel = flagset.String("update_channel", "stable", "The channel to pull updates from (options: stable, beta, nightly)")
flNotaryPrefix = flagset.String("notary_prefix", autoupdate.DefaultNotaryPrefix, "The prefix for Notary path that contains the collections (default: kolide/)")
flAutoupdateInitialDelay = flagset.Duration("autoupdater_initial_delay", 1*time.Hour, "Initial autoupdater subprocess delay")

// Development options
flDebug = flagset.Bool("debug", false, "Whether or not debug logging is enabled (default: false)")
Expand Down Expand Up @@ -147,31 +148,32 @@ func parseOptions(args []string) (*launcher.Options, error) {
}

opts := &launcher.Options{
Autoupdate: *flAutoupdate,
AutoupdateInterval: *flAutoupdateInterval,
CertPins: certPins,
Control: *flControl,
ControlServerURL: *flControlServerURL,
Debug: *flDebug,
DebugLogFile: *flDebugLogFile,
DisableControlTLS: *flDisableControlTLS,
EnableInitialRunner: *flInitialRunner,
EnrollSecret: *flEnrollSecret,
EnrollSecretPath: *flEnrollSecretPath,
InsecureTLS: *flInsecureTLS,
InsecureTransport: *flInsecureTransport,
KolideServerURL: *flKolideServerURL,
LoggingInterval: *flLoggingInterval,
MirrorServerURL: *flMirrorURL,
NotaryPrefix: *flNotaryPrefix,
NotaryServerURL: *flNotaryServerURL,
OsqueryFlags: flOsqueryFlags,
OsqueryVerbose: *flOsqueryVerbose,
OsquerydPath: osquerydPath,
RootDirectory: *flRootDirectory,
RootPEM: *flRootPEM,
Transport: *flTransport,
UpdateChannel: updateChannel,
Autoupdate: *flAutoupdate,
AutoupdateInterval: *flAutoupdateInterval,
AutoupdateInitialDelay: *flAutoupdateInitialDelay,
CertPins: certPins,
Control: *flControl,
ControlServerURL: *flControlServerURL,
Debug: *flDebug,
DebugLogFile: *flDebugLogFile,
DisableControlTLS: *flDisableControlTLS,
EnableInitialRunner: *flInitialRunner,
EnrollSecret: *flEnrollSecret,
EnrollSecretPath: *flEnrollSecretPath,
InsecureTLS: *flInsecureTLS,
InsecureTransport: *flInsecureTransport,
KolideServerURL: *flKolideServerURL,
LoggingInterval: *flLoggingInterval,
MirrorServerURL: *flMirrorURL,
NotaryPrefix: *flNotaryPrefix,
NotaryServerURL: *flNotaryServerURL,
OsqueryFlags: flOsqueryFlags,
OsqueryVerbose: *flOsqueryVerbose,
OsquerydPath: osquerydPath,
RootDirectory: *flRootDirectory,
RootPEM: *flRootPEM,
Transport: *flTransport,
UpdateChannel: updateChannel,
}
return opts, nil
}
Expand Down
21 changes: 11 additions & 10 deletions cmd/launcher/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,17 @@ func getArgsAndResponse() (map[string]string, *launcher.Options) {
}

opts := &launcher.Options{
Control: true,
OsquerydPath: windowsAddExe("/dev/null"),
KolideServerURL: randomHostname,
LoggingInterval: time.Duration(randomInt) * time.Second,
AutoupdateInterval: 48 * time.Hour,
NotaryServerURL: "https://notary.kolide.co",
MirrorServerURL: "https://dl.kolide.co",
NotaryPrefix: "kolide",
UpdateChannel: "stable",
Transport: "grpc",
Control: true,
OsquerydPath: windowsAddExe("/dev/null"),
KolideServerURL: randomHostname,
LoggingInterval: time.Duration(randomInt) * time.Second,
AutoupdateInterval: 48 * time.Hour,
AutoupdateInitialDelay: 1 * time.Hour,
NotaryServerURL: "https://notary.kolide.co",
MirrorServerURL: "https://dl.kolide.co",
NotaryPrefix: "kolide",
UpdateChannel: "stable",
Transport: "grpc",
}

return args, opts
Expand Down
10 changes: 10 additions & 0 deletions cmd/launcher/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type updaterConfig struct {
RootDirectory string // launcher's root dir. use for holding tuf staging and updates
AutoupdateInterval time.Duration
UpdateChannel autoupdate.UpdateChannel
InitialDelay time.Duration // start delay, to avoid whomping critical early data

NotaryURL string
MirrorURL string
Expand Down Expand Up @@ -64,6 +65,15 @@ func createUpdater(

return &actor.Actor{
Execute: func() error {
// When launcher first starts, we'd like the
// server to start receiving data
// immediately. But, if updater is trying to
// run, this creates an awkward pause for restart.
// So, delay starting updates by an hour or two.
if config.InitialDelay != 0 {
time.Sleep(config.InitialDelay)
}

// Failing to start the updater is not a fatal launcher
// error. If there's a problem, sleep and try
// again. Implementing this is a bit gnarly. In the event of a
Expand Down
2 changes: 2 additions & 0 deletions pkg/launcher/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ type Options struct {
UpdateChannel autoupdate.UpdateChannel
// NotaryPrefix is the path prefix used to store launcher and osqueryd binaries on the Notary server
NotaryPrefix string
// AutoupdateInitialDelay set an initial startup delay on the autoupdater process.
AutoupdateInitialDelay time.Duration

// Debug enables debug logging.
Debug bool
Expand Down