프로세스 종료시 알림
This commit is contained in:
@ -153,23 +153,27 @@ func prepareProcessLaunch(storageRoot string, req *shared.StartProcessRequest) *
|
||||
|
||||
if err == nil && fi.IsDir() {
|
||||
exefile := "./" + path.Clean(strings.TrimPrefix(req.Args[0], "/"))
|
||||
err = set_permission(path.Join(verpath, exefile))
|
||||
if err != nil {
|
||||
logger.Println("set_permission failed :", err)
|
||||
return nil
|
||||
}
|
||||
os.Chmod(path.Join(verpath, exefile), 0777)
|
||||
|
||||
exef, _ := os.Executable()
|
||||
cmd := exec.Command(path.Join(path.Dir(exef), verpath, exefile), req.Args[1:]...)
|
||||
|
||||
if err := run_prelaunch_script(cmd.Args[0]); err != nil {
|
||||
logger.Println("run_prelaunch_script failed :", cmd.Args[0], err)
|
||||
return nil
|
||||
}
|
||||
|
||||
cmd.Dir = verpath
|
||||
stdin, _ := cmd.StdinPipe()
|
||||
|
||||
seq++
|
||||
return &procmeta{
|
||||
id: seq,
|
||||
cmd: cmd,
|
||||
name: req.Name,
|
||||
args: req.Args,
|
||||
version: req.Version,
|
||||
state: protos.ProcessState_Stopped,
|
||||
state: int32(protos.ProcessState_Stopped),
|
||||
stdin: stdin,
|
||||
}
|
||||
}
|
||||
@ -236,6 +240,17 @@ func (hc *houstonClient) launch(meta *procmeta) error {
|
||||
var metricBuffer []byte
|
||||
metricValues := make(map[string]metricValueAccessor)
|
||||
|
||||
defer func() {
|
||||
if meta.isState(protos.ProcessState_Running) {
|
||||
hc.operationChan <- &protos.OperationQueryResponse{
|
||||
Operation: string(shared.Exception),
|
||||
Args: map[string]string{
|
||||
"id": fmt.Sprintf("%d", meta.id),
|
||||
},
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
for {
|
||||
buff, err := reader.ReadBytes('\n')
|
||||
if err != nil {
|
||||
@ -319,11 +334,11 @@ func (hc *houstonClient) launch(meta *procmeta) error {
|
||||
go stdReader(meta.name, stdout)
|
||||
|
||||
logger.Println("startChildProcess :", meta.cmd.Args)
|
||||
|
||||
err = meta.cmd.Start()
|
||||
if err == nil {
|
||||
meta.state = protos.ProcessState_Running
|
||||
meta.setState(protos.ProcessState_Running)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@ -389,7 +404,7 @@ func (hc *houstonClient) stopChildProcess(req *shared.StopProcessRequest, op pro
|
||||
var remains []*procmeta
|
||||
var killing []*procmeta
|
||||
for _, proc := range hc.childProcs {
|
||||
if proc.state != protos.ProcessState_Running {
|
||||
if !proc.isState(protos.ProcessState_Running) {
|
||||
continue
|
||||
}
|
||||
|
||||
@ -419,7 +434,7 @@ func (hc *houstonClient) stopChildProcess(req *shared.StopProcessRequest, op pro
|
||||
|
||||
if len(killing) > 0 {
|
||||
for _, proc := range killing {
|
||||
proc.state = protos.ProcessState_Stopping
|
||||
proc.setState(protos.ProcessState_Stopping)
|
||||
if err := proc.cmd.Process.Signal(syscall.SIGTERM); err != nil {
|
||||
proc.cmd.Process.Signal(os.Kill)
|
||||
}
|
||||
@ -453,7 +468,7 @@ func (hc *houstonClient) restartChildProcess(req *shared.RestartProcessRequest,
|
||||
}
|
||||
}
|
||||
|
||||
proc.state = protos.ProcessState_Restart
|
||||
proc.setState(protos.ProcessState_Restart)
|
||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||
hc.exitChan <- proc.cmd
|
||||
|
||||
|
||||
Reference in New Issue
Block a user