houston server에 재접속시 autorun이 다시 불리는 문제 수정
This commit is contained in:
@ -317,6 +317,7 @@ func NewClient(standalone bool) (HoustonClient, error) {
|
||||
|
||||
case newClient := <-hc.clientChan:
|
||||
op = protos.NewOperationClient(newClient)
|
||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||
|
||||
case exited := <-exitChan:
|
||||
var newprocs []*procmeta
|
||||
@ -331,11 +332,15 @@ func NewClient(standalone bool) (HoustonClient, error) {
|
||||
proc.cmd.Process.Release()
|
||||
|
||||
if proc.isState(protos.ProcessState_Restart) {
|
||||
hc.startChildProcess(&shared.StartProcessRequest{
|
||||
if err := hc.startChildProcess(&shared.StartProcessRequest{
|
||||
Version: proc.version,
|
||||
Name: proc.name,
|
||||
Args: proc.args,
|
||||
}, op)
|
||||
}); err != nil {
|
||||
logger.ErrorWithCallStack(err)
|
||||
} else {
|
||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||
}
|
||||
}
|
||||
}(proc)
|
||||
}
|
||||
@ -422,8 +427,10 @@ func NewClient(standalone bool) (HoustonClient, error) {
|
||||
case shared.Start:
|
||||
var sr shared.StartProcessRequest
|
||||
unmarshal(&sr, resp.Args)
|
||||
if err := hc.startChildProcess(&sr, op); err != nil {
|
||||
logger.Println(err)
|
||||
if err := hc.startChildProcess(&sr); err != nil {
|
||||
logger.ErrorWithCallStack(err)
|
||||
} else {
|
||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||
}
|
||||
|
||||
case shared.Stop:
|
||||
@ -517,6 +524,38 @@ func (hc *houstonClient) Start() {
|
||||
reconnCount := 0
|
||||
time.Sleep(time.Second)
|
||||
|
||||
if autorun != nil && len(*autorun) > 0 {
|
||||
hascount := strings.Split(*autorun, "/")
|
||||
var service string
|
||||
count := 1
|
||||
if len(hascount) > 1 {
|
||||
service = hascount[0]
|
||||
if len(hascount[1]) > 0 {
|
||||
count, _ = strconv.Atoi(hascount[1])
|
||||
}
|
||||
} else {
|
||||
service = *autorun
|
||||
}
|
||||
|
||||
if cmd, ok := hc.config.Autorun[service]; ok {
|
||||
// service 서비스
|
||||
for i := 0; i < count; i++ {
|
||||
sr := shared.StartProcessRequest{
|
||||
Name: service,
|
||||
Version: cmd.Version,
|
||||
Args: append([]string{cmd.Exec}, cmd.Args...),
|
||||
}
|
||||
|
||||
if err := hc.startChildProcess(&sr); err != nil {
|
||||
logger.Println("startChildProcess failed by autorun :", err)
|
||||
logger.ErrorWithCallStack(err)
|
||||
} else {
|
||||
logger.Println("autorun success :", sr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-hc.ctx.Done():
|
||||
@ -548,7 +587,6 @@ func (hc *houstonClient) Start() {
|
||||
err := hc.checkOperation(client)
|
||||
if err != nil {
|
||||
logger.Println("grpc.DialContext hc.checkOperation failed :", err)
|
||||
|
||||
client = nil
|
||||
}
|
||||
}
|
||||
@ -580,37 +618,6 @@ func (hc *houstonClient) checkOperation(client *grpc.ClientConn) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if autorun != nil && len(*autorun) > 0 {
|
||||
hascount := strings.Split(*autorun, "/")
|
||||
var service string
|
||||
count := 1
|
||||
if len(hascount) > 1 {
|
||||
service = hascount[0]
|
||||
if len(hascount[1]) > 0 {
|
||||
count, _ = strconv.Atoi(hascount[1])
|
||||
}
|
||||
} else {
|
||||
service = *autorun
|
||||
}
|
||||
|
||||
if cmd, ok := hc.config.Autorun[service]; ok {
|
||||
// service 서비스
|
||||
for i := 0; i < count; i++ {
|
||||
sr := shared.StartProcessRequest{
|
||||
Name: service,
|
||||
Version: cmd.Version,
|
||||
Args: append([]string{cmd.Exec}, cmd.Args...),
|
||||
}
|
||||
|
||||
if err := hc.startChildProcess(&sr, op); err != nil {
|
||||
logger.Println("startChildProcess failed by autorun :", err)
|
||||
} else {
|
||||
logger.Println("autorun success :", sr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for {
|
||||
update, err := cl.Recv()
|
||||
if err != nil {
|
||||
|
||||
@ -435,7 +435,7 @@ func (hc *houstonClient) launch(meta *procmeta) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (hc *houstonClient) startChildProcess(req *shared.StartProcessRequest, op protos.OperationClient) error {
|
||||
func (hc *houstonClient) startChildProcess(req *shared.StartProcessRequest) error {
|
||||
meta, err := prepareProcessLaunch(hc.config.StorageRoot, req)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -465,8 +465,6 @@ func (hc *houstonClient) startChildProcess(req *shared.StartProcessRequest, op p
|
||||
}
|
||||
|
||||
hc.childProcs = append(hc.childProcs, meta)
|
||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user