From 92432fcd83656d224494eb9bb630a15d7d71d199 Mon Sep 17 00:00:00 2001 From: mountain Date: Mon, 11 Nov 2024 20:59:12 +0900 Subject: [PATCH] =?UTF-8?q?replacer=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/client.go | 81 +++++++++++++++++----------------------- client/deploy.go | 48 ------------------------ make_houston_package.ps1 | 12 ------ 3 files changed, 34 insertions(+), 107 deletions(-) diff --git a/client/client.go b/client/client.go index e90dfc6..e85e857 100644 --- a/client/client.go +++ b/client/client.go @@ -405,56 +405,43 @@ func NewClient(standalone bool) (HoustonClient, error) { unmarshal(&dr, resp.Args) logger.Println("args :", dr) - if dr.Name == myname { - if srcdir, replacer, err := hc.prepareUpdateSelf(&dr); err == nil { - args := []string{ - fmt.Sprintf("%d", os.Getpid()), - srcdir, - filepath.ToSlash(os.Args[0]), - } - args = append(args, os.Args[1:]...) - cmd := exec.Command(replacer, args...) - if err := cmd.Start(); err != nil { - logger.Println(err) - } else { - hc.shutdownFunc() - } - } else { - logger.Println(err) + hn, _ := os.Hostname() + + if err := hc.deploy(&dr, func(dp *protos.DeployingProgress) { + dp.Hostname = hn + dp.Name = dr.Name + dp.Version = dr.Version + op.ReportDeployingProgress(ctx, dp) + }); err == nil { + if dr.Name == "houston" { + // houston.update 다운로드가 완료되었으므로 종료 + // 종료되고나면 스크립트가 알아서 재 실행 + hc.Shutdown() + return } + prog := gatherDeployedPrograms(hc.config.StorageRoot, dr.Name) + hc.deploys[dr.Name] = prog + op.Refresh(ctx, hc.makeOperationQueryRequest()) + + op.ReportDeployingProgress(ctx, &protos.DeployingProgress{ + Hostname: hn, + Name: dr.Name, + Version: dr.Version, + State: "success", + Progress: 0, + Total: 0, + }) } else { - hn, _ := os.Hostname() + logger.Println(err) - if err := hc.deploy(&dr, func(dp *protos.DeployingProgress) { - dp.Hostname = hn - dp.Name = dr.Name - dp.Version = dr.Version - op.ReportDeployingProgress(ctx, dp) - }); err == nil { - prog := gatherDeployedPrograms(hc.config.StorageRoot, dr.Name) - hc.deploys[dr.Name] = prog - op.Refresh(ctx, hc.makeOperationQueryRequest()) - - op.ReportDeployingProgress(ctx, &protos.DeployingProgress{ - Hostname: hn, - Name: dr.Name, - Version: dr.Version, - State: "success", - Progress: 0, - Total: 0, - }) - } else { - logger.Println(err) - - op.ReportDeployingProgress(ctx, &protos.DeployingProgress{ - Hostname: hn, - Name: dr.Name, - Version: dr.Version, - State: "fail:" + err.Error(), - Progress: 0, - Total: 0, - }) - } + op.ReportDeployingProgress(ctx, &protos.DeployingProgress{ + Hostname: hn, + Name: dr.Name, + Version: dr.Version, + State: "fail:" + err.Error(), + Progress: 0, + Total: 0, + }) } case shared.Withdraw: diff --git a/client/deploy.go b/client/deploy.go index 445a48d..708ae6c 100644 --- a/client/deploy.go +++ b/client/deploy.go @@ -282,57 +282,9 @@ func copyfile(src, dst string) error { return nil } -func (hc *houstonClient) prepareUpdateSelf(req *shared.DeployRequest) (srcdir string, replacer string, err error) { - // 내가 스스로 업데이트 - // 다운로드 받고 압축 푼 다음에 교체용 프로세스 시작 - tempdir, err := os.MkdirTemp(os.TempDir(), "*") - if err != nil { - return "", "", err - } - fname, err := download(tempdir, hc.makeDownloadUrl(req.Url), req.AccessToken, nil) - if err != nil { - return "", "", err - } - - switch path.Ext(fname) { - case ".zip": - err = unzip(fname) - case ".tar": - err = untar(fname) - } - - if err != nil { - return "", "", err - } - - // houston version 파일 - err = os.WriteFile(path.Join(path.Dir(fname), "@version"), []byte(req.Version), 0644) - 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)) - err = copyfile(srcreplacer, replacer) - if err == nil { - err = os.Chmod(replacer, 0775) - } - - // replacer먼저 가져옴 - return filepath.ToSlash(tempdir), replacer, err -} - func (hc *houstonClient) deploy(req *shared.DeployRequest, cb func(*protos.DeployingProgress)) (err error) { logger.Println("start deploying") - defer func() { - if req.Name == "houston" && err == nil { - // houston.update 다운로드가 완료되었으므로 종료 - // 종료되고나면 스크립트가 알아서 재 실행 - hc.Shutdown() - } - }() var root string if req.Name == "houston" { // houston은 버전없이 houston.update폴더로 다운로드 diff --git a/make_houston_package.ps1 b/make_houston_package.ps1 index 05f6568..5b51726 100644 --- a/make_houston_package.ps1 +++ b/make_houston_package.ps1 @@ -10,19 +10,7 @@ go mod tidy go build -ldflags="-s -w" -tags=client . -cp houston .\replacer\houston -cp config.json .\replacer\config.json - -cd replacer -go build -ldflags="-s -w" . - -Compress-Archive -Path replacer -DestinationPath houston.zip -Force Compress-Archive -Path config.json -Update -DestinationPath houston.zip Compress-Archive -Path houston -Update -DestinationPath houston.zip -del houston -del config.json -del replacer -mv houston.zip ..\houston.zip -cd ..