| | |
| | | "analysis/util" |
| | | ) |
| | | |
| | | const ( |
| | | opRemove = "remove" |
| | | opAdd = "add" |
| | | ) |
| | | |
| | | // Notice transit to slave |
| | | type Notice struct { |
| | | Op string `json:"Op"` |
| | | Content []string `json:"Content"` |
| | | } |
| | | |
| | | type transit struct { |
| | | chNotify chan<- []byte |
| | | cancel context.CancelFunc |
| | | } |
| | | |
| | | // NamedProc 单个进程名字和服务通道 |
| | | type NamedProc struct { |
| | | // 进程名字 |
| | |
| | | Typ string |
| | | // 具名进程 |
| | | SNameProc []NamedProc |
| | | } |
| | | |
| | | // Notice transit to slave |
| | | type Notice struct { |
| | | Op string `json:"Op"` |
| | | Content []string `json:"Content"` |
| | | } |
| | | type transit struct { |
| | | chNotify chan<- []byte |
| | | cancel context.CancelFunc |
| | | } |
| | | |
| | | // Worker 单个进程服务 |
| | |
| | | for _, w := range workers { |
| | | if v == w.info.Name { |
| | | // 找到了对应名字的进程,首先求不需要再运行的通道 |
| | | var notice *Notice |
| | | removes := difference(w.info.Channels, proc.Channels) |
| | | if len(removes) > 0 { |
| | | // 通知子进程关闭通道 |
| | | notice = &Notice{ |
| | | Op: "remove", |
| | | n := Notice{ |
| | | Op: opRemove, |
| | | Content: removes, |
| | | } |
| | | |
| | | if d, err := json.Marshal(n); err == nil { |
| | | w.trans.chNotify <- d |
| | | } |
| | | } |
| | | |
| | | // 其次求出新增的通道 |
| | | adds := difference(proc.Channels, w.info.Channels) |
| | | if len(adds) > 0 { |
| | | // 通知子进程打开通道 |
| | | notice = &Notice{ |
| | | Op: "add", |
| | | n := Notice{ |
| | | Op: opAdd, |
| | | Content: adds, |
| | | } |
| | | } |
| | | if notice != nil { |
| | | if d, err := json.Marshal(*notice); err == nil { |
| | | if d, err := json.Marshal(n); err == nil { |
| | | w.trans.chNotify <- d |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | if cmd == nil { |
| | | logo.Errorf("ANALYSIS START SLAVE PROC %s IPC: %s Failed\n", typ, ipcID) |
| | | return |
| | | } |
| | | logo.Infof("START SDK %s ID %s PID %d Env: %s\n", typ, ipcID, cmd.Process.Pid, info.Env) |
| | | logo.Infoln(cmd.Args) |
| | | |
| | | ch := make(chan []byte, 3) |
| | | cancel := fnNotify(ctx, ipcID, ch, logo.Infoln) |
| | |
| | | os.Setenv(runtime, old) |
| | | } |
| | | |
| | | // //debug |
| | | // cmd.Stdout = os.Stdout |
| | | // cmd.Stderr = os.Stderr |
| | | //debug |
| | | cmd.Stdout = os.Stdout |
| | | cmd.Stderr = os.Stderr |
| | | cmd.SysProcAttr = &syscall.SysProcAttr{Pdeathsig: syscall.SIGTERM} |
| | | |
| | | if err := cmd.Start(); err == nil { |