// Copyright 2017-2025 WIT.COM Inc. All rights reserved. // Use of this source code is governed by the 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 := me.machine.HttpPostMachine(url) 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" body, err := me.machine.HttpPostMachine(url) if err != nil { log.Info("httpPost() failed: url", url) log.Info("httpPost() failed:", err) log.Info("httpPost() data:", string(body)) return err } // out := strings.TrimSpace(string(body)) // log.Info("httpPost() data:", out, len(body)) test := strings.TrimSpace(string(body)) // log.Info("virtigo returned body:", test) for _, line := range strings.Split(test, "\n") { if line == "good" { log.Info(s, "zookeeper is healthy") me.failcount = 0 } else if line == "kill" { os.Exit(0) } else if strings.HasPrefix(line, "apt update") { log.Info("machine upgrade now", line) shell.RunRealtime([]string{"mv", "-f", "/usr/bin/zood", "/usr/bin/zood.last"}) shell.RunRealtime([]string{"apt", "update"}) shell.RunRealtime([]string{"apt", "install", "zood"}) if shell.Exists("/usr/bin/zood") { shell.RunRealtime([]string{"rm", "-f", "/usr/bin/zood.last"}) } else { // there is not a new version of the binary. move the old one back shell.RunRealtime([]string{"mv", "-f", "/usr/bin/zood.last", "/usr/bin/zood"}) } os.Exit(0) } else if strings.HasPrefix(line, "apt install") { log.Info("Got to apt install", line) parts := strings.Fields(line) if len(parts) > 1 { cmd := []string{"apt"} cmd = append(cmd, parts[1:]...) log.Info("Got to parts =", parts) log.Info("Got to cmd =", cmd) shell.RunRealtime(cmd) } else { log.Info("nothing to install for line:", line) } } 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 }