|
|
@ -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") |
|
|
|