Compare commits
No commits in common. "master" and "v0.0.1" have entirely different histories.
35
Makefile
35
Makefile
|
@ -7,24 +7,12 @@ BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
|
|||
# REDOMOD = $(shell if [ -e go.mod ]; then echo go.mod; else echo no go mod; fi)
|
||||
REDOMOD = $(shell if [ -e go.sum ]; then echo go.sum exists; else GO111MODULE= go mod init; GO111MODULE= go mod tidy; fi)
|
||||
|
||||
all: goimports gocui-debugging
|
||||
# ./zookeeper
|
||||
all: build
|
||||
#./zookeeper
|
||||
./zookeeper --version
|
||||
|
||||
vet:
|
||||
@GO111MODULE=off go vet
|
||||
@echo this go binary package builds okay
|
||||
|
||||
nogui:
|
||||
./zookeeper --gui nocui
|
||||
|
||||
gocui: build
|
||||
./zookeeper --gui gocui
|
||||
|
||||
gocui-debugging: build
|
||||
./zookeeper --gui gocui --gui-file ~/go/src/go.wit.com/toolkits/gocui/gocui.so >/tmp/forge.log 2>&1
|
||||
|
||||
build: goimports vet
|
||||
GO111MODULE=off go build -v -x \
|
||||
build:
|
||||
GO111MODULE=off go build \
|
||||
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
|
||||
|
||||
install:
|
||||
|
@ -38,7 +26,7 @@ release-build:
|
|||
|
||||
# makes a .deb package
|
||||
debian:
|
||||
go-deb --auto --repo go.wit.com/apps/zookeeper
|
||||
go-deb --no-gui --repo go.wit.com/apps/zookeeper
|
||||
|
||||
goimports:
|
||||
goimports -w *.go
|
||||
|
@ -51,18 +39,11 @@ redomod:
|
|||
clean:
|
||||
rm -f go.*
|
||||
rm -f zookeeper
|
||||
go-mod-clean --purge
|
||||
|
||||
# git clone the sources and all the golang dependancies into ~/go/src
|
||||
# if you don't have go-clone, you can get it from http://go.wit.com/
|
||||
git-clone:
|
||||
go-clone --recursive go.wit.com/apps/zookeeper
|
||||
|
||||
http-toogle-ZOOD:
|
||||
curl --silent http://localhost:8080/flag?flag=ZOOD
|
||||
|
||||
http-list-machines:
|
||||
curl --silent http://localhost:8080/list
|
||||
|
||||
http-uptime:
|
||||
curl --silent http://localhost:8080/uptime
|
||||
http-list-packages:
|
||||
curl --silent http://localhost:2521/list?hostname=zookeeper.wit.com
|
||||
|
|
47
apt.go
47
apt.go
|
@ -1,6 +1,3 @@
|
|||
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
||||
// Use of this source code is governed by the GPL 3.0
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
@ -24,15 +21,53 @@ func initPackages() {
|
|||
new1 := new(zoopb.Package)
|
||||
new1.Name = pkg
|
||||
new1.Version = version
|
||||
me.packages.Append(new1)
|
||||
if me.packages.Append(new1) {
|
||||
// log.Info("added", new1.Name, "ok")
|
||||
} else {
|
||||
log.Info("added", new1.Name, "failed")
|
||||
}
|
||||
}
|
||||
|
||||
log.Info(me.hostname, "has distro", me.distro, "with", me.packages.Len(), "packages installed")
|
||||
}
|
||||
|
||||
func addNew(name string, version string) {
|
||||
func addNew(name string, version string) bool {
|
||||
new1 := new(zoopb.Package)
|
||||
new1.Name = name
|
||||
new1.Version = version
|
||||
me.packages.Append(new1)
|
||||
return me.packages.Append(new1)
|
||||
}
|
||||
|
||||
func updatePackages() {
|
||||
// Get the list of installed packages for the detected distro
|
||||
newP, err := getPackageList(me.distro)
|
||||
if err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
return
|
||||
}
|
||||
|
||||
var newCounter, changeCounter int
|
||||
// Print the installed packages and their versions
|
||||
for pkg, version := range newP {
|
||||
found := me.packages.FindByName(pkg)
|
||||
if found == nil {
|
||||
log.Info("adding new", pkg, version)
|
||||
addNew(pkg, version)
|
||||
newCounter += 1
|
||||
} else {
|
||||
found.Version = version
|
||||
if me.packages.Update(found) {
|
||||
changeCounter += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
footer := fmt.Sprintf("%s has distro %s with %d packages installed",me.hostname, me.distro, me.packages.Len())
|
||||
if changeCounter != 0 {
|
||||
footer += fmt.Sprintf(" (%d changed)", changeCounter)
|
||||
}
|
||||
if newCounter != 0 {
|
||||
footer += fmt.Sprintf(" (%d new)", newCounter)
|
||||
}
|
||||
log.Info(footer)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
||||
// Use of this source code is governed by the GPL 3.0
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
|
29
argv.go
29
argv.go
|
@ -1,6 +1,3 @@
|
|||
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
||||
// Use of this source code is governed by the GPL 3.0
|
||||
|
||||
package main
|
||||
|
||||
/*
|
||||
|
@ -9,44 +6,26 @@ package main
|
|||
*/
|
||||
|
||||
import (
|
||||
"go.wit.com/log"
|
||||
"go.wit.com/dev/alexflint/arg"
|
||||
)
|
||||
|
||||
var argv args
|
||||
|
||||
type args struct {
|
||||
Verbose bool `arg:"--verbose" default:"false" help:"talk more"`
|
||||
Daemon bool `arg:"--daemon" default:"false" help:"run in daemon mode"`
|
||||
Port int `arg:"--port" default:"8080" help:"port to run on"`
|
||||
Daemon bool `arg:"--daemon" default:"false" help:"run in daemon mode"`
|
||||
Port int `arg:"--port" default:"2521" help:"port to run on"`
|
||||
}
|
||||
|
||||
func (args) Version() string {
|
||||
return "zookeeper " + VERSION + " Built on: " + BUILDTIME
|
||||
return "zood " + VERSION + " Built on: " + BUILDTIME
|
||||
}
|
||||
|
||||
/*
|
||||
func init() {
|
||||
arg.MustParse(&argv)
|
||||
}
|
||||
*/
|
||||
|
||||
func (a args) Description() string {
|
||||
return `
|
||||
this daemon talks to zookeeper
|
||||
`
|
||||
}
|
||||
|
||||
var NOW *log.LogFlag
|
||||
var INFO *log.LogFlag
|
||||
var ZOOD *log.LogFlag
|
||||
var WARN *log.LogFlag
|
||||
|
||||
func init() {
|
||||
full := "go.wit.com/apps/zookeeper"
|
||||
short := "zookeeper"
|
||||
|
||||
NOW = log.NewFlag("NOW", true, full, short, "useful while doing debugging")
|
||||
INFO = log.NewFlag("INFO", false, full, short, "general zookeeper")
|
||||
ZOOD = log.NewFlag("ZOOD", false, full, short, "show reporting from zood")
|
||||
WARN = log.NewFlag("WARN", true, full, short, "bad things")
|
||||
}
|
||||
|
|
15
control
15
control
|
@ -1,15 +1,8 @@
|
|||
Source: zookeeper-go
|
||||
Source: zood
|
||||
Build-Depends: golang
|
||||
Package: zookeeper-go
|
||||
Conflicts: zookeeper
|
||||
Breaks: zookeeper
|
||||
Replaces: zookeeper
|
||||
Package: zood
|
||||
Maintainer: Jeff Carr <jcarr@wit.com>
|
||||
Architecture: amd64
|
||||
Depends:
|
||||
URL: https://go.wit.com/apps/zookeeper
|
||||
Description: zookeeper for homelab grids
|
||||
keeps track of things in a grid. Maybe
|
||||
this is similar to the apache project by
|
||||
the same name, but in any case, this is
|
||||
customized for the grid here at WIT
|
||||
URL: https://go.wit.com/lib/daemons/zood
|
||||
Description: the zookeeper daemon
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
// Copyright 2016 The go-qemu Authors.
|
||||
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
||||
// Use of this source code is governed by the GPL 3.0
|
||||
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
|
|
88
doGui.go
88
doGui.go
|
@ -1,88 +0,0 @@
|
|||
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
||||
// Use of this source code is governed by the GPL 3.0
|
||||
|
||||
package main
|
||||
|
||||
// An app to submit patches for the 30 GO GUI repos
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"go.wit.com/gui"
|
||||
"go.wit.com/lib/gadgets"
|
||||
"go.wit.com/lib/protobuf/zoopb"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
// refresh the windows & tables the user has open
|
||||
func refresh() {
|
||||
if argv.Verbose {
|
||||
log.Info("zookeeper scan here")
|
||||
}
|
||||
if me.zood != nil {
|
||||
me.zood.doMachinesUpgradeTable(me.machines)
|
||||
all := me.machines.All()
|
||||
for all.Scan() {
|
||||
m := all.Next()
|
||||
if me.hostname == m.Hostname {
|
||||
// this is me! This is the version of zood that should be installed everywhere
|
||||
v := findVersion(m, "zood")
|
||||
me.zood.version = v
|
||||
me.zood.versionL.SetText(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func doGui() {
|
||||
me.myGui = gui.New()
|
||||
me.myGui.InitEmbed(resources)
|
||||
me.myGui.Default()
|
||||
|
||||
win := gadgets.RawBasicWindow("Zookeeper: (inventory your cluster)")
|
||||
win.Make()
|
||||
win.Show()
|
||||
win.Custom = func() {
|
||||
log.Warn("Main window close")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
box := win.Box()
|
||||
|
||||
vbox := box.NewVerticalBox("BOX2")
|
||||
|
||||
group1 := vbox.NewGroup("Zookeeper Settings")
|
||||
grid := group1.NewGrid("buildOptions", 0, 0)
|
||||
|
||||
grid.NewButton("zood versions", func() {
|
||||
// if the window exists, just toggle it open or closed
|
||||
if me.zood != nil {
|
||||
me.zood.Toggle()
|
||||
return
|
||||
}
|
||||
me.zood = makeZoodWin()
|
||||
})
|
||||
|
||||
grid.NewButton("Cluster Events", func() {
|
||||
log.Info("todo: start a list here!")
|
||||
})
|
||||
|
||||
// sit here forever refreshing the GUI
|
||||
for {
|
||||
refresh()
|
||||
time.Sleep(90 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func saveMachineState() {
|
||||
cur := zoopb.NewMachines()
|
||||
|
||||
all := me.machines.SortByHostname()
|
||||
for all.Scan() {
|
||||
m := all.Next()
|
||||
log.Info("have machine:", m.Hostname)
|
||||
cur.Append(m)
|
||||
}
|
||||
cur.ConfigSave()
|
||||
}
|
105
http.go
105
http.go
|
@ -1,12 +1,10 @@
|
|||
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
||||
// Use of this source code is governed by the GPL 3.0
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"go.wit.com/log"
|
||||
|
@ -19,89 +17,70 @@ func cleanURL(url string) string {
|
|||
}
|
||||
|
||||
func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||
// log.Info("Got URL Path: ", r.URL.Path)
|
||||
log.Info("Got URL Path: ", r.URL.Path)
|
||||
route := cleanURL(r.URL.Path)
|
||||
|
||||
hostname := r.URL.Query().Get("hostname")
|
||||
// flag := r.URL.Query().Get("flag")
|
||||
domname := r.URL.Query().Get("domain")
|
||||
|
||||
msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte
|
||||
if err != nil {
|
||||
log.Info("ReadAll() error =", err)
|
||||
fmt.Fprintln(w, "ReadAll() error =", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Info("Got URL msg:", string(msg))
|
||||
if route == "/" {
|
||||
fmt.Fprintln(w, "OK")
|
||||
return
|
||||
}
|
||||
|
||||
if route == "/machine" {
|
||||
handleMachine(r, w, hostname, msg)
|
||||
// exit the virtigo daemon & have systemd restart it
|
||||
// this can happen & when it does, access to
|
||||
// to libvirtd will hang (aka: virsh list will hang)
|
||||
// One way to trigger this is to not properly close
|
||||
// domain sockets opened from go-qemu/hypervisor
|
||||
// it's a good idea in any case so leave it here
|
||||
if route == "/kill" {
|
||||
log.Warn("KILLED")
|
||||
fmt.Fprintln(w, "KILLED")
|
||||
os.Exit(-1)
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
if route == "/status" {
|
||||
var packs *zoopb.Packages
|
||||
packs = new(zoopb.Packages)
|
||||
if err := packs.Unmarshal(msg); err != nil {
|
||||
log.Info("/status proto.Unmarshal() failed on wire message len", len(msg), "from", hostname)
|
||||
return
|
||||
}
|
||||
// curl http://localhost:2520/import?domain=foo.bar.com
|
||||
if route == "/import" {
|
||||
fmt.Fprint(w, "import domain:", domname)
|
||||
|
||||
log.Info("/status Unmarshal worked with msg len", len(msg), "from", hostname)
|
||||
log.Info("/status hostname", hostname, "has", packs.Len(), "packages installed")
|
||||
fmt.Fprintln(w, "upgrade")
|
||||
return
|
||||
}
|
||||
*/
|
||||
return
|
||||
}
|
||||
|
||||
// list out the machines and thier version of zood
|
||||
/*
|
||||
if route == "/list" {
|
||||
log.HttpMode(w)
|
||||
defer log.HttpMode(nil)
|
||||
loop := me.machines.SortByHostname()
|
||||
for loop.Scan() {
|
||||
m := loop.Next()
|
||||
zood := m.Packages.FindByName("zood")
|
||||
v := me.targets["zood"] // this is the target version
|
||||
if zood == nil {
|
||||
log.Info("machine", m.Hostname, "does not have zood installed")
|
||||
} else {
|
||||
log.Info(fmt.Sprintf("zood version %s vs target version %s on machine %s", zood.Version, v, m.Hostname))
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
*/
|
||||
|
||||
if route == "/uptime" {
|
||||
if me.zood == nil {
|
||||
fmt.Fprintf(w, "BAD zood == nil\n")
|
||||
return
|
||||
}
|
||||
var count int
|
||||
var bad int
|
||||
all := me.machines.All()
|
||||
for all.Scan() {
|
||||
m := all.Next()
|
||||
count += 1
|
||||
if findVersion(m, "zood") != me.zood.version {
|
||||
bad += 1
|
||||
}
|
||||
}
|
||||
if bad == 0 {
|
||||
fmt.Fprintf(w, "GOOD machine count=(%d) all machines are version %s\n", count, me.zood.version)
|
||||
} else {
|
||||
fmt.Fprintf(w, "BAD machine count=(%d) upgrade=(%d) to %s\n", count, bad, me.zood.version)
|
||||
}
|
||||
if route == "/favicon.ico" {
|
||||
writeFile(w, "ipv6.png")
|
||||
return
|
||||
}
|
||||
|
||||
log.Warn("BAD URL =", route)
|
||||
}
|
||||
|
||||
func writeFile(w http.ResponseWriter, filename string) {
|
||||
// fmt.Fprintln(w, "GOT TEST?")
|
||||
fullname := "resources/" + filename
|
||||
pfile, err := resources.ReadFile(fullname)
|
||||
if err != nil {
|
||||
log.Println("ERROR:", err)
|
||||
// w.Write(pfile)
|
||||
return
|
||||
}
|
||||
|
||||
var repohtml string
|
||||
repohtml = string(pfile)
|
||||
if filename == "goReference.svg" {
|
||||
w.Header().Set("Content-Type", "image/svg+xml")
|
||||
}
|
||||
fmt.Fprintln(w, repohtml)
|
||||
log.Println("writeFile() found internal file:", filename)
|
||||
}
|
||||
|
||||
// starts and sits waiting for HTTP requests
|
||||
func startHTTP() {
|
||||
http.HandleFunc("/", okHandler)
|
||||
|
|
83
httpDump.go
83
httpDump.go
|
@ -1,83 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func dumpRemoteAddr(r *http.Request) string {
|
||||
return r.RemoteAddr
|
||||
}
|
||||
|
||||
func dumpUserAgent(r *http.Request) string {
|
||||
var all string
|
||||
for param, values := range r.URL.Query() {
|
||||
for _, value := range values {
|
||||
all += fmt.Sprint(" Query:", param, value)
|
||||
}
|
||||
}
|
||||
// hostname := r.URL.Query().Get("hostname")
|
||||
return r.UserAgent() + all
|
||||
}
|
||||
|
||||
func dumpClient(r *http.Request) {
|
||||
/*
|
||||
var host, url, proto, addr, agent string
|
||||
|
||||
host = r.Host
|
||||
url = r.URL.String()
|
||||
proto = r.Proto
|
||||
addr = r.RemoteAddr
|
||||
agent = r.UserAgent()
|
||||
|
||||
log.Warn(host, proto, addr, url, agent)
|
||||
|
||||
fmt.Fprintln(accessf, time.Now(), host, proto, addr, url, agent)
|
||||
// return
|
||||
|
||||
fmt.Fprintln(clientf)
|
||||
fmt.Fprintln(clientf, time.Now())
|
||||
// Basic request information
|
||||
fmt.Fprintln(clientf, "Method:", r.Method)
|
||||
fmt.Fprintln(clientf, "URL:", r.URL)
|
||||
fmt.Fprintln(clientf, "Protocol:", r.Proto)
|
||||
fmt.Fprintln(clientf, "Host:", r.Host)
|
||||
fmt.Fprintln(clientf, "Remote Address:", r.RemoteAddr)
|
||||
|
||||
// Headers
|
||||
fmt.Fprintln(clientf, "Headers:")
|
||||
for name, values := range r.Header {
|
||||
for _, value := range values {
|
||||
fmt.Fprintln(clientf, "Headers:", name, value)
|
||||
}
|
||||
}
|
||||
|
||||
// Query parameters
|
||||
fmt.Fprintln(clientf, "Query Parameters:")
|
||||
for param, values := range r.URL.Query() {
|
||||
for _, value := range values {
|
||||
fmt.Fprintln(clientf, "Query:", param, value)
|
||||
}
|
||||
}
|
||||
|
||||
// User-Agent
|
||||
fmt.Fprintln(clientf, "User-Agent:", r.UserAgent())
|
||||
|
||||
// Content Length
|
||||
fmt.Fprintln(clientf, "Content Length:", r.ContentLength)
|
||||
|
||||
// Cookies
|
||||
fmt.Fprintln(clientf, "Cookies:")
|
||||
for _, cookie := range r.Cookies() {
|
||||
fmt.Fprintln(clientf, cookie.Name, cookie.Value)
|
||||
}
|
||||
|
||||
// Request Body (if applicable)
|
||||
if r.Body != nil {
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err == nil {
|
||||
fmt.Fprintln(clientf, "Body:", string(body))
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
143
machine.go
143
machine.go
|
@ -1,143 +0,0 @@
|
|||
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
||||
// Use of this source code is governed by the GPL 3.0
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go.wit.com/lib/protobuf/zoopb"
|
||||
"go.wit.com/log"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
func rawGetHostname(data []byte) *zoopb.Machine {
|
||||
newm := new(zoopb.Machine)
|
||||
newm.Unmarshal(data)
|
||||
return newm
|
||||
}
|
||||
|
||||
func handleMachine(r *http.Request, w http.ResponseWriter, hostname string, data []byte) {
|
||||
hostname = strings.TrimSpace(hostname)
|
||||
newm := rawGetHostname(data)
|
||||
if newm == nil {
|
||||
log.Info("unmarshal failed on data len =", len(data))
|
||||
}
|
||||
if hostname != newm.Hostname {
|
||||
// log.Info("hostname mismatch", hostname, "vs", newm.Hostname)
|
||||
hostname = newm.Hostname
|
||||
}
|
||||
|
||||
if hostname == "" {
|
||||
ua := dumpUserAgent(r)
|
||||
ra := dumpRemoteAddr(r)
|
||||
log.Info("hostname is blank even after unmarshal. data len =", len(data), ra, ua, newm.Cpus, newm.Hostname)
|
||||
return
|
||||
}
|
||||
// log.Info("lookoing for", hostname)
|
||||
m := me.machines.FindByHostname(hostname)
|
||||
if m == nil {
|
||||
am := new(zoopb.Machine)
|
||||
am.Hostname = newm.Hostname
|
||||
am.Memory = newm.Memory
|
||||
// me.machines2.Append(am)
|
||||
me.machines.Append(newm)
|
||||
log.Info("new machine", am.Hostname, am.Memory)
|
||||
return
|
||||
}
|
||||
ua := dumpUserAgent(r)
|
||||
ra := dumpRemoteAddr(r)
|
||||
if m.UserAgent != ua {
|
||||
log.Info("hostname ua changed len =", len(data), ra, hostname, ua)
|
||||
m.UserAgent = ua
|
||||
}
|
||||
if m.Upgrade {
|
||||
log.Info(m.Hostname, "was told to upgrade zood")
|
||||
fmt.Fprintln(w, "apt update")
|
||||
m.Upgrade = false
|
||||
} else {
|
||||
fmt.Fprintln(w, "good")
|
||||
}
|
||||
// log.Info("update machine protobuf", hostname)
|
||||
updateMachine(newm)
|
||||
}
|
||||
|
||||
// someone sent machine 'u' is it new?
|
||||
// if not, update the record of it
|
||||
func updateMachine(u *zoopb.Machine) string {
|
||||
if u == nil {
|
||||
return "nil"
|
||||
}
|
||||
m := me.machines.FindByHostname(u.Hostname)
|
||||
if m == nil {
|
||||
log.Info("adding new machine", u.Hostname)
|
||||
me.machines.Append(u)
|
||||
if me.zood == nil {
|
||||
// do nothing. window has not been opened
|
||||
} else {
|
||||
me.zood.doMachinesUpgradeTable(me.machines)
|
||||
}
|
||||
saveMachineState()
|
||||
return "new"
|
||||
}
|
||||
// log.Info("updating machine", m.Hostname)
|
||||
|
||||
// did the # of cpus change?
|
||||
if m.Cpus != u.Cpus {
|
||||
m.Cpus = u.Cpus
|
||||
log.Info("cpus changed to", m.Cpus)
|
||||
}
|
||||
|
||||
// did the memory change?
|
||||
if m.Memory != u.Memory {
|
||||
m.Memory = u.Memory
|
||||
log.Info("memory changed to", m.Memory)
|
||||
}
|
||||
|
||||
// init these if nil
|
||||
if m.Packages == nil {
|
||||
m.Packages = new(zoopb.Packages)
|
||||
}
|
||||
if u.Packages == nil {
|
||||
u.Packages = new(zoopb.Packages)
|
||||
}
|
||||
if zood := m.Packages.FindByName("zood"); zood != nil {
|
||||
log.Log(INFO, m.Hostname, "has zood version", zood.Version)
|
||||
}
|
||||
m.Laststamp = timestamppb.New(time.Now())
|
||||
|
||||
updatePackages(m, u.Packages)
|
||||
return "upgrade"
|
||||
}
|
||||
|
||||
// looks to see if any packages:
|
||||
// changed versions
|
||||
// were newly installed
|
||||
// were uninstalled
|
||||
func updatePackages(m *zoopb.Machine, newp *zoopb.Packages) bool {
|
||||
var changed bool = false
|
||||
|
||||
loop := newp.SortByName()
|
||||
for loop.Scan() {
|
||||
p := loop.Next()
|
||||
if p.Name == "zood" {
|
||||
if pold := m.Packages.FindByName("zood"); pold == nil {
|
||||
changed = true
|
||||
log.Log(ZOOD, "updatePackages() new package", p.Name, "version", p.Version, "machine", m.Hostname)
|
||||
m.Packages.Append(p)
|
||||
} else {
|
||||
if p.Version == pold.Version {
|
||||
log.Log(ZOOD, "updatePackages() unchanged", p.Version, "machine", m.Hostname)
|
||||
} else {
|
||||
changed = true
|
||||
log.Log(NOW, "updatePackages() package", p.Name, "version changed", pold.Version, "to", p.Version, "machine", m.Hostname)
|
||||
pold.Version = p.Version
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return changed
|
||||
}
|
47
main.go
47
main.go
|
@ -1,5 +1,16 @@
|
|||
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
||||
// Use of this source code is governed by the GPL 3.0
|
||||
// Copyright 2016 The go-qemu Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
|
@ -9,7 +20,6 @@ import (
|
|||
"time"
|
||||
|
||||
"go.wit.com/dev/alexflint/arg"
|
||||
"go.wit.com/gui"
|
||||
"go.wit.com/lib/protobuf/zoopb"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
@ -22,7 +32,6 @@ var resources embed.FS
|
|||
|
||||
func main() {
|
||||
var pp *arg.Parser
|
||||
gui.InitArg()
|
||||
pp = arg.MustParse(&argv)
|
||||
|
||||
if pp == nil {
|
||||
|
@ -35,27 +44,19 @@ func main() {
|
|||
log.DaemonMode(true)
|
||||
}
|
||||
|
||||
me = new(zookeep)
|
||||
me = new(stuff)
|
||||
me.zookeeper = "zookeeper.wit.com"
|
||||
me.hostname, _ = os.Hostname()
|
||||
me.pollDelay = time.Hour
|
||||
me.machines = zoopb.NewMachines()
|
||||
// me.machines2 = zoopb.NewMachines()
|
||||
if err := me.machines.ConfigLoad(); err != nil {
|
||||
log.Warn("load config failed", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
/*
|
||||
if err := me.machines2.ConfigLoad(); err != nil {
|
||||
log.Warn("load config failed", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
*/
|
||||
// me.targets = make(map[string]string) // keep track of what versions the machines should be running
|
||||
me.upgrade = make(map[string]bool) // used to trigger upgrade attempts
|
||||
me.pollDelay = 3 * time.Second
|
||||
|
||||
// what OS?
|
||||
me.distro = initDistro()
|
||||
|
||||
// init the installed package list
|
||||
me.packages = new(zoopb.Packages)
|
||||
initPackages()
|
||||
|
||||
go NewWatchdog()
|
||||
|
||||
go startHTTP()
|
||||
|
||||
doGui()
|
||||
startHTTP()
|
||||
}
|
||||
|
|
6
postinst
6
postinst
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
systemctl enable zookeeper.service
|
||||
systemctl stop zookeeper.service
|
||||
systemctl start zookeeper.service
|
||||
systemctl enable zood.service
|
||||
systemctl stop zood.service
|
||||
systemctl start zood.service
|
||||
|
|
22
structs.go
22
structs.go
|
@ -1,33 +1,19 @@
|
|||
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
||||
// Use of this source code is governed by the GPL 3.0
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.wit.com/gui"
|
||||
"go.wit.com/lib/gadgets"
|
||||
"go.wit.com/lib/protobuf/zoopb"
|
||||
)
|
||||
|
||||
var me *zookeep
|
||||
var me *stuff
|
||||
|
||||
// this app's variables
|
||||
type zookeep struct {
|
||||
hostname string // my fqdn dns zookeeper hostname
|
||||
type stuff struct {
|
||||
hostname string // my hostname to send to zookeeper
|
||||
zookeeper string // the dns name for the zookeeper
|
||||
pollDelay time.Duration // how often to report our status
|
||||
dog *time.Ticker // the watchdog timer
|
||||
dogchan chan bool // can kill the watchdog
|
||||
distro string // debian,redhat,gentoo,macos,wincrap
|
||||
packages *zoopb.Packages // installed packages and versions
|
||||
machines *zoopb.Machines // every machine that has reported itself to the zookeeper
|
||||
// machines2 *zoopb.Machines // every machine that has reported itself to the zookeeper
|
||||
targets map[string]string // what versions the machines should be running
|
||||
upgrade map[string]bool // use this to trigger builds
|
||||
myGui *gui.Node // the gui toolkit handle
|
||||
machinesWin *gadgets.GenericWindow // the machines gui window
|
||||
machinesBox *gui.Node // the machines gui parent box widget
|
||||
machinesTB *zoopb.MachinesTable // the machines gui table buffer
|
||||
zood *stdTableWin // the zood version window
|
||||
}
|
||||
|
|
32
watchdog.go
32
watchdog.go
|
@ -1,6 +1,3 @@
|
|||
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
||||
// Use of this source code is governed by the GPL 3.0
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
@ -17,18 +14,10 @@ func TimeFunction(f func()) time.Duration {
|
|||
return time.Since(startTime) // Calculate the elapsed time
|
||||
}
|
||||
|
||||
func shutdownDog() {
|
||||
// this example would exit/destroy the ticker in 10 seconds
|
||||
go func() {
|
||||
time.Sleep(10 * time.Second)
|
||||
me.dogchan <- true
|
||||
}()
|
||||
}
|
||||
|
||||
func NewWatchdog() {
|
||||
me.dog = time.NewTicker(me.pollDelay)
|
||||
defer me.dog.Stop()
|
||||
me.dogchan = make(chan bool)
|
||||
done := make(chan bool)
|
||||
/*
|
||||
// this example would exit/destroy the ticker in 10 seconds
|
||||
go func() {
|
||||
|
@ -38,25 +27,12 @@ func NewWatchdog() {
|
|||
*/
|
||||
for {
|
||||
select {
|
||||
case <-me.dogchan:
|
||||
case <-done:
|
||||
fmt.Println("Done!")
|
||||
return
|
||||
case t := <-me.dog.C:
|
||||
// log.Info("zookeeper Watchdog() ticked", me.hostname, "Current time: ", t)
|
||||
var counter int
|
||||
loop := me.machines.SortByHostname()
|
||||
for loop.Scan() {
|
||||
m := loop.Next()
|
||||
counter += 1
|
||||
zood := m.Packages.FindByName("zood")
|
||||
if zood == nil {
|
||||
log.Info("machine", m.Hostname, "does not have zood installed")
|
||||
} else {
|
||||
// log.Info("know about machine", m.Hostname, "zood version", zood.Version)
|
||||
}
|
||||
}
|
||||
log.Info("hour watchdog:", counter, "machines. Current time:", t)
|
||||
|
||||
log.Info("Watchdog() ticked", me.zookeeper, "Current time: ", t)
|
||||
updatePackages()
|
||||
// h.pollHypervisor()
|
||||
// h.Scan()
|
||||
}
|
||||
|
|
161
windowZood.go
161
windowZood.go
|
@ -1,161 +0,0 @@
|
|||
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
||||
// Use of this source code is governed by the GPL 3.0
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.wit.com/gui"
|
||||
"go.wit.com/lib/gadgets"
|
||||
"go.wit.com/lib/protobuf/zoopb"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
type stdTableWin struct {
|
||||
sync.Mutex
|
||||
win *gadgets.GenericWindow // the machines gui window
|
||||
box *gui.Node // the machines gui parent box widget
|
||||
TB *zoopb.MachinesTable // the machines gui table buffer
|
||||
version string // the current zood version
|
||||
versionL *gui.Node // label widget to display the current zood version
|
||||
update bool // if the window should be updated
|
||||
}
|
||||
|
||||
func (w *stdTableWin) Toggle() {
|
||||
if w == nil {
|
||||
return
|
||||
}
|
||||
if w.win == nil {
|
||||
return
|
||||
}
|
||||
w.win.Toggle()
|
||||
}
|
||||
|
||||
func makeZoodWin() *stdTableWin {
|
||||
zood := new(stdTableWin)
|
||||
zood.win = gadgets.NewGenericWindow("zood daemon versions", "todo: add global controls here")
|
||||
zood.win.Custom = func() {
|
||||
log.Info("test delete window here")
|
||||
}
|
||||
grid := zood.win.Group.RawGrid()
|
||||
grid.NewButton("save machines.pb", func() {
|
||||
saveMachineState()
|
||||
})
|
||||
grid.NewButton("show active", func() {
|
||||
zood.doMachinesUpgradeTable(me.machines)
|
||||
})
|
||||
grid.NewButton("refresh", func() {
|
||||
refresh()
|
||||
})
|
||||
zood.versionL = grid.NewLabel("scan")
|
||||
grid.NewButton("show out of date", func() {
|
||||
found := zoopb.NewMachines()
|
||||
all := me.machines.All()
|
||||
for all.Scan() {
|
||||
m := all.Next()
|
||||
if findVersion(m, "zood") != me.zood.version {
|
||||
found.Append(m)
|
||||
}
|
||||
}
|
||||
zood.doMachinesUpgradeTable(found)
|
||||
})
|
||||
|
||||
// make a box at the bottom of the window for the protobuf table
|
||||
zood.box = zood.win.Bottom.Box().SetProgName("TBOX")
|
||||
zood.doMachinesUpgradeTable(me.machines)
|
||||
|
||||
return zood
|
||||
}
|
||||
|
||||
func (zood *stdTableWin) doMachinesUpgradeTable(pb *zoopb.Machines) {
|
||||
zood.Lock()
|
||||
defer zood.Unlock()
|
||||
if zood.TB != nil {
|
||||
zood.TB.Delete()
|
||||
zood.TB = nil
|
||||
}
|
||||
|
||||
/*
|
||||
found := zoopb.NewMachines()
|
||||
all := pb.SortByHostname()
|
||||
for all.Scan() {
|
||||
m := all.Next()
|
||||
found.Append(m)
|
||||
}
|
||||
*/
|
||||
|
||||
// display the protobuf
|
||||
zood.TB = AddMachinesPB(zood.box, pb)
|
||||
f := func(m *zoopb.Machine) {
|
||||
log.Info("Triggering machine", m.Hostname, "to upgrade zood")
|
||||
m.Upgrade = true
|
||||
}
|
||||
zood.TB.Custom(f)
|
||||
log.Info("table has uuid", zood.TB.GetUuid())
|
||||
}
|
||||
|
||||
func AddMachinesPB(tbox *gui.Node, pb *zoopb.Machines) *zoopb.MachinesTable {
|
||||
t := pb.NewTable("MachinesPB")
|
||||
t.NewUuid()
|
||||
t.SetParent(tbox)
|
||||
|
||||
upbut := t.AddButtonFunc("upgrade", func(m *zoopb.Machine) string {
|
||||
if me.zood != nil {
|
||||
mver := findVersion(m, "zood")
|
||||
if mver == me.zood.version {
|
||||
return ""
|
||||
} else {
|
||||
// log.Info("machine mismatch", m.Hostname, mver, me.zood.version)
|
||||
}
|
||||
}
|
||||
// log.Info("machine =", m.Hostname)
|
||||
return "now"
|
||||
})
|
||||
upbut.Custom = func(m *zoopb.Machine) {
|
||||
log.Info("Triggering machine", m.Hostname, "to upgrade zood")
|
||||
m.Upgrade = true
|
||||
}
|
||||
|
||||
t.AddHostname()
|
||||
t.AddMemory()
|
||||
t.AddCpus()
|
||||
t.AddStringFunc("sMB", func(m *zoopb.Machine) string {
|
||||
return fmt.Sprintf("%d mb", m.Memory/(1024*1024))
|
||||
})
|
||||
|
||||
t.AddStringFunc("zood", func(m *zoopb.Machine) string {
|
||||
return findVersion(m, "zood")
|
||||
})
|
||||
delf := func(m *zoopb.Machine) string {
|
||||
return "delete"
|
||||
}
|
||||
t.AddButtonFunc("delete", delf)
|
||||
|
||||
/*
|
||||
// show if the machine needs to be upgraded
|
||||
t.AddStringFunc("triggered?", func(m *zoopb.Machine) string {
|
||||
if m.Upgrade {
|
||||
return "yes"
|
||||
}
|
||||
return ""
|
||||
})
|
||||
*/
|
||||
|
||||
t.AddTimeFunc("age", func(m *zoopb.Machine) time.Time {
|
||||
return m.Laststamp.AsTime()
|
||||
})
|
||||
|
||||
t.ShowTable()
|
||||
return t
|
||||
}
|
||||
|
||||
func findVersion(m *zoopb.Machine, pkgname string) string {
|
||||
zood := m.Packages.FindByName(pkgname)
|
||||
if zood == nil {
|
||||
return "n/a"
|
||||
}
|
||||
return zood.Version
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
[Unit]
|
||||
Description=zookeeper
|
||||
Description=zood
|
||||
|
||||
[Service]
|
||||
User=root
|
||||
Type=simple
|
||||
ExecStart=/usr/bin/zookeeper
|
||||
ExecStop=killall zookeeper
|
||||
ExecStart=/usr/bin/zood
|
||||
ExecStop=killall zood
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
|
||||
|
|
Loading…
Reference in New Issue