diff --git a/aws-experiment-launch/experiment/commander/main.go b/aws-experiment-launch/experiment/commander/main.go index aa67daeb4..fa0a4798d 100644 --- a/aws-experiment-launch/experiment/commander/main.go +++ b/aws-experiment-launch/experiment/commander/main.go @@ -122,13 +122,18 @@ func dictateNode(addr string, command string) int { log.Printf("Failed to send command to %s", addr) return 0 } - log.Printf("Send \"%s\" to %s", command, addr) + // log.Printf("Send \"%s\" to %s", command, addr) // read response buff := make([]byte, 1024) if n, err := conn.Read(buff); err == nil { - log.Printf("Receive from %s: %s", addr, buff[:n]) - return 1 + received := string(buff[:n]) + // log.Printf("Receive from %s: %s", addr, buff[:n]) + if strings.Contains(received, "Failed") { + return 0 + } else { + return 1 + } } else { return 0 } diff --git a/aws-experiment-launch/experiment/soldier/main.go b/aws-experiment-launch/experiment/soldier/main.go index e98ff4027..ab27397f2 100644 --- a/aws-experiment-launch/experiment/soldier/main.go +++ b/aws-experiment-launch/experiment/soldier/main.go @@ -144,24 +144,29 @@ func handleInitCommand(args []string, w *bufio.Writer) { utils.DownloadFile(globalSession.localConfigFileName, configURL) log.Println("Successfully downloaded config") - runInstance() - - logAndReply(w, "Successfully init-ed") + if err := runInstance(); err == nil { + logAndReply(w, "Done init.") + } else { + logAndReply(w, "Failed.") + } } func handleKillCommand(w *bufio.Writer) { log.Println("Kill command") - killPort(setting.port) - logAndReply(w, "Kill command done.") + if err := killPort(setting.port); err == nil { + logAndReply(w, "Done kill.") + } else { + logAndReply(w, "Failed.") + } } -func killPort(port string) { +func killPort(port string) error { if runtime.GOOS == "windows" { command := fmt.Sprintf("(Get-NetTCPConnection -LocalPort %s).OwningProcess -Force", port) - runCmd("Stop-Process", "-Id", command) + return runCmd("Stop-Process", "-Id", command) } else { command := fmt.Sprintf("lsof -i tcp:%s | grep LISTEN | awk '{print $2}' | xargs kill -9", port) - runCmd("bash", "-c", command) + return runCmd("bash", "-c", command) } } @@ -280,7 +285,7 @@ func runCmd(name string, args ...string) error { } } -func runInstance() { +func runInstance() error { config := readConfigFile(globalSession.localConfigFileName) myConfig := getMyConfig(setting.ip, setting.port, &config) @@ -288,9 +293,9 @@ func runInstance() { os.MkdirAll(globalSession.logFolder, os.ModePerm) if myConfig[2] == "client" { - runClient() + return runClient() } else { - runNode() + return runNode() } }