중지할 프로세스를 동시에 처리
This commit is contained in:
@ -422,8 +422,6 @@ func (hc *houstonClient) startChildProcess(req *shared.StartProcessRequest, op p
|
||||
return nil
|
||||
}
|
||||
|
||||
var errNoRunningProcess = errors.New("no running processed")
|
||||
|
||||
func (hc *houstonClient) stopChildProcess(req *shared.StopProcessRequest, op protos.OperationClient) error {
|
||||
if req.Version == "latest" {
|
||||
// 최신 버전을 찾음
|
||||
@ -435,8 +433,23 @@ func (hc *houstonClient) stopChildProcess(req *shared.StopProcessRequest, op pro
|
||||
req.Version = latest
|
||||
}
|
||||
|
||||
var remains []*procmeta
|
||||
var killing []*procmeta
|
||||
killer := func(proc *procmeta) {
|
||||
proc.setState(protos.ProcessState_Stopping)
|
||||
if err := proc.cmd.Process.Signal(syscall.SIGTERM); err != nil {
|
||||
proc.cmd.Process.Signal(os.Kill)
|
||||
}
|
||||
|
||||
go func() {
|
||||
proc.cmd.Wait()
|
||||
hc.operationChan <- &protos.OperationQueryResponse{
|
||||
Operation: string(shared.Exception),
|
||||
Args: map[string]string{
|
||||
"id": fmt.Sprintf("%d", proc.id),
|
||||
},
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
for _, proc := range hc.childProcs {
|
||||
if !proc.isState(protos.ProcessState_Running) {
|
||||
continue
|
||||
@ -445,50 +458,22 @@ func (hc *houstonClient) stopChildProcess(req *shared.StopProcessRequest, op pro
|
||||
if req.Pid != 0 {
|
||||
if req.Pid == int32(proc.cmd.Process.Pid) {
|
||||
// 해당 pid만 제거
|
||||
killing = append(killing, proc)
|
||||
} else {
|
||||
remains = append(remains, proc)
|
||||
killer(proc)
|
||||
}
|
||||
} else if proc.name == req.Name {
|
||||
if len(req.Version) == 0 {
|
||||
// program 다 정지
|
||||
killing = append(killing, proc)
|
||||
killer(proc)
|
||||
} else if req.Version == proc.version {
|
||||
// program의 특정 버전만 정지
|
||||
killing = append(killing, proc)
|
||||
} else {
|
||||
// 해당 사항 없음
|
||||
remains = append(remains, proc)
|
||||
killer(proc)
|
||||
}
|
||||
} else {
|
||||
// 해당 사항 없음
|
||||
remains = append(remains, proc)
|
||||
}
|
||||
}
|
||||
|
||||
if len(killing) > 0 {
|
||||
for _, proc := range killing {
|
||||
proc.setState(protos.ProcessState_Stopping)
|
||||
if err := proc.cmd.Process.Signal(syscall.SIGTERM); err != nil {
|
||||
proc.cmd.Process.Signal(os.Kill)
|
||||
}
|
||||
}
|
||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||
|
||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||
|
||||
for _, proc := range killing {
|
||||
proc.cmd.Wait()
|
||||
proc.cmd.Process.Release()
|
||||
}
|
||||
|
||||
hc.childProcs = remains
|
||||
|
||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
return errNoRunningProcess
|
||||
return nil
|
||||
}
|
||||
|
||||
func (hc *houstonClient) restartChildProcess(req *shared.RestartProcessRequest, op protos.OperationClient) error {
|
||||
|
||||
Reference in New Issue
Block a user