Compare commits
28 Commits
7c54fda9a2
...
kd-live
| Author | SHA1 | Date | |
|---|---|---|---|
| 31d77efe84 | |||
| 3ace1be27a | |||
| 3fccae1ef5 | |||
| 3dc121bc71 | |||
| 706339a386 | |||
| 849973c449 | |||
| 759dcaf00b | |||
| d1a192159b | |||
| db4769687c | |||
| 7a5696961f | |||
| 7418d847b7 | |||
| 4d9a25dd6b | |||
| b057730ad5 | |||
| 9bd09509c8 | |||
| d526a923ca | |||
| 1b57e9f87e | |||
| 30412bce70 | |||
| 4667d351a8 | |||
| 20dc204cb1 | |||
| 571f0d76df | |||
| 025e583f12 | |||
| 15dd1e544c | |||
| b3ed139431 | |||
| 45ab15d345 | |||
| c0a0f88220 | |||
| 02db65e06f | |||
| ed4ca6cfed | |||
| a8821b694b |
@ -164,25 +164,33 @@ func gatherDeployedPrograms(storageRoot, name string) []*protos.VersionAndArgs {
|
||||
}
|
||||
|
||||
func (hc *houstonClient) makeOperationQueryRequest() *protos.OperationQueryRequest {
|
||||
procs := make([]*protos.ProcessDescription, 0, len(hc.childProcs)+1)
|
||||
var procs []*protos.ProcessDescription
|
||||
var deploys []*protos.DeployedVersions
|
||||
|
||||
var selfname string
|
||||
var selfargs []string
|
||||
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()),
|
||||
})
|
||||
selfname = path.Base(os.Args[0])
|
||||
selfargs = os.Args[1:]
|
||||
} else {
|
||||
procs = append(procs, &protos.ProcessDescription{
|
||||
Name: "houston",
|
||||
Args: []string{},
|
||||
Version: hc.version,
|
||||
State: protos.ProcessState_Running,
|
||||
Pid: int32(os.Getpid()),
|
||||
})
|
||||
selfname = "houston"
|
||||
selfargs = []string{}
|
||||
}
|
||||
|
||||
procs = append(procs, &protos.ProcessDescription{
|
||||
Name: selfname,
|
||||
Args: selfargs,
|
||||
Version: hc.version,
|
||||
State: protos.ProcessState_Running,
|
||||
Pid: int32(os.Getpid()),
|
||||
})
|
||||
deploys = append(deploys, &protos.DeployedVersions{
|
||||
Name: selfname,
|
||||
Versions: []*protos.VersionAndArgs{
|
||||
{Version: hc.version, Args: selfargs},
|
||||
},
|
||||
})
|
||||
|
||||
for _, child := range hc.childProcs {
|
||||
procs = append(procs, &protos.ProcessDescription{
|
||||
Name: child.name,
|
||||
@ -193,13 +201,13 @@ func (hc *houstonClient) makeOperationQueryRequest() *protos.OperationQueryReque
|
||||
})
|
||||
}
|
||||
|
||||
var deploys []*protos.DeployedVersions
|
||||
for name, prog := range hc.deploys {
|
||||
deploys = append(deploys, &protos.DeployedVersions{
|
||||
Name: name,
|
||||
Versions: prog,
|
||||
})
|
||||
}
|
||||
|
||||
hn, _ := os.Hostname()
|
||||
return &protos.OperationQueryRequest{
|
||||
Hostname: hn,
|
||||
|
||||
@ -265,7 +265,7 @@ func (hc *houstonClient) prepareUpdateSelf(req *shared.DeployRequest) (srcdir st
|
||||
}
|
||||
|
||||
// houston version 파일
|
||||
err = os.WriteFile(path.Join(fname, "@version"), []byte(req.Version), 0444)
|
||||
err = os.WriteFile(path.Join(path.Dir(fname), "@version"), []byte(req.Version), 0644)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
@ -102,11 +102,12 @@ func zipLogFiles(storageRoot string, req *shared.UploadRequest, start, except st
|
||||
defer w.Close()
|
||||
|
||||
oldestFile := ""
|
||||
for _, file := range matches {
|
||||
for i, file := range matches {
|
||||
if file == root {
|
||||
continue
|
||||
}
|
||||
if len(except) > 0 && file >= except {
|
||||
matches = matches[:i]
|
||||
break
|
||||
}
|
||||
if len(start) > 0 && file < start {
|
||||
@ -480,11 +481,7 @@ func (hc *houstonClient) uploadFiles(req *shared.UploadRequest) error {
|
||||
// 전체 파일을 대상으로
|
||||
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 {
|
||||
os.Remove(oldf)
|
||||
}
|
||||
} else {
|
||||
if err = hc.uploadZipLogFile(zipFile, req.Name, req.Version); err != nil {
|
||||
logger.Println("uploadZipLogFile failed :", err)
|
||||
}
|
||||
} else if err != nil {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
nohup /home/opdev/houston -client -logfile &
|
||||
nohup /home/opdev/houston -client -logfile > /dev/null &
|
||||
|
||||
|
||||
@ -11,11 +11,21 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func copy(src, dst string) error {
|
||||
func copy(src, dst string, stdlog *log.Logger) error {
|
||||
fi, err := os.Stat(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if fi.IsDir() {
|
||||
entries, _ := os.ReadDir(src)
|
||||
for _, ent := range entries {
|
||||
if err := copy(path.Join(src, ent.Name()), path.Join(dst, ent.Name()), stdlog); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
inmode := fi.Mode()
|
||||
|
||||
in, err := os.Open(src)
|
||||
@ -45,6 +55,7 @@ func copy(src, dst string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
stdlog.Println("file copied :", src, dst)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -70,33 +81,21 @@ func main() {
|
||||
|
||||
stdlog.Println("target is terminated")
|
||||
|
||||
selfext, _ := os.Executable()
|
||||
selfext = path.Base(selfext)
|
||||
nextArgs := args[4:]
|
||||
entries, _ := os.ReadDir(args[2])
|
||||
for _, ent := range entries {
|
||||
if ent.Name() == selfext {
|
||||
continue
|
||||
}
|
||||
// replacer 제거. 내가 돌고 있으므로 복사는 안된다.
|
||||
// 내가 실행되기 전에 이미 복사가 되서 나는 최신 버전임
|
||||
os.Remove(path.Join(args[2], os.Args[0]))
|
||||
if err := copy(args[2], "", stdlog); err != nil {
|
||||
stdlog.Fatal(err)
|
||||
}
|
||||
|
||||
if ent.IsDir() {
|
||||
if err := os.MkdirAll(ent.Name(), 0775); err != nil {
|
||||
stdlog.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
if ent.Name() == "@args" {
|
||||
var tempArgs []string
|
||||
argfile, _ := os.Open(path.Join(args[2], ent.Name()))
|
||||
dec := json.NewDecoder(argfile)
|
||||
if dec.Decode(&tempArgs) == nil {
|
||||
nextArgs = tempArgs
|
||||
}
|
||||
} else if err := copy(path.Join(args[2], ent.Name()), ent.Name()); err != nil {
|
||||
stdlog.Println("copy failed :", path.Join(args[2], ent.Name()), ent.Name())
|
||||
stdlog.Fatal(err)
|
||||
}
|
||||
nextArgs := args[4:]
|
||||
if bt, _ := os.ReadFile("@args"); len(bt) > 0 {
|
||||
var tempArgs []string
|
||||
if json.Unmarshal(bt, &tempArgs) == nil {
|
||||
nextArgs = tempArgs
|
||||
}
|
||||
}
|
||||
os.Remove("@args")
|
||||
|
||||
err := os.RemoveAll(args[2])
|
||||
if err != nil {
|
||||
|
||||
@ -34,6 +34,16 @@ func (h *houstonHandler) GetAgents(w http.ResponseWriter, r *http.Request) {
|
||||
enc.Encode(allHosts)
|
||||
}
|
||||
|
||||
func readTagsFromFile(paths ...string) string {
|
||||
raw, _ := os.ReadFile(path.Join(paths...))
|
||||
if len(raw) > 0 {
|
||||
tag := string(raw)
|
||||
return strings.Trim(tag, "\n")
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func (h *houstonHandler) GetDeploySources(w http.ResponseWriter, r *http.Request) {
|
||||
files, err := os.ReadDir(h.deployPath)
|
||||
if err != nil {
|
||||
@ -43,19 +53,31 @@ func (h *houstonHandler) GetDeploySources(w http.ResponseWriter, r *http.Request
|
||||
}
|
||||
|
||||
getVersions := func(name string) []string {
|
||||
var out []string
|
||||
vers, _ := os.ReadDir(path.Join(h.deployPath, name))
|
||||
mytags := readTagsFromFile(h.deployPath, name, "@tags")
|
||||
out := []string{
|
||||
mytags,
|
||||
}
|
||||
for _, fd := range vers {
|
||||
if fd.IsDir() {
|
||||
ver := fd.Name()
|
||||
files, _ := os.ReadDir(path.Join(h.deployPath, name, ver))
|
||||
vertags := readTagsFromFile(h.deployPath, name, ver, "@tags")
|
||||
if len(files) > 0 {
|
||||
downloadpath := path.Join(sub_folder_name_deploys, name, ver, files[0].Name())
|
||||
ver = fmt.Sprintf("%s:%s", ver, downloadpath)
|
||||
for _, file := range files {
|
||||
if strings.HasPrefix(file.Name(), "@") {
|
||||
continue
|
||||
}
|
||||
|
||||
downloadpath := path.Join(sub_folder_name_deploys, name, ver, file.Name())
|
||||
ver = fmt.Sprintf("%s:%s", ver+mytags+vertags, downloadpath)
|
||||
break
|
||||
}
|
||||
}
|
||||
out = append(out, ver)
|
||||
}
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
@ -100,8 +122,12 @@ func (h *houstonHandler) UploadDeploySource(w http.ResponseWriter, r *http.Reque
|
||||
|
||||
if version == "config" {
|
||||
filename = path.Join(h.deployPath, name, version, "config"+ext)
|
||||
tags := readTagsFromFile(h.deployPath, name, version, "@tags")
|
||||
if !strings.Contains(tags, "#hidden") {
|
||||
tags = tags + "#hidden"
|
||||
os.WriteFile(path.Join(h.deployPath, name, version, "@tags"), []byte(tags), 0644)
|
||||
}
|
||||
} else {
|
||||
// deploys 폴더는 파일시스템 서비스이므로 다운로드 가능
|
||||
filename = path.Join(h.deployPath, name, version, name+ext)
|
||||
}
|
||||
|
||||
@ -223,6 +249,10 @@ func (h *houstonHandler) Deploy(w http.ResponseWriter, r *http.Request) {
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.HasPrefix(fd.Name(), "@") {
|
||||
continue
|
||||
}
|
||||
|
||||
fi, _ := fd.Info()
|
||||
if fi.ModTime().After(latestTime) {
|
||||
latestFilename = fi.Name()
|
||||
|
||||
@ -165,8 +165,6 @@ func marshal(argval reflect.Value, output map[string]string) map[string]string {
|
||||
}
|
||||
|
||||
func (os *operationServer) Query(svr protos.Operation_QueryServer) error {
|
||||
// 서버는 업데이트가 있는지 확인하고 있으면 stream에 응답을 보낸다.
|
||||
// 업데이트가 없으면 대기
|
||||
desc, err := svr.Recv()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -186,9 +186,7 @@ func (hs *houstonServer) Start() error {
|
||||
|
||||
go func() {
|
||||
hc.Start()
|
||||
logger.Println("houstonClient is finished")
|
||||
if atomic.AddInt32(&closeCount, 1) == 1 {
|
||||
logger.Println("try stop houstonServer")
|
||||
hs.Stop()
|
||||
}
|
||||
}()
|
||||
@ -197,17 +195,15 @@ func (hs *houstonServer) Start() error {
|
||||
err = hs.rpcServer.Serve(lis)
|
||||
if atomic.AddInt32(&closeCount, 1) == 1 {
|
||||
if hc != nil {
|
||||
logger.Println("try stop houstonClient")
|
||||
hc.Shutdown()
|
||||
}
|
||||
}
|
||||
logger.Println("houstonServer is finished")
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (hs *houstonServer) Stop() {
|
||||
hs.rpcServer.GracefulStop()
|
||||
hs.rpcServer.Stop()
|
||||
}
|
||||
|
||||
func (hs *houstonServer) Operation() Operation {
|
||||
|
||||
Reference in New Issue
Block a user