| | |
| | | "analysis/logo" |
| | | "analysis/util" |
| | | "context" |
| | | |
| | | "github.com/spf13/viper" |
| | | ) |
| | | |
| | | func reaper(ctxt context.Context) { |
| | |
| | | |
| | | util.InitDBAPI() |
| | | |
| | | const ( |
| | | configFilePath = "/opt/vasystem/config/" |
| | | configFileName = "sdkconfig" |
| | | configFileType = "yaml" |
| | | ) |
| | | viper.SetConfigType(configFileType) |
| | | viper.SetConfigName(configFileName) |
| | | viper.AddConfigPath(configFilePath) |
| | | viper.AddConfigPath("./") |
| | | |
| | | envString := "" |
| | | |
| | | sdks := util.SDKInfo() |
| | | for k, v := range sdks { |
| | | |
| | | if err := viper.ReadInConfig(); err == nil { |
| | | |
| | | envString = viper.GetString(v.SdkType) |
| | | |
| | | } |
| | | logo.Errorln("MASTER ANALYSIS START SLAVE TYPE: ", v.SdkType, " SDK CONFIG: ", envString) |
| | | |
| | | args := []string{ |
| | | `-role=slave`, |
| | | "-sdk=" + v.SdkType, |
| | | "-id=" + v.IpcId, |
| | | } |
| | | |
| | | args = append(args, (*util.GetParams())...) |
| | | |
| | | pid, err := runProc(ctx, "./analysis", args) |
| | | pid, err := runProc(ctx, "./analysis", args, &envString) |
| | | |
| | | if err != nil { |
| | | logo.Errorf("ANALYSIS START SLAVE PROC %s IPC: %s error %+v\n", v.SdkType, v.IpcId, err) |
| | |
| | | "time" |
| | | ) |
| | | |
| | | type procInfo struct { |
| | | cmd *exec.Cmd |
| | | env string |
| | | } |
| | | |
| | | var ( |
| | | procMap = make(map[int]*exec.Cmd) |
| | | procMap = make(map[int]*procInfo) |
| | | ) |
| | | |
| | | func restartProc(ctxt context.Context, pid int) { |
| | | cmd, ok := procMap[pid] |
| | | info, ok := procMap[pid] |
| | | if ok { |
| | | err := cmd.Wait() |
| | | err := info.cmd.Wait() |
| | | |
| | | if err != nil { |
| | | logo.Errorln("pid : [", pid, "] quit error: ", err) |
| | |
| | | logo.Infoln("pid : [", pid, "] quit") |
| | | } |
| | | delete(procMap, pid) |
| | | runProc(ctxt, cmd.Path, cmd.Args[1:]) |
| | | runProc(ctxt, info.cmd.Path, info.cmd.Args[1:], &info.env) |
| | | } else { |
| | | logo.Errorln(pid, " doesn't exist") |
| | | } |
| | | } |
| | | |
| | | func quitProc(pid int) { |
| | | cmd, ok := procMap[pid] |
| | | info, ok := procMap[pid] |
| | | if ok { |
| | | delete(procMap, pid) |
| | | |
| | | syscall.Kill(pid, syscall.SIGINT) |
| | | cmd.Wait() |
| | | info.cmd.Wait() |
| | | } else { |
| | | logo.Errorln(pid, " doesn't exist") |
| | | } |
| | | } |
| | | func runProc(ctxt context.Context, bin string, args []string) (int, error) { |
| | | func runProc(ctxt context.Context, bin string, args []string, env *string) (int, error) { |
| | | cmd := exec.CommandContext(ctxt, bin, args...) |
| | | cmd.Env = os.Environ() |
| | | cmd.Env = append(cmd.Env, *env) |
| | | |
| | | pid := -1 |
| | | cmd.Stdout = os.Stdout |
| | | cmd.Stderr = os.Stderr |
| | | err := cmd.Start() |
| | | if err == nil { |
| | | pid = cmd.Process.Pid |
| | | procMap[pid] = cmd |
| | | procMap[pid] = &procInfo{cmd, *env} |
| | | } |
| | | return pid, err |
| | | } |
New file |
| | |
| | | FaceDetect: LD_LIBRARY_PATH=./libs:/usr/local/cuda-8.0/lib64 |
| | | Yolo: LD_LIBRARY_PATH=./libs:/usr/local/cuda-8.0/lib64 |
| | | HumanTrack: LD_LIBRARY_PATH=./libs:/usr/local/cuda-10.0/lib64 |