runs and reports versions

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-11-24 23:22:52 -06:00
parent 4e0dc17202
commit 5d9eb5add6
2 changed files with 11 additions and 15 deletions

22
http.go
View File

@ -60,20 +60,15 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
} }
if route == "/status" { if route == "/status" {
if hostname == "" {
// ignore junk
log.Info("hostname was blank")
return
}
var packs *zoopb.Packages var packs *zoopb.Packages
packs = new(zoopb.Packages) packs = new(zoopb.Packages)
if err := packs.Unmarshal(msg); err != nil { if err := packs.Unmarshal(msg); err != nil {
log.Info("proto.Unmarshal() failed on wire message len", len(msg), "from", hostname) log.Info("/status proto.Unmarshal() failed on wire message len", len(msg), "from", hostname)
return return
} }
log.Info("Unmarshal worked with msg len", len(msg), "from", hostname) log.Info("/status Unmarshal worked with msg len", len(msg), "from", hostname)
log.Info(hostname, "has", packs.Len(), "packages installed") log.Info("/status hostname", hostname, "has", packs.Len(), "packages installed")
fmt.Fprintln(w, "upgrade") fmt.Fprintln(w, "upgrade")
return return
} }
@ -100,14 +95,11 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
if route == "/save" { if route == "/save" {
log.HttpMode(w) log.HttpMode(w)
defer log.HttpMode(nil) defer log.HttpMode(nil)
data, err := me.machines.Marshal() if err := me.machines.ConfigSave(); err == nil {
if err != nil { log.Log(NOW, "ConfigSave() ok")
log.Info("proto.Marshal() failed len", len(msg), err) } else {
return log.Log(NOW, "ConfigSave() failed", err)
} }
log.Info("proto.Marshal() worked len", len(msg))
// me.machines.ConfigSave()
zoopb.ConfigSaveRaw(data)
return return
} }

View File

@ -48,6 +48,10 @@ func main() {
me.hostname, _ = os.Hostname() me.hostname, _ = os.Hostname()
me.pollDelay = 10 * time.Second me.pollDelay = 10 * time.Second
me.machines = new(zoopb.Machines) me.machines = new(zoopb.Machines)
if err := me.machines.ConfigLoad(); err != nil {
log.Warn("load config failed", err)
os.Exit(-1)
}
me.targets = make(map[string]string) // keep track of what versions the machines should be running me.targets = make(map[string]string) // keep track of what versions the machines should be running
me.upgrade = make(map[string]bool) // used to trigger upgrade attempts me.upgrade = make(map[string]bool) // used to trigger upgrade attempts