zhangmeng
2019-12-12 db6c60ab7b161be80e84dae2e647072c7d311ac7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package proc
 
import (
    "analysis/logo"
    "analysis/util"
    "context"
)
 
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()
 
    sdks := util.SDKInfo()
    for k, v := range sdks {
        args := []string{
            `-role=slave`,
            "-sdk=" + v.SdkType,
            "-id=" + v.IpcId,
        }
 
        args = append(args, (*util.GetParams())...)
 
        pid, err := runProc(ctx, "./analysis", args)
 
        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
}