//Return nodes status and see which nodes failed and which nodes are still ok haha. //We know we want an address list to be changed only when a node goes down. func CheckBuild(addressList []string, nodeStat map[string]NodeStatus) (bool, []string) { var cnt int var kill []string var readyList []string newList := addressList fmServ := fnet.NewBuildServer("http://localhost:8080", true) ok := false status := make(map[string]interfaces.StatusMessage) timeoutOffset := 45 * 60 interval := time.Duration(5 * time.Second) finish := time.Now().Add(time.Duration(timeoutOffset)) msgTime := time.Now() diagDaemon.DaemonLog.Log(fmt.Sprintf("Waiting for information from nodes in %s", newList)) for finish.After(time.Now()) { time.Sleep(interval) buf, _ := ControlMsg(newList, msgTime.Unix()) ret, err := fmServ.Post("/status", buf) diagDaemon.DaemonLog.LogError("Could not find server", err) if err == nil { json.Unmarshal(ret, &status) for _, address := range newList { nodeStat[address] = CheckStatus(address, status, "Ready") working := ReadInfo(address, status) if !working { kill = append(kill, address) diagDaemon.DaemonLog.Log(fmt.Sprintf("%s - ERROR: %s has been shut down due to error", time.Now(), address)) } } if len(kill) != 0 { addressList = Delete(addressList, kill) newList = addressList } kill = nil msgTime = time.Now() cnt = 0 //Last function needs to be cleaned better. for _, addy := range newList { if nodeStat[addy].Stat == false { cnt += 1 } else if nodeStat[addy].Stat == true { readyList = append(readyList, addy) } } newList = Delete(newList, readyList) readyList = nil if cnt == 0 { ok = true break } } } return ok, addressList }
//Could use error checking from the power daemon as well. c func CheckPower(addressList []string, cmd string) bool { ready := false exsist := false fmServ := fnet.NewBuildServer("http://localhost:8085", true) interval := time.Duration(5 * time.Second) timeoutOffset := 5 * 60 resp, err := json.Marshal(addressList) diagDaemon.DaemonLog.LogError("Unable to marshal data", err) buf := bytes.NewBufferString(string(resp)) finish := time.Now().Add(time.Duration(timeoutOffset)) for finish.After(time.Now()) { _, err = fmServ.Post("/reboot", buf) if err == nil { exsist = true break } diagDaemon.DaemonLog.LogError("%s", err) time.Sleep(interval) } if exsist { diagDaemon.DaemonLog.Log(fmt.Sprintf("%s %s request sent", addressList, cmd)) ready = true } else { ready = false diagDaemon.DaemonLog.Log("Function CheckPower() cannot be contacted") } return ready }
func SendCtrl(addressList []string) bool { exsist := false fmServ := fnet.NewBuildServer("http://localhost:8080", true) buf, _ := ControlMsg(addressList, int64(0)) finish := time.Now().Add(time.Duration(300 * time.Second)) diagDaemon.DaemonLog.Log(fmt.Sprintf("%s - INFO: Sending control messages for %s", time.Now(), addressList)) for finish.After(time.Now()) { _, err := fmServ.Post("/ctl", buf) if err == nil { exsist = true break } diagDaemon.DaemonLog.LogError(fmt.Sprintf("%s - ERROR: %s", time.Now()), err) time.Sleep(5 * time.Second) } return exsist }
func main() { flag.Parse() if help { fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0]) flag.PrintDefaults() os.Exit(0) } if os.Args[0] == "/opt/bootlocal.sh" { parseCmdLine() exec = "install" bs := fnet.NewBuildServer(server, verbose) fmt.Fprintf(os.Stdout, "Getting and executing %s script.\n", exec) startTime := time.Now() bail := false for _, err := bs.Run(exec); err != nil && !bail; _, err = bs.Run(exec) { if time.Now().Sub(startTime) >= 300 { bail = true fmt.Fprintf(os.Stderr, "ERROR: 5 minutes passed and microcore could not get install script.") } time.Sleep(5 * time.Second) } os.Exit(0) } else { bs := fnet.NewBuildServer(server, verbose) bs.DebugLog(fmt.Sprintf("Server is %s", server)) if get != "" { data, err := bs.Get(get) if err != nil { os.Exit(255) } fmt.Fprintf(os.Stdout, "%s", string(data)) } else if exec != "" { fmt.Fprintf(os.Stdout, "Getting and executing %s.", exec) status, err := bs.Run(exec) if err != nil { os.Exit(255) } os.Exit(status) } else if info != "" { im := new(infoErrorMsg) im.Message = info js, _ := json.Marshal(im) buf := bytes.NewBufferString(string(js)) _, err := bs.Post("/info", buf) if err != nil { os.Exit(255) } } else if error != "" { em := new(infoErrorMsg) em.Message = error js, _ := json.Marshal(em) buf := bytes.NewBufferString(string(js)) _, err := bs.Post("/error", buf) if err != nil { os.Exit(255) } } } }