someday this will work

This commit is contained in:
Jeff Carr 2024-11-18 20:22:12 -06:00
parent b71fec22c8
commit afc7fedbe1
8 changed files with 63 additions and 48 deletions

View File

@ -7,15 +7,11 @@ all:
log: log:
journalctl -f -xeu zood.service journalctl -f -xeu zood.service
curl-vms: curl-toggle-PING-output:
curl http://localhost:2520/vms curl "http://localhost:2521/flag?flag-PING"
curl-kill: curl-kill:
curl http://localhost:2520/kill curl http://localhost:2521/kill
curl-dumpdomain-coriolis:
# information about libvirt domain for vm 'coriolis':
curl --silent http://localhost:2520/dumpdomain?domain=coriolis
status: status:
dpkg -s zood dpkg -s zood

16
argv.go
View File

@ -7,6 +7,7 @@ package main
import ( import (
"go.wit.com/dev/alexflint/arg" "go.wit.com/dev/alexflint/arg"
"go.wit.com/log"
) )
var argv args var argv args
@ -29,3 +30,18 @@ func (a args) Description() string {
this daemon talks to zookeeper this daemon talks to zookeeper
` `
} }
var NOW *log.LogFlag
var INFO *log.LogFlag
var PING *log.LogFlag
var WARN *log.LogFlag
func init() {
full := "go.wit.com/apps/zood"
short := "zood"
NOW = log.NewFlag("NOW", true, full, short, "useful while doing debugging")
INFO = log.NewFlag("INFO", false, full, short, "general zood")
PING = log.NewFlag("PING", false, full, short, "show pings to the zookeeper")
WARN = log.NewFlag("WARN", true, full, short, "bad things")
}

View File

@ -1,16 +1,4 @@
// Copyright 2016 The go-qemu Authors. // Copyright 2024 WIT.COM Inc.
//
// 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 package main

21
http.go
View File

@ -21,6 +21,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
route := cleanURL(r.URL.Path) route := cleanURL(r.URL.Path)
domname := r.URL.Query().Get("domain") domname := r.URL.Query().Get("domain")
flag := r.URL.Query().Get("flag")
msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte
if err != nil { if err != nil {
@ -54,6 +55,26 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
// toggle logging flags
if route == "/flag" {
log.HttpMode(w)
defer log.HttpMode(nil)
log.Info("going to toggle flag:", flag)
switch flag {
case "PING":
if PING.Bool() {
log.Log(NOW, "toogle PING false")
PING.SetBool(false)
} else {
log.Log(NOW, "toogle PING true")
PING.SetBool(true)
}
default:
log.Info("unknown looging flag:", flag)
}
return
}
if route == "/favicon.ico" { if route == "/favicon.ico" {
writeFile(w, "ipv6.png") writeFile(w, "ipv6.png")
return return

18
main.go
View File

@ -1,16 +1,4 @@
// Copyright 2016 The go-qemu Authors. // Copyright 2024 WIT.COM Inc.
//
// 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 package main
@ -45,9 +33,11 @@ func main() {
} }
me = new(stuff) me = new(stuff)
me.zookeeper = "zookeeper.wit.com" me.urlbase = "http://zookeeper.grid.wit.com:8080"
me.hostname, _ = os.Hostname() me.hostname, _ = os.Hostname()
me.pollDelay = 3 * time.Second me.pollDelay = 3 * time.Second
me.failcountmax = 20 // die every minute if zookeeper can't be found
// what OS? // what OS?
me.distro = initDistro() me.distro = initDistro()

12
send.go
View File

@ -10,14 +10,9 @@ import (
"go.wit.com/log" "go.wit.com/log"
) )
var urlbase string = "http://zookeeper.grid.wit.com:8080"
func send() {
}
func pingStatus() error { func pingStatus() error {
var url string var url string
url = urlbase + "/status?hostname=" + me.hostname url = me.urlbase + "/status?hostname=" + me.hostname
msg, err := me.machine.Packages.Marshal() msg, err := me.machine.Packages.Marshal()
if err != nil { if err != nil {
log.Info("proto.Marshal() failed:", err) log.Info("proto.Marshal() failed:", err)
@ -45,7 +40,7 @@ func pingStatus() error {
func sendMachine(s string) error { func sendMachine(s string) error {
var url string var url string
url = urlbase + "/machine" url = me.urlbase + "/machine"
msg, err := me.machine.Marshal() msg, err := me.machine.Marshal()
if err != nil { if err != nil {
log.Info("proto.Marshal() failed:", err) log.Info("proto.Marshal() failed:", err)
@ -62,6 +57,7 @@ func sendMachine(s string) error {
for _, line := range strings.Split(test, "\n") { for _, line := range strings.Split(test, "\n") {
if line == "upgrade" { if line == "upgrade" {
log.Info(s, "zookeeper is healthy", len(msg)) log.Info(s, "zookeeper is healthy", len(msg))
me.failcount = 0
} else if line == "kill" { } else if line == "kill" {
os.Exit(0) os.Exit(0)
} else if strings.HasPrefix(line, "apt update") { } else if strings.HasPrefix(line, "apt update") {
@ -71,7 +67,7 @@ func sendMachine(s string) error {
log.Sleep(1) log.Sleep(1)
os.Exit(0) os.Exit(0)
} else { } else {
log.Info(urlbase, "is maybe not working GOT:", line) log.Info(me.urlbase, "is maybe not working GOT:", line)
} }
} }
return nil return nil

View File

@ -10,11 +10,13 @@ var me *stuff
// this app's variables // this app's variables
type stuff struct { type stuff struct {
hostname string // my hostname to send to zookeeper hostname string // my hostname to send to zookeeper
zookeeper string // the dns name for the zookeeper urlbase string // the dns name for the zookeeper
pollDelay time.Duration // how often to report our status pollDelay time.Duration // how often to report our status
dog *time.Ticker // the watchdog timer dog *time.Ticker // the watchdog timer
distro string // debian,redhat,gentoo,macos,wincrap distro string // debian,redhat,gentoo,macos,wincrap
machine *zoopb.Machine // my protobuf machine *zoopb.Machine // my protobuf
failcount int // how many times we've failed to contact the zookeeper
failcountmax int // after this, exit and let systemd restart the daemon
// packages *zoopb.Packages // installed packages and versions // packages *zoopb.Packages // installed packages and versions
} }

View File

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"os"
"time" "time"
) )
@ -32,7 +33,12 @@ func NewWatchdog() {
// log.Info("Watchdog() ticked", me.zookeeper, "Current time: ", t) // log.Info("Watchdog() ticked", me.zookeeper, "Current time: ", t)
s := updatePackages() s := updatePackages()
// pingStatus() // pingStatus()
me.failcount += 1
sendMachine(s) sendMachine(s)
if me.failcount > 20 {
os.Exit(0)
}
// h.pollHypervisor() // h.pollHypervisor()
// h.Scan() // h.Scan()
} }