update kill command on soldier

pull/43/head
Richard Liu 6 years ago
parent fc3397ae16
commit 892d809a1c
  1. 13
      aws-experiment-launch/experiment/soldier/main.go

@ -16,6 +16,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
)
@ -150,10 +151,20 @@ func handleInitCommand(args []string, w *bufio.Writer) {
func handleKillCommand(w *bufio.Writer) {
log.Println("Kill command")
runCmd("./kill_node.sh")
killPort(setting.port)
logAndReply(w, "Kill command done.")
}
func killPort(port string) {
if runtime.GOOS == "windows" {
command := fmt.Sprintf("(Get-NetTCPConnection -LocalPort %s).OwningProcess -Force", port)
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)
}
}
func handlePingCommand(w *bufio.Writer) {
log.Println("Ping command")
logAndReply(w, "I'm alive")

Loading…
Cancel
Save