a68e9d5531
getclient
56 lines
1.0 KiB
Go
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
|
|
}
|
|
|