// Copyright 2024 WIT.COM Inc Licensed GPL 3.0 package main import ( "os" "strings" "go.wit.com/lib/gui/shell" "go.wit.com/log" ) func pingStatus() error { var url string url = me.urlbase + "/status?hostname=" + me.machine.Hostname msg, err := me.machine.Packages.Marshal() if err != nil { log.Info("proto.Marshal() failed:", err) return err } log.Info("proto Marshal len =", len(msg)) body, err := httpPost(url, msg) if err != nil { log.Info("httpPost() failed:", err) return err } test := strings.TrimSpace(string(body)) // log.Info("virtigo returned body:", test) for _, line := range strings.Split(test, "\n") { switch line { case "upgrade": log.Info("should upgrade now") default: log.Info("GOT:", line) } } return nil } func sendMachine(s string) error { var url string url = me.urlbase + "/machine" msg, err := me.machine.Marshal() if err != nil { log.Info("proto.Marshal() failed:", err) return err } body, err := httpPost(url, msg) if err != nil { log.Info("httpPost() failed:", err) return err } test := strings.TrimSpace(string(body)) // log.Info("virtigo returned body:", test) for _, line := range strings.Split(test, "\n") { if line == "upgrade" { log.Info(s, "zookeeper is healthy", len(msg)) me.failcount = 0 } else if line == "kill" { os.Exit(0) } else if strings.HasPrefix(line, "apt update") { log.Info("machine upgrade now", line) shell.Run([]string{"apt", "update"}) shell.Run([]string{"apt", "install", "zood"}) log.Sleep(1) os.Exit(0) } else { log.Info(me.urlbase, "is maybe not working GOT:", line) log.Info(me.urlbase, "fail count", me.failcount, "from hostname", me.machine.Hostname) } } return nil }