2024-11-15 19:25:24 -06:00
|
|
|
// Copyright 2024 WIT.COM Inc Licensed GPL 3.0
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-11-18 09:41:08 -06:00
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
2024-11-17 04:16:45 -06:00
|
|
|
var urlbase string = "http://zookeeper.grid.wit.com:8080"
|
2024-11-15 19:25:24 -06:00
|
|
|
|
|
|
|
func send() {
|
|
|
|
}
|
|
|
|
|
|
|
|
func pingStatus() error {
|
|
|
|
var url string
|
2024-11-15 20:59:42 -06:00
|
|
|
url = urlbase + "/status?hostname=" + me.hostname
|
2024-11-15 21:05:03 -06:00
|
|
|
msg, err := me.machine.Packages.Marshal()
|
2024-11-15 19:52:46 -06:00
|
|
|
if err != nil {
|
|
|
|
log.Info("proto.Marshal() failed:", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
log.Info("proto Marshal len =", len(msg))
|
|
|
|
body, err := httpPost(url, msg)
|
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
|
|
|
|
}
|
|
|
|
|
2024-11-18 09:41:08 -06:00
|
|
|
func sendMachine(s string) error {
|
2024-11-15 20:59:42 -06:00
|
|
|
var url string
|
|
|
|
url = 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") {
|
2024-11-18 09:41:08 -06:00
|
|
|
if line == "upgrade" {
|
|
|
|
log.Info(s, "zookeeper is healthy", len(msg))
|
|
|
|
} 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"})
|
2024-11-18 09:41:08 -06:00
|
|
|
log.Sleep(1)
|
|
|
|
os.Exit(0)
|
|
|
|
} else {
|
|
|
|
log.Info(urlbase, "is maybe not working GOT:", line)
|
2024-11-15 20:59:42 -06:00
|
|
|
}
|
2024-11-15 19:25:24 -06:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|