From 6e0bd71c80b932517567876cd8040d289eb3e1b9 Mon Sep 17 00:00:00 2001 From: mountain Date: Fri, 1 Dec 2023 19:34:35 +0900 Subject: [PATCH] =?UTF-8?q?=EC=A4=91=EC=A7=80=ED=95=A0=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=EC=84=B8=EC=8A=A4=EB=A5=BC=20=EB=8F=99=EC=8B=9C?= =?UTF-8?q?=EC=97=90=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/client.go | 25 +++++++------------ client/operation.go | 59 +++++++++++++++++---------------------------- 2 files changed, 31 insertions(+), 53 deletions(-) diff --git a/client/client.go b/client/client.go index 75f85a4..57783bf 100644 --- a/client/client.go +++ b/client/client.go @@ -22,6 +22,7 @@ import ( "time" "unsafe" + "repositories.action2quare.com/ayo/gocommon" "repositories.action2quare.com/ayo/gocommon/logger" "repositories.action2quare.com/ayo/houston/shared" "repositories.action2quare.com/ayo/houston/shared/protos" @@ -431,22 +432,14 @@ func NewClient(standalone bool) (HoustonClient, error) { id64, _ := strconv.ParseInt(idstr, 10, 0) id := int32(id64) - var killing *procmeta - var remains []*procmeta - for _, meta := range hc.childProcs { - if meta.id == id { - killing = meta - } else { - remains = append(remains, meta) + hc.childProcs = gocommon.ShrinkSlice(hc.childProcs, func(e *procmeta) bool { + if e.id == id { + e.cmd.Wait() + e.cmd.Process.Release() + return true } - } - - if killing != nil { - killing.cmd.Wait() - killing.cmd.Process.Release() - } - - hc.childProcs = remains + return false + }) op.Refresh(context.Background(), hc.makeOperationQueryRequest()) } @@ -523,7 +516,7 @@ func (hc *houstonClient) Start() { if client != nil { err := hc.checkOperation(client) if err != nil { - logger.Println("hc.checkUpdate failed :", err) + logger.Println("grpc.DialContext hc.checkOperation failed :", err) client = nil } diff --git a/client/operation.go b/client/operation.go index 8686c8a..362613a 100644 --- a/client/operation.go +++ b/client/operation.go @@ -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 {