From 5429d3d90f0945baaafb03e444891f136dbe098b Mon Sep 17 00:00:00 2001 From: mountain Date: Thu, 29 Jun 2023 11:00:26 +0900 Subject: [PATCH] =?UTF-8?q?houstonClient=EB=8F=84=20=EB=B2=84=EC=A0=84=20?= =?UTF-8?q?=EA=B4=80=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/client.go | 36 ++++++++++++++++++++++++++++++++---- client/deploy.go | 6 ++++++ main.go | 2 +- server/server.go | 4 +--- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/client/client.go b/client/client.go index e47d58c..f303c0e 100644 --- a/client/client.go +++ b/client/client.go @@ -117,6 +117,8 @@ type houstonClient struct { timestamp string wg sync.WaitGroup config clientConfig + version string + standalone bool } func unmarshal[T any](val *T, src map[string]string) { @@ -162,8 +164,25 @@ func gatherDeployedPrograms(storageRoot, name string) []*protos.VersionAndArgs { } func (hc *houstonClient) makeOperationQueryRequest() *protos.OperationQueryRequest { - hn, _ := os.Hostname() - procs := make([]*protos.ProcessDescription, 0, len(hc.childProcs)) + procs := make([]*protos.ProcessDescription, 0, len(hc.childProcs)+1) + if hc.standalone { + procs = append(procs, &protos.ProcessDescription{ + Name: os.Args[0], + Args: os.Args[1:], + Version: hc.version, + State: protos.ProcessState_Running, + Pid: int32(os.Getpid()), + }) + } else { + procs = append(procs, &protos.ProcessDescription{ + Name: "houston", + Args: []string{}, + Version: hc.version, + State: protos.ProcessState_Running, + Pid: int32(os.Getpid()), + }) + } + for _, child := range hc.childProcs { procs = append(procs, &protos.ProcessDescription{ Name: child.name, @@ -181,7 +200,7 @@ func (hc *houstonClient) makeOperationQueryRequest() *protos.OperationQueryReque Versions: prog, }) } - + hn, _ := os.Hostname() return &protos.OperationQueryRequest{ Hostname: hn, Procs: procs, @@ -189,7 +208,7 @@ func (hc *houstonClient) makeOperationQueryRequest() *protos.OperationQueryReque } } -func NewClient() (HoustonClient, error) { +func NewClient(standalone bool) (HoustonClient, error) { clientConfig, err := loadClientConfig() if err != nil { return nil, err @@ -238,12 +257,19 @@ func NewClient() (HoustonClient, error) { } } + ver, _ := os.ReadFile("@version") + if len(ver) == 0 { + ver = []byte("0.0.0") + } + hc := &houstonClient{ config: clientConfig, clientChan: make(chan *grpc.ClientConn), extraMetrics: unsafe.Pointer(&map[string]float32{}), deploys: deploys, timestamp: exefi.ModTime().String(), + version: string(ver), + standalone: standalone, } ctx, cancel := context.WithCancel(context.Background()) @@ -419,6 +445,8 @@ func (hc *houstonClient) Start() { var client *grpc.ClientConn reconnCount := 0 + time.Sleep(time.Second) + for { select { case <-hc.ctx.Done(): diff --git a/client/deploy.go b/client/deploy.go index 2ad1f2b..9819e4e 100644 --- a/client/deploy.go +++ b/client/deploy.go @@ -264,6 +264,12 @@ func (hc *houstonClient) prepareUpdateSelf(req *shared.DeployRequest) (srcdir st return "", "", err } + // houston version 파일 + err = os.WriteFile(path.Join(fname, "@version"), []byte(req.Version), 0444) + if err != nil { + return "", "", err + } + selfname, _ := os.Executable() srcreplacer := path.Join(path.Dir(fname), "replacer") + path.Ext(selfname) replacer = "./" + filepath.ToSlash("replacer"+path.Ext(selfname)) diff --git a/main.go b/main.go index f3731df..2858ac4 100644 --- a/main.go +++ b/main.go @@ -18,7 +18,7 @@ func main() { } if *runAsClient { - hc, err := client.NewClient() + hc, err := client.NewClient(true) if err != nil { logger.Fatal(err) return diff --git a/server/server.go b/server/server.go index 8a3c07e..4465aad 100644 --- a/server/server.go +++ b/server/server.go @@ -6,7 +6,6 @@ import ( "net" "os" "sync/atomic" - "time" "repositories.action2quare.com/ayo/gocommon/logger" "repositories.action2quare.com/ayo/houston/client" @@ -180,13 +179,12 @@ func (hs *houstonServer) Start() error { closeCount := int32(0) var hc client.HoustonClient if loadServerConfig().RunAsClient { - hc, err = client.NewClient() + hc, err = client.NewClient(false) if err != nil { return err } go func() { - time.Sleep(time.Second) hc.Start() logger.Println("houstonClient is finished") if atomic.AddInt32(&closeCount, 1) == 1 {