Skip to content

Commit

Permalink
New option: run_once, and removed skip_waiting
Browse files Browse the repository at this point in the history
- new default behaviour: an update check is always attempted right from
  the start, regardless of check_frequency value.
- run_once: controls whether we exit right after the initial update
  check.
- skip_waiting: removed

Fixes gokrazy#6
  • Loading branch information
mpl committed Jan 16, 2025
1 parent df3187b commit df63163
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func main() {
var o opts

flag.StringVar(&o.gusServer, "gus_server", "", "the HTTP/S endpoint of the GUS (gokrazy Update System) server (required)")
flag.StringVar(&o.checkFrequency, "check_frequency", "1h", "the time frequency for checks to the update service. default: 1h")
flag.StringVar(&o.checkFrequency, "check_frequency", "1h", "the time frequency for checks to the update service. The very first check is done on startup. default: 1h")
flag.StringVar(&o.destinationDir, "destination_dir", "/tmp/selfupdate", "the destination directory for the fetched update file. default: /tmp/selfupdate")
flag.BoolVar(&o.skipWaiting, "skip_waiting", false, "skips the time frequency check and jitter waits, and immediately performs an update check. default: false")
flag.BoolVar(&o.runOnce, "run_once", false, "exits right after the initial update attempt. default: false")

flag.Parse()

Expand Down Expand Up @@ -83,14 +83,13 @@ func logic(ctx context.Context, o opts) error {
gusCfg.BasePath = gusBasePath
gusCli := gusapi.NewAPIClient(gusCfg)

if o.skipWaiting {
log.Print("skipping waiting, performing an immediate updateProcess")
if err := updateProcess(ctx, gusCli, machineID, o.gusServer, sbomHash, o.destinationDir, httpPassword, httpPort); err != nil {
// If the updateProcess fails we exit with an error
// so that gokrazy supervisor will restart the process.
return fmt.Errorf("error performing updateProcess: %v", err)
}
if err := updateProcess(ctx, gusCli, machineID, o.gusServer, sbomHash, o.destinationDir, httpPassword, httpPort); err != nil {
// If the updateProcess fails we exit with an error
// so that gokrazy supervisor will restart the process.
return fmt.Errorf("error performing updateProcess: %w", err)
}

if o.runOnce {
// If the updateProcess doesn't error
// we happily return to terminate the process.
return nil
Expand Down

0 comments on commit df63163

Please sign in to comment.