중지할 프로세스를 동시에 처리
This commit is contained in:
@ -22,6 +22,7 @@ import (
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"repositories.action2quare.com/ayo/gocommon"
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
"repositories.action2quare.com/ayo/houston/shared"
|
||||
"repositories.action2quare.com/ayo/houston/shared/protos"
|
||||
@ -431,22 +432,14 @@ func NewClient(standalone bool) (HoustonClient, error) {
|
||||
id64, _ := strconv.ParseInt(idstr, 10, 0)
|
||||
id := int32(id64)
|
||||
|
||||
var killing *procmeta
|
||||
var remains []*procmeta
|
||||
for _, meta := range hc.childProcs {
|
||||
if meta.id == id {
|
||||
killing = meta
|
||||
} else {
|
||||
remains = append(remains, meta)
|
||||
hc.childProcs = gocommon.ShrinkSlice(hc.childProcs, func(e *procmeta) bool {
|
||||
if e.id == id {
|
||||
e.cmd.Wait()
|
||||
e.cmd.Process.Release()
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
if killing != nil {
|
||||
killing.cmd.Wait()
|
||||
killing.cmd.Process.Release()
|
||||
}
|
||||
|
||||
hc.childProcs = remains
|
||||
return false
|
||||
})
|
||||
|
||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||
}
|
||||
@ -523,7 +516,7 @@ func (hc *houstonClient) Start() {
|
||||
if client != nil {
|
||||
err := hc.checkOperation(client)
|
||||
if err != nil {
|
||||
logger.Println("hc.checkUpdate failed :", err)
|
||||
logger.Println("grpc.DialContext hc.checkOperation failed :", err)
|
||||
|
||||
client = nil
|
||||
}
|
||||
|
||||
@ -422,8 +422,6 @@ func (hc *houstonClient) startChildProcess(req *shared.StartProcessRequest, op p
|
||||
return nil
|
||||
}
|
||||
|
||||
var errNoRunningProcess = errors.New("no running processed")
|
||||
|
||||
func (hc *houstonClient) stopChildProcess(req *shared.StopProcessRequest, op protos.OperationClient) error {
|
||||
if req.Version == "latest" {
|
||||
// 최신 버전을 찾음
|
||||
@ -435,8 +433,23 @@ func (hc *houstonClient) stopChildProcess(req *shared.StopProcessRequest, op pro
|
||||
req.Version = latest
|
||||
}
|
||||
|
||||
var remains []*procmeta
|
||||
var killing []*procmeta
|
||||
killer := func(proc *procmeta) {
|
||||
proc.setState(protos.ProcessState_Stopping)
|
||||
if err := proc.cmd.Process.Signal(syscall.SIGTERM); err != nil {
|
||||
proc.cmd.Process.Signal(os.Kill)
|
||||
}
|
||||
|
||||
go func() {
|
||||
proc.cmd.Wait()
|
||||
hc.operationChan <- &protos.OperationQueryResponse{
|
||||
Operation: string(shared.Exception),
|
||||
Args: map[string]string{
|
||||
"id": fmt.Sprintf("%d", proc.id),
|
||||
},
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
for _, proc := range hc.childProcs {
|
||||
if !proc.isState(protos.ProcessState_Running) {
|
||||
continue
|
||||
@ -445,50 +458,22 @@ func (hc *houstonClient) stopChildProcess(req *shared.StopProcessRequest, op pro
|
||||
if req.Pid != 0 {
|
||||
if req.Pid == int32(proc.cmd.Process.Pid) {
|
||||
// 해당 pid만 제거
|
||||
killing = append(killing, proc)
|
||||
} else {
|
||||
remains = append(remains, proc)
|
||||
killer(proc)
|
||||
}
|
||||
} else if proc.name == req.Name {
|
||||
if len(req.Version) == 0 {
|
||||
// program 다 정지
|
||||
killing = append(killing, proc)
|
||||
killer(proc)
|
||||
} else if req.Version == proc.version {
|
||||
// program의 특정 버전만 정지
|
||||
killing = append(killing, proc)
|
||||
} else {
|
||||
// 해당 사항 없음
|
||||
remains = append(remains, proc)
|
||||
killer(proc)
|
||||
}
|
||||
} else {
|
||||
// 해당 사항 없음
|
||||
remains = append(remains, proc)
|
||||
}
|
||||
}
|
||||
|
||||
if len(killing) > 0 {
|
||||
for _, proc := range killing {
|
||||
proc.setState(protos.ProcessState_Stopping)
|
||||
if err := proc.cmd.Process.Signal(syscall.SIGTERM); err != nil {
|
||||
proc.cmd.Process.Signal(os.Kill)
|
||||
}
|
||||
}
|
||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||
|
||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||
|
||||
for _, proc := range killing {
|
||||
proc.cmd.Wait()
|
||||
proc.cmd.Process.Release()
|
||||
}
|
||||
|
||||
hc.childProcs = remains
|
||||
|
||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
return errNoRunningProcess
|
||||
return nil
|
||||
}
|
||||
|
||||
func (hc *houstonClient) restartChildProcess(req *shared.RestartProcessRequest, op protos.OperationClient) error {
|
||||
|
||||
Reference in New Issue
Block a user