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

updatehub-server: replace --wait option with --probe #216

Merged
merged 1 commit into from
Jul 30, 2018
Merged
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
47 changes: 23 additions & 24 deletions cmd/updatehub-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func main() {

isQuiet := cmd.PersistentFlags().Bool("quiet", false, "sets the log level to 'error'")
isDebug := cmd.PersistentFlags().Bool("debug", false, "sets the log level to 'debug'")
wait := cmd.PersistentFlags().Bool("wait", false, "wait for UpdateHub Agent")
probe := cmd.PersistentFlags().Bool("probe", false, "probe the updatehub for update")
mount := cmd.PersistentFlags().StringP("mount", "m", "", "device to mount")
fstype := cmd.PersistentFlags().StringP("fstype", "f", "", "filesystem type of device to mount")

Expand Down Expand Up @@ -140,37 +140,36 @@ func main() {
var info *AgentInfo

// Wait and check for UpdateHub Agent is running
for ok := true; ok; ok = *wait {
for *probe {
_, _, errs := gorequest.New().Get(buildURL("/info")).EndStruct(&info)
if len(errs) == 0 {
log.Info("UpdateHub Agent is running")
*wait = false
}

time.Sleep(time.Second)
}

// UpdateHub Agent is running?
if info != nil {
probe := ProbeResponse{UpdateAvailable: false}

var req struct {
ServerAddress string `json:"server-address"`
}
req.ServerAddress = "http://localhost:8088"
probe := ProbeResponse{UpdateAvailable: false}

// Probe for update
_, _, errs := gorequest.New().Post(buildURL("/probe")).Send(req).EndStruct(&probe)
if len(errs) == 0 {
if probe.UpdateAvailable {
log.Info("Update available")
var req struct {
ServerAddress string `json:"server-address"`
}
req.ServerAddress = "http://localhost:8088"

// Probe for update
_, _, errs := gorequest.New().Post(buildURL("/probe")).Send(req).EndStruct(&probe)
if len(errs) == 0 {
if probe.UpdateAvailable {
log.Info("Update available")
} else {
log.Info("Update not available")
os.Exit(0)
}
} else {
log.Info("Update not available")
os.Exit(0)
log.Fatal("Invalid response from UpdateHub Agent")
}
} else {
log.Fatal("Invalid response from UpdateHub Agent")

break
}

log.Info("Waiting for updatehub")
time.Sleep(time.Second)
}

d.Run()
Expand Down