houstonClient도 버전 관리
This commit is contained in:
@ -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():
|
||||
|
||||
@ -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))
|
||||
|
||||
2
main.go
2
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
|
||||
|
||||
@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user