client도 storageroot지원

This commit is contained in:
2023-06-14 14:16:47 +09:00
parent 46aedbe767
commit 279c9f47f0
7 changed files with 60 additions and 36 deletions

View File

@ -74,8 +74,8 @@ func (hc *houstonClient) uploadZipLogFile(zipFile string, name string, version s
return nil
}
func zipLogFiles(req *shared.UploadRequest, start, except string) (string, []string, error) {
root := path.Join(req.Name, req.Version)
func zipLogFiles(storageRoot string, req *shared.UploadRequest, start, except string) (string, []string, error) {
root := path.Join(storageRoot, req.Name, req.Version)
matches, err := filepath.Glob(path.Join(root, req.Filter))
if err != nil {
return "", nil, err
@ -164,14 +164,14 @@ func zipLogFiles(req *shared.UploadRequest, start, except string) (string, []str
//return nil
}
func prepareProcessLaunch(req *shared.StartProcessRequest) *procmeta {
func prepareProcessLaunch(storageRoot string, req *shared.StartProcessRequest) *procmeta {
re := regexp.MustCompile(`[^\s"']+|"([^"]*)"|'([^']*)`)
args := re.FindAllString(req.Args, -1)
if len(args) == 0 {
return nil
}
verpath := path.Join(req.Name, req.Version)
verpath := path.Join(storageRoot, req.Name, req.Version)
fi, err := os.Stat(verpath)
if err == nil && fi.IsDir() {
@ -258,7 +258,7 @@ func (hc *houstonClient) launch(meta *procmeta) error {
startFile := uploadStartFile
uploadStartFile = nextFile
go func(startFile, nextFile string) {
zipFile, srcFiles, err := zipLogFiles(req, startFile, nextFile)
zipFile, srcFiles, err := zipLogFiles(hc.config.StorageRoot, req, startFile, nextFile)
if err == nil && len(zipFile) > 0 && len(srcFiles) > 0 {
if err = hc.uploadZipLogFile(zipFile, meta.name, meta.version); err == nil {
for _, oldf := range srcFiles {
@ -327,7 +327,7 @@ func (hc *houstonClient) startChildProcess(req *shared.StartProcessRequest, op p
logger.Println("startChildProcess :", *req)
if req.Version == "latest" {
// 최신 버전을 찾음
latest, err := shared.FindLastestVersion(req.Name)
latest, err := shared.FindLastestVersion(hc.config.StorageRoot, req.Name)
if err != nil {
return err
}
@ -335,7 +335,7 @@ func (hc *houstonClient) startChildProcess(req *shared.StartProcessRequest, op p
req.Version = latest
}
meta := prepareProcessLaunch(req)
meta := prepareProcessLaunch(hc.config.StorageRoot, req)
if meta == nil {
return errPrepareprocessLaunchFailed
}
@ -351,12 +351,12 @@ func (hc *houstonClient) startChildProcess(req *shared.StartProcessRequest, op p
}
}
if argfile, err := os.Create(path.Join(req.Name, "@args")); err == nil {
if argfile, err := os.Create(path.Join(hc.config.StorageRoot, req.Name, "@args")); err == nil {
enc := json.NewEncoder(argfile)
enc.Encode(meta.cmd.Args)
argfile.Close()
}
if argfile, err := os.Create(path.Join(req.Name, req.Version, "@args")); err == nil {
if argfile, err := os.Create(path.Join(hc.config.StorageRoot, req.Name, req.Version, "@args")); err == nil {
enc := json.NewEncoder(argfile)
enc.Encode(meta.cmd.Args)
argfile.Close()
@ -373,7 +373,7 @@ var errNoRunningProcess = errors.New("no running processed")
func (hc *houstonClient) stopChildProcess(req *shared.StopProcessRequest, op protos.OperationClient) error {
if req.Version == "latest" {
// 최신 버전을 찾음
latest, err := shared.FindLastestVersion(req.Name)
latest, err := shared.FindLastestVersion(hc.config.StorageRoot, req.Name)
if err != nil {
return err
}
@ -439,7 +439,7 @@ func (hc *houstonClient) stopChildProcess(req *shared.StopProcessRequest, op pro
func (hc *houstonClient) restartChildProcess(req *shared.RestartProcessRequest, op protos.OperationClient) error {
if req.Version == "latest" {
// 최신 버전을 찾음
latest, err := shared.FindLastestVersion(req.Name)
latest, err := shared.FindLastestVersion(hc.config.StorageRoot, req.Name)
if err != nil {
return err
}
@ -490,7 +490,7 @@ func (hc *houstonClient) restartChildProcess(req *shared.RestartProcessRequest,
func (hc *houstonClient) uploadFiles(req *shared.UploadRequest) error {
if req.Version == "latest" {
// 최신 버전을 찾음
latest, err := shared.FindLastestVersion(req.Name)
latest, err := shared.FindLastestVersion(hc.config.StorageRoot, req.Name)
if err != nil {
return err
}
@ -509,7 +509,7 @@ func (hc *houstonClient) uploadFiles(req *shared.UploadRequest) error {
// 실행 중이 아닌 폴더에서도 대상을 찾는다
// 전체 파일을 대상으로
zipFile, srcFiles, err := zipLogFiles(req, "", "")
zipFile, srcFiles, err := zipLogFiles(hc.config.StorageRoot, req, "", "")
if err == nil && len(zipFile) > 0 && len(srcFiles) > 0 {
if err = hc.uploadZipLogFile(zipFile, req.Name, req.Version); err == nil {
for _, oldf := range srcFiles {