diff --git a/Makefile.help b/Makefile.help index ca0c9ef..c64a2dc 100644 --- a/Makefile.help +++ b/Makefile.help @@ -7,15 +7,11 @@ all: log: journalctl -f -xeu zood.service -curl-vms: - curl http://localhost:2520/vms +curl-toggle-PING-output: + curl "http://localhost:2521/flag?flag-PING" curl-kill: - curl http://localhost:2520/kill - -curl-dumpdomain-coriolis: - # information about libvirt domain for vm 'coriolis': - curl --silent http://localhost:2520/dumpdomain?domain=coriolis + curl http://localhost:2521/kill status: dpkg -s zood diff --git a/argv.go b/argv.go index 9846438..6a25aa0 100644 --- a/argv.go +++ b/argv.go @@ -7,6 +7,7 @@ package main import ( "go.wit.com/dev/alexflint/arg" + "go.wit.com/log" ) var argv args @@ -29,3 +30,18 @@ func (a args) Description() string { 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") +} diff --git a/distro.go b/distro.go index e6852b9..0269ea1 100644 --- a/distro.go +++ b/distro.go @@ -1,16 +1,4 @@ -// 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. +// Copyright 2024 WIT.COM Inc. package main diff --git a/http.go b/http.go index 6547f74..f97f39c 100644 --- a/http.go +++ b/http.go @@ -21,6 +21,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) { route := cleanURL(r.URL.Path) domname := r.URL.Query().Get("domain") + flag := r.URL.Query().Get("flag") msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte if err != nil { @@ -54,6 +55,26 @@ func okHandler(w http.ResponseWriter, r *http.Request) { 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" { writeFile(w, "ipv6.png") return diff --git a/main.go b/main.go index d60f1e0..3b5bbba 100644 --- a/main.go +++ b/main.go @@ -1,16 +1,4 @@ -// 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. +// Copyright 2024 WIT.COM Inc. package main @@ -45,9 +33,11 @@ func main() { } me = new(stuff) - me.zookeeper = "zookeeper.wit.com" + me.urlbase = "http://zookeeper.grid.wit.com:8080" + me.hostname, _ = os.Hostname() me.pollDelay = 3 * time.Second + me.failcountmax = 20 // die every minute if zookeeper can't be found // what OS? me.distro = initDistro() diff --git a/send.go b/send.go index 045c625..ca8889b 100644 --- a/send.go +++ b/send.go @@ -10,14 +10,9 @@ import ( "go.wit.com/log" ) -var urlbase string = "http://zookeeper.grid.wit.com:8080" - -func send() { -} - func pingStatus() error { var url string - url = urlbase + "/status?hostname=" + me.hostname + url = me.urlbase + "/status?hostname=" + me.hostname msg, err := me.machine.Packages.Marshal() if err != nil { log.Info("proto.Marshal() failed:", err) @@ -45,7 +40,7 @@ func pingStatus() error { func sendMachine(s string) error { var url string - url = urlbase + "/machine" + url = me.urlbase + "/machine" msg, err := me.machine.Marshal() if err != nil { log.Info("proto.Marshal() failed:", err) @@ -62,6 +57,7 @@ func sendMachine(s string) error { for _, line := range strings.Split(test, "\n") { if line == "upgrade" { log.Info(s, "zookeeper is healthy", len(msg)) + me.failcount = 0 } else if line == "kill" { os.Exit(0) } else if strings.HasPrefix(line, "apt update") { @@ -71,7 +67,7 @@ func sendMachine(s string) error { log.Sleep(1) os.Exit(0) } else { - log.Info(urlbase, "is maybe not working GOT:", line) + log.Info(me.urlbase, "is maybe not working GOT:", line) } } return nil diff --git a/structs.go b/structs.go index 02e9500..7cb8a8c 100644 --- a/structs.go +++ b/structs.go @@ -10,11 +10,13 @@ var me *stuff // this app's variables 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 - distro string // debian,redhat,gentoo,macos,wincrap - machine *zoopb.Machine // my protobuf + hostname string // my hostname to send to zookeeper + urlbase string // the dns name for the zookeeper + pollDelay time.Duration // how often to report our status + dog *time.Ticker // the watchdog timer + distro string // debian,redhat,gentoo,macos,wincrap + 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 } diff --git a/watchdog.go b/watchdog.go index c490143..9db2471 100644 --- a/watchdog.go +++ b/watchdog.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "os" "time" ) @@ -32,7 +33,12 @@ func NewWatchdog() { // log.Info("Watchdog() ticked", me.zookeeper, "Current time: ", t) s := updatePackages() // pingStatus() + me.failcount += 1 sendMachine(s) + + if me.failcount > 20 { + os.Exit(0) + } // h.pollHypervisor() // h.Scan() }