From 016f4592523ae274ff038e9fd4910179c90f6ded Mon Sep 17 00:00:00 2001 From: mountain Date: Tue, 30 Jul 2024 11:19:25 +0900 Subject: [PATCH] =?UTF-8?q?houston=20server=EC=97=90=20=EC=9E=AC=EC=A0=91?= =?UTF-8?q?=EC=86=8D=EC=8B=9C=20autorun=EC=9D=B4=20=EB=8B=A4=EC=8B=9C=20?= =?UTF-8?q?=EB=B6=88=EB=A6=AC=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/client.go | 79 ++++++++++++++++++++++++--------------------- client/operation.go | 4 +-- 2 files changed, 44 insertions(+), 39 deletions(-) diff --git a/client/client.go b/client/client.go index d69e918..dca3a89 100644 --- a/client/client.go +++ b/client/client.go @@ -317,6 +317,7 @@ func NewClient(standalone bool) (HoustonClient, error) { case newClient := <-hc.clientChan: op = protos.NewOperationClient(newClient) + op.Refresh(context.Background(), hc.makeOperationQueryRequest()) case exited := <-exitChan: var newprocs []*procmeta @@ -331,11 +332,15 @@ func NewClient(standalone bool) (HoustonClient, error) { proc.cmd.Process.Release() if proc.isState(protos.ProcessState_Restart) { - hc.startChildProcess(&shared.StartProcessRequest{ + if err := hc.startChildProcess(&shared.StartProcessRequest{ Version: proc.version, Name: proc.name, Args: proc.args, - }, op) + }); err != nil { + logger.ErrorWithCallStack(err) + } else { + op.Refresh(context.Background(), hc.makeOperationQueryRequest()) + } } }(proc) } @@ -422,8 +427,10 @@ func NewClient(standalone bool) (HoustonClient, error) { case shared.Start: var sr shared.StartProcessRequest unmarshal(&sr, resp.Args) - if err := hc.startChildProcess(&sr, op); err != nil { - logger.Println(err) + if err := hc.startChildProcess(&sr); err != nil { + logger.ErrorWithCallStack(err) + } else { + op.Refresh(context.Background(), hc.makeOperationQueryRequest()) } case shared.Stop: @@ -517,6 +524,38 @@ func (hc *houstonClient) Start() { reconnCount := 0 time.Sleep(time.Second) + if autorun != nil && len(*autorun) > 0 { + hascount := strings.Split(*autorun, "/") + var service string + count := 1 + if len(hascount) > 1 { + service = hascount[0] + if len(hascount[1]) > 0 { + count, _ = strconv.Atoi(hascount[1]) + } + } else { + service = *autorun + } + + if cmd, ok := hc.config.Autorun[service]; ok { + // service 서비스 + for i := 0; i < count; i++ { + sr := shared.StartProcessRequest{ + Name: service, + Version: cmd.Version, + Args: append([]string{cmd.Exec}, cmd.Args...), + } + + if err := hc.startChildProcess(&sr); err != nil { + logger.Println("startChildProcess failed by autorun :", err) + logger.ErrorWithCallStack(err) + } else { + logger.Println("autorun success :", sr) + } + } + } + } + for { select { case <-hc.ctx.Done(): @@ -548,7 +587,6 @@ func (hc *houstonClient) Start() { err := hc.checkOperation(client) if err != nil { logger.Println("grpc.DialContext hc.checkOperation failed :", err) - client = nil } } @@ -580,37 +618,6 @@ func (hc *houstonClient) checkOperation(client *grpc.ClientConn) error { return err } - if autorun != nil && len(*autorun) > 0 { - hascount := strings.Split(*autorun, "/") - var service string - count := 1 - if len(hascount) > 1 { - service = hascount[0] - if len(hascount[1]) > 0 { - count, _ = strconv.Atoi(hascount[1]) - } - } else { - service = *autorun - } - - if cmd, ok := hc.config.Autorun[service]; ok { - // service 서비스 - for i := 0; i < count; i++ { - sr := shared.StartProcessRequest{ - Name: service, - Version: cmd.Version, - Args: append([]string{cmd.Exec}, cmd.Args...), - } - - if err := hc.startChildProcess(&sr, op); err != nil { - logger.Println("startChildProcess failed by autorun :", err) - } else { - logger.Println("autorun success :", sr) - } - } - } - } - for { update, err := cl.Recv() if err != nil { diff --git a/client/operation.go b/client/operation.go index cc60987..be31ea0 100644 --- a/client/operation.go +++ b/client/operation.go @@ -435,7 +435,7 @@ func (hc *houstonClient) launch(meta *procmeta) error { return err } -func (hc *houstonClient) startChildProcess(req *shared.StartProcessRequest, op protos.OperationClient) error { +func (hc *houstonClient) startChildProcess(req *shared.StartProcessRequest) error { meta, err := prepareProcessLaunch(hc.config.StorageRoot, req) if err != nil { return err @@ -465,8 +465,6 @@ func (hc *houstonClient) startChildProcess(req *shared.StartProcessRequest, op p } hc.childProcs = append(hc.childProcs, meta) - op.Refresh(context.Background(), hc.makeOperationQueryRequest()) - return nil }