package main import ( "time" "go.wit.com/lib/gui/shell" "go.wit.com/log" ) func (d *DropletT) Start() { log.Info("a new virtual machine is running") } func (h *HyperT) RestartDaemon() { url := "http://" + h.Hostname + ":2520/kill" s := shell.Wget(url) log.Info("EVENT RestartDaemon", url, s) 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) me.killcount += 1 } // 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 } func (h *HyperT) Start(d *DropletT) { if ! clusterReady() { return } if ! d.dropletReady() { return } url := "http://" + h.Hostname + ":2520/start?start=" + d.Hostname s := shell.Wget(url) 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() }