zood/send.go

79 lines
1.8 KiB
Go
Raw Normal View History

2025-02-15 12:30:07 -06:00
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
2024-11-15 19:25:24 -06:00
package main
import (
"os"
2024-11-15 19:25:24 -06:00
"strings"
2024-11-16 13:51:25 -06:00
"go.wit.com/lib/gui/shell"
2024-11-15 19:25:24 -06:00
"go.wit.com/log"
)
func pingStatus() error {
var url string
2025-02-22 07:17:28 -06:00
url = me.urlbase + "/status?hostname=" + me.machine.Hostname
2025-02-16 12:02:47 -06:00
/*
2025-02-22 07:17:28 -06:00
msg, err := me.machine.Packages.Marshal()
2025-02-16 12:02:47 -06:00
if err != nil {
log.Info("proto.Marshal() failed:", err)
return err
}
log.Info("proto Marshal len =", len(msg))
*/
2025-02-22 07:17:28 -06:00
body, err := me.machine.HttpPostMachine(url)
2024-11-15 19:25:24 -06:00
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") {
2024-11-15 20:59:42 -06:00
switch line {
case "upgrade":
log.Info("should upgrade now")
default:
log.Info("GOT:", line)
}
}
return nil
}
func sendMachine(s string) error {
2024-11-15 20:59:42 -06:00
var url string
2024-11-18 20:22:12 -06:00
url = me.urlbase + "/machine"
2025-02-22 07:17:28 -06:00
body, err := me.machine.HttpPostMachine(url)
2024-11-15 20:59:42 -06:00
if err != nil {
2025-02-15 06:44:55 -06:00
log.Info("httpPost() failed: url", url)
2024-11-15 20:59:42 -06:00
log.Info("httpPost() failed:", err)
2025-02-16 12:02:47 -06:00
log.Info("httpPost() data:", string(body))
2024-11-15 20:59:42 -06:00
return err
}
2025-02-16 12:02:47 -06:00
out := strings.TrimSpace(string(body))
log.Info("httpPost() data:", out, len(body))
2024-11-15 20:59:42 -06:00
test := strings.TrimSpace(string(body))
// log.Info("virtigo returned body:", test)
for _, line := range strings.Split(test, "\n") {
if line == "upgrade" {
2025-02-16 12:02:47 -06:00
log.Info(s, "zookeeper is healthy")
2024-11-18 20:22:12 -06:00
me.failcount = 0
} else if line == "kill" {
os.Exit(0)
} else if strings.HasPrefix(line, "apt update") {
log.Info("machine upgrade now", line)
2024-11-16 13:51:25 -06:00
shell.Run([]string{"apt", "update"})
2024-11-17 06:04:24 -06:00
shell.Run([]string{"apt", "install", "zood"})
log.Sleep(1)
os.Exit(0)
} else {
2024-11-18 20:22:12 -06:00
log.Info(me.urlbase, "is maybe not working GOT:", line)
2025-02-22 07:17:28 -06:00
log.Info(me.urlbase, "fail count", me.failcount, "from hostname", me.machine.Hostname)
2024-11-15 20:59:42 -06:00
}
2024-11-15 19:25:24 -06:00
}
return nil
}