Merge pull request #43 from simple-rules/ricl-kill

update kill command on soldier
pull/44/head
Richard Liu 6 years ago committed by GitHub
commit e90372bdf0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      aws-experiment-launch/experiment/soldier/main.go

@ -16,6 +16,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"runtime"
"strings" "strings"
) )
@ -150,10 +151,20 @@ func handleInitCommand(args []string, w *bufio.Writer) {
func handleKillCommand(w *bufio.Writer) { func handleKillCommand(w *bufio.Writer) {
log.Println("Kill command") log.Println("Kill command")
runCmd("./kill_node.sh") killPort(setting.port)
logAndReply(w, "Kill command done.") 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) { func handlePingCommand(w *bufio.Writer) {
log.Println("Ping command") log.Println("Ping command")
logAndReply(w, "I'm alive") logAndReply(w, "I'm alive")

Loading…
Cancel
Save