package proc
|
|
import (
|
"analysis/logo"
|
"analysis/util"
|
"context"
|
|
"github.com/spf13/viper"
|
)
|
|
func reaper(ctxt context.Context) {
|
pidChan := make(chan int, 1)
|
Reap(pidChan)
|
go waitForRestart(ctxt, pidChan)
|
}
|
|
// MasterRole master
|
func MasterRole(ctx context.Context) bool {
|
reaper(ctx)
|
|
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, &envString)
|
|
if err != nil {
|
logo.Errorf("ANALYSIS START SLAVE PROC %s IPC: %s error %+v\n", v.SdkType, v.IpcId, err)
|
}
|
logo.Infof("START %d PROC %d SDK %s ID %s\n", k, pid, v.IpcId, v.SdkType)
|
}
|
return true
|
}
|