package master
|
|
import (
|
"analysis/app"
|
"analysis/logo"
|
"analysis/util"
|
"context"
|
"strings"
|
|
"basic.com/libgowrapper/sdkstruct.git"
|
)
|
|
func reaper(ctxt context.Context) {
|
pidChan := make(chan int, 1)
|
Reap(pidChan)
|
go waitForRestart(ctxt, pidChan)
|
}
|
|
// Run run
|
func Run(ctx context.Context, soFile, configPath string) bool {
|
reaper(ctx)
|
|
fetcher := NewFetcher(soFile)
|
if fetcher == nil {
|
logo.Errorln("New Fetcher Load so File Funcs Error From File: ", soFile)
|
return false
|
}
|
|
logo.Infoln("~~~~~~Created Fetcher, Now Sync From DB")
|
|
fetcher.fnInitDBAPI(util.FSI.IP, util.FSI.HTTPort, util.FSI.HBPort, util.FSI.DataPort, logo.Infoln)
|
// fetcher.fnInitDBAPI("192.168.20.10", util.FSI.HTTPort, util.FSI.HBPort, util.FSI.DataPort, logo.Infoln)
|
sdks := fetcher.fnSDKInfo()
|
for {
|
if len(sdks) == 0 {
|
logo.Errorln("!!!!!!Fetcher Can't Get SDK Infos From Remote DB")
|
continue
|
}
|
break
|
}
|
return manualStart(ctx, sdks, configPath)
|
}
|
|
func manualStart(ctx context.Context, sdks []sdkstruct.SDKInfo, configPath string) bool {
|
rPath := configPath
|
|
params := app.GetParams()
|
|
for _, v := range sdks {
|
|
file := rPath + v.SdkType + ".json"
|
if rPath[len(rPath)-1] != '/' {
|
file = rPath + "/" + v.SdkType + ".json"
|
}
|
|
cfg, err := app.ReadConfig(file)
|
if err != nil {
|
logo.Errorln("Master Read: ", file, " Config Error: ", err)
|
continue
|
}
|
|
if len(cfg.Env) > 0 {
|
envs := strings.Split(cfg.Env, ":")
|
normal := true
|
for _, v := range envs {
|
if !util.IsFileExist(v) {
|
normal = false
|
break
|
}
|
}
|
if !normal {
|
logo.Infoln("Can't Find Runtime Path, Skip It: ", file)
|
continue
|
}
|
}
|
|
logo.Infoln(file, " CONFIG: ", cfg)
|
|
args := []string{
|
`-role=slave`,
|
"-sdk=" + v.SdkType,
|
"-id=" + v.IpcID,
|
"-" + util.ConfigPath + "=" + file,
|
}
|
|
args = append(args, params...)
|
pid, err := runProc(ctx, "./analysis", args, cfg.Env)
|
|
if err != nil {
|
logo.Errorf("ANALYSIS START SLAVE PROC %s IPC: %s error %+v\n", v.SdkType, v.IpcID, err)
|
}
|
logo.Infof("START SDK %s ID %s PID %d Env: %s\n", v.SdkType, v.IpcID, pid, cfg.Env)
|
}
|
return true
|
|
}
|