2024-10-12 10:59:11 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-10-13 02:23:30 -05:00
|
|
|
"time"
|
|
|
|
|
2024-10-13 01:33:32 -05:00
|
|
|
"go.wit.com/lib/gui/shell"
|
2024-10-12 10:59:11 -05:00
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (d *DropletT) Start() {
|
|
|
|
log.Info("a new virtual machine is running")
|
|
|
|
}
|
2024-10-13 01:33:32 -05:00
|
|
|
|
|
|
|
func (h *HyperT) RestartDaemon() {
|
|
|
|
url := "http://" + h.Hostname + ":2520/kill"
|
|
|
|
s := shell.Wget(url)
|
|
|
|
log.Info("EVENT RestartDaemon", url, s)
|
2024-10-13 02:23:30 -05:00
|
|
|
h.lastpoll = time.Now()
|
|
|
|
h.killcount += 1
|
|
|
|
|
|
|
|
dur := time.Since(h.lastpoll) // Calculate the elapsed time
|
|
|
|
log.Info("KILLED DAEMON", h.Hostname, shell.FormatDuration(dur), "curl", url)
|
2024-10-13 03:20:48 -05:00
|
|
|
me.killcount += 1
|
2024-10-13 01:33:32 -05:00
|
|
|
}
|
2024-10-13 03:49:54 -05:00
|
|
|
|
2024-10-15 11:02:34 -05:00
|
|
|
// checks if the cluster is ready and stable
|
|
|
|
func clusterReady() bool {
|
|
|
|
last := time.Since(me.unstable)
|
|
|
|
if last > 133*time.Second {
|
|
|
|
// the cluster has not been stable for 133 seconds
|
|
|
|
log.Warn("clusterReady() is stable for 133s")
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
log.Warn("clusterReady() is unstable for", shell.FormatDuration(last))
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *DropletT) dropletReady() bool {
|
|
|
|
if d.CurrentState == "ON" {
|
|
|
|
log.Warn("EVENT start droplet is already ON")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if d.starts > 2 {
|
|
|
|
log.Warn("EVENT start droplet has already been started", d.starts, "times")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-10-13 03:49:54 -05:00
|
|
|
func (h *HyperT) Start(d *DropletT) {
|
2024-10-15 11:02:34 -05:00
|
|
|
if ! clusterReady() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if ! d.dropletReady() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
url := "http://" + h.Hostname + ":2520/start?start=" + d.Hostname
|
2024-10-13 03:49:54 -05:00
|
|
|
s := shell.Wget(url)
|
2024-10-15 11:02:34 -05:00
|
|
|
log.Warn("EVENT start droplet url:", url)
|
|
|
|
log.Warn("EVENT start droplet response:", s)
|
|
|
|
|
|
|
|
// increment the counter for a start attempt working
|
|
|
|
d.starts += 1
|
|
|
|
|
|
|
|
// mark the cluster as unstable so droplet starts can be throttled
|
|
|
|
me.unstable = time.Now()
|
2024-10-13 03:49:54 -05:00
|
|
|
}
|