From 425e75d388beb3f00e527e89ef81a35fd5b6e931 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 13 Oct 2024 03:49:54 -0500 Subject: [PATCH] trigger start over http Signed-off-by: Jeff Carr --- Makefile | 3 ++- event.go | 6 ++++++ http.go | 14 +++++++------- poll.go | 11 ++++++++++- structs.go | 1 + 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index a4b8953..3443eda 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,8 @@ all: ./virtigo --hosts farm01 farm02 farm03 start: - ./virtigo --start jcarr + curl --silent http://localhost:8080/start?start=jcarr + @# ./virtigo --start jcarr curl-uptime: curl --silent http://localhost:8080/uptime diff --git a/event.go b/event.go index c6e4bb5..ee4bef0 100644 --- a/event.go +++ b/event.go @@ -22,3 +22,9 @@ func (h *HyperT) RestartDaemon() { log.Info("KILLED DAEMON", h.Hostname, shell.FormatDuration(dur), "curl", url) me.killcount += 1 } + +func (h *HyperT) Start(d *DropletT) { + url := "http://" + h.Hostname + ":2520/start?" + d.Hostname + s := shell.Wget(url) + log.Info("EVENT start droplet", url, s) +} diff --git a/http.go b/http.go index d94a6a1..16dc79b 100644 --- a/http.go +++ b/http.go @@ -32,7 +32,6 @@ func okHandler(w http.ResponseWriter, r *http.Request) { // is the cluster running what it should? if tmp == "/droplets" { - var good = true for _, d := range me.droplets { if d.State != "ON" { continue @@ -40,17 +39,11 @@ func okHandler(w http.ResponseWriter, r *http.Request) { dur := time.Since(d.lastpoll) // Calculate the elapsed time if d.CurrentState != "ON" { fmt.Fprintln(w, "BAD STATE ", d.Hostname, "State =", d.State, "CurrentState =", d.CurrentState, shell.FormatDuration(dur)) - good = false } else { dur := time.Since(d.lastpoll) // Calculate the elapsed time fmt.Fprintln(w, "GOOD STATE ON", d.Hostname, d.hname, shell.FormatDuration(dur)) } } - if good { - fmt.Fprintln(w, "Handling URL:", tmp, "GOOD=true") - } else { - fmt.Fprintln(w, "Handling URL:", tmp, "GOOD=false") - } return } @@ -90,6 +83,13 @@ func okHandler(w http.ResponseWriter, r *http.Request) { return } + if tmp == "/start" { + start := r.URL.Query().Get("start") + log.Info("should start droplet here", start) + fmt.Fprintln(w, "should start droplet here", start) + return + } + log.Warn("BAD URL =", tmp) fmt.Fprintln(w, "BAD ZOOT") // badurl(w, r.URL.String()) diff --git a/poll.go b/poll.go index f7f2414..981bf86 100644 --- a/poll.go +++ b/poll.go @@ -136,8 +136,17 @@ func clusterHealthy() (bool, string) { } summary = strings.TrimSpace(summary) summary += ")" - summary += "(killcount=" + fmt.Sprintf("%d", me.killcount) + ")" + if me.killcount > 0 { + summary += "(killcount=" + fmt.Sprintf("%d", me.killcount) + ")" + } + last := time.Since(me.stable) + if last > 133*time.Second { + // the cluster has not been stable for 10 seconds + s := shell.FormatDuration(last) + summary += "(unstable " + s + ")" + } if good { + me.stable = time.Now() return good, "GOOD=true " + summary } return good, "GOOD=false " + summary diff --git a/structs.go b/structs.go index 94d7ce5..b97d35f 100644 --- a/structs.go +++ b/structs.go @@ -20,6 +20,7 @@ type virtigoT struct { hypers []*HyperT droplets []*DropletT killcount int + stable time.Time // the latest time the cluster has been okay } // the stuff that is needed for a hypervisor