|
|
@ -144,24 +144,29 @@ func handleInitCommand(args []string, w *bufio.Writer) { |
|
|
|
utils.DownloadFile(globalSession.localConfigFileName, configURL) |
|
|
|
utils.DownloadFile(globalSession.localConfigFileName, configURL) |
|
|
|
log.Println("Successfully downloaded config") |
|
|
|
log.Println("Successfully downloaded config") |
|
|
|
|
|
|
|
|
|
|
|
runInstance() |
|
|
|
if err := runInstance(); err == nil { |
|
|
|
|
|
|
|
logAndReply(w, "Done init.") |
|
|
|
logAndReply(w, "Successfully init-ed") |
|
|
|
} else { |
|
|
|
|
|
|
|
logAndReply(w, "Failed.") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func handleKillCommand(w *bufio.Writer) { |
|
|
|
func handleKillCommand(w *bufio.Writer) { |
|
|
|
log.Println("Kill command") |
|
|
|
log.Println("Kill command") |
|
|
|
killPort(setting.port) |
|
|
|
if err := killPort(setting.port); err == nil { |
|
|
|
logAndReply(w, "Kill command done.") |
|
|
|
logAndReply(w, "Done kill.") |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
logAndReply(w, "Failed.") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func killPort(port string) { |
|
|
|
func killPort(port string) error { |
|
|
|
if runtime.GOOS == "windows" { |
|
|
|
if runtime.GOOS == "windows" { |
|
|
|
command := fmt.Sprintf("(Get-NetTCPConnection -LocalPort %s).OwningProcess -Force", port) |
|
|
|
command := fmt.Sprintf("(Get-NetTCPConnection -LocalPort %s).OwningProcess -Force", port) |
|
|
|
runCmd("Stop-Process", "-Id", command) |
|
|
|
return runCmd("Stop-Process", "-Id", command) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
command := fmt.Sprintf("lsof -i tcp:%s | grep LISTEN | awk '{print $2}' | xargs kill -9", port) |
|
|
|
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) |
|
|
|
config := readConfigFile(globalSession.localConfigFileName) |
|
|
|
|
|
|
|
|
|
|
|
myConfig := getMyConfig(setting.ip, setting.port, &config) |
|
|
|
myConfig := getMyConfig(setting.ip, setting.port, &config) |
|
|
@ -288,9 +293,9 @@ func runInstance() { |
|
|
|
os.MkdirAll(globalSession.logFolder, os.ModePerm) |
|
|
|
os.MkdirAll(globalSession.logFolder, os.ModePerm) |
|
|
|
|
|
|
|
|
|
|
|
if myConfig[2] == "client" { |
|
|
|
if myConfig[2] == "client" { |
|
|
|
runClient() |
|
|
|
return runClient() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
runNode() |
|
|
|
return runNode() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|