keep working towards update working

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-11-18 09:41:08 -06:00
parent 769c9757b7
commit b71fec22c8
3 changed files with 20 additions and 19 deletions

8
apt.go
View File

@ -28,7 +28,7 @@ func initPackages() {
} }
} }
log.Info(me.hostname, "has distro", me.distro, "with", me.machine.Packages.Len(), "packages installed") log.Info(me.hostname, "has distro", me.distro, "with", me.machine.Packages.Len(), "packages installed.")
} }
func addNew(name string, version string) bool { func addNew(name string, version string) bool {
@ -38,12 +38,12 @@ func addNew(name string, version string) bool {
return me.machine.Packages.Append(new1) return me.machine.Packages.Append(new1)
} }
func updatePackages() { func updatePackages() string {
// Get the list of installed packages for the detected distro // Get the list of installed packages for the detected distro
newP, err := getPackageList(me.distro) newP, err := getPackageList(me.distro)
if err != nil { if err != nil {
fmt.Println("Error:", err) fmt.Println("Error:", err)
return return fmt.Sprintln("getPackageList()", err)
} }
var newCounter, changeCounter int var newCounter, changeCounter int
@ -69,5 +69,5 @@ func updatePackages() {
if newCounter != 0 { if newCounter != 0 {
footer += fmt.Sprintf(" (%d new)", newCounter) footer += fmt.Sprintf(" (%d new)", newCounter)
} }
log.Info(footer) return footer
} }

21
send.go
View File

@ -3,6 +3,7 @@
package main package main
import ( import (
"os"
"strings" "strings"
"go.wit.com/lib/gui/shell" "go.wit.com/lib/gui/shell"
@ -42,7 +43,7 @@ func pingStatus() error {
return nil return nil
} }
func sendMachine() error { func sendMachine(s string) error {
var url string var url string
url = urlbase + "/machine" url = urlbase + "/machine"
msg, err := me.machine.Marshal() msg, err := me.machine.Marshal()
@ -50,7 +51,6 @@ func sendMachine() error {
log.Info("proto.Marshal() failed:", err) log.Info("proto.Marshal() failed:", err)
return err return err
} }
log.Info("proto Marshal len =", len(msg))
body, err := httpPost(url, msg) body, err := httpPost(url, msg)
if err != nil { if err != nil {
log.Info("httpPost() failed:", err) log.Info("httpPost() failed:", err)
@ -60,15 +60,18 @@ func sendMachine() error {
test := strings.TrimSpace(string(body)) test := strings.TrimSpace(string(body))
// log.Info("virtigo returned body:", test) // log.Info("virtigo returned body:", test)
for _, line := range strings.Split(test, "\n") { for _, line := range strings.Split(test, "\n") {
switch line { if line == "upgrade" {
case "upgrade": log.Info(s, "zookeeper is healthy", len(msg))
log.Info("zookeeper is healthy") } else if line == "kill" {
case "apt update": os.Exit(0)
log.Info("machine upgrade now") } else if strings.HasPrefix(line, "apt update") {
log.Info("machine upgrade now", line)
shell.Run([]string{"apt", "update"}) shell.Run([]string{"apt", "update"})
shell.Run([]string{"apt", "install", "zood"}) shell.Run([]string{"apt", "install", "zood"})
default: log.Sleep(1)
log.Info("zookeeper is maybe not working GOT:", line) os.Exit(0)
} else {
log.Info(urlbase, "is maybe not working GOT:", line)
} }
} }
return nil return nil

View File

@ -3,8 +3,6 @@ package main
import ( import (
"fmt" "fmt"
"time" "time"
"go.wit.com/log"
) )
// timeFunction takes a function as an argument and returns the execution time. // timeFunction takes a function as an argument and returns the execution time.
@ -30,11 +28,11 @@ func NewWatchdog() {
case <-done: case <-done:
fmt.Println("Done!") fmt.Println("Done!")
return return
case t := <-me.dog.C: case _ = <-me.dog.C:
log.Info("Watchdog() ticked", me.zookeeper, "Current time: ", t) // log.Info("Watchdog() ticked", me.zookeeper, "Current time: ", t)
updatePackages() s := updatePackages()
// pingStatus() // pingStatus()
sendMachine() sendMachine(s)
// h.pollHypervisor() // h.pollHypervisor()
// h.Scan() // h.Scan()
} }