crawler_manager_go/crawler_runner.go
snoop a68e9d5531 moved
getclient
2017-04-14 17:23:32 +09:00

56 lines
1.0 KiB
Go

package crawler_manager
import (
"log"
"os/exec"
"time"
"strconv"
"io/ioutil"
"os"
)
func RunContainer(container *string, cpm *map[string][]string) {
cmdStr := getRunCommand(container)
for {
pArg := "-Port=" + strconv.Itoa(currentPort)
cmd := exec.Command(cmdStr, pArg)
err := cmd.Start()
if err != nil {
log.Println(err)
}
time.Sleep(time.Duration( time.Second * 2))
paths := (*cpm)[*container]
b := CallInit2("localhost:" + strconv.Itoa(currentPort), &paths)
log.Println("current Port:" , currentPort)
if b == false {
currentPort++
continue;
}
log.Println(*container + " run success port:" , currentPort , "pid:", cmd.Process.Pid )
//write pid file container_pid_port
ioutil.WriteFile(PidFolder+*container+"_"+strconv.Itoa(cmd.Process.Pid)+ "_"+strconv.Itoa(currentPort), []byte(""), os.ModePerm)
portMap[*container] = strconv.Itoa(currentPort)
currentPort++
break;
}
}
func getRunCommand(container *string ) string {
return BinaryFolder + "/" + *container + "/" + runFile
}