wangyj 6 years ago
parent e8e3e0e71d
commit 235e10c98e

@ -304,20 +304,17 @@ func (p *Process) waitNextRetry() {
} }
func (p *Process) stopCommand() { func (p *Process) stopCommand() {
fmt.Println("stop 111", p)
p.mu.Lock() p.mu.Lock()
defer p.mu.Unlock() defer p.mu.Unlock()
defer p.SetState(Stopped) defer p.SetState(Stopped)
if p.cmd == nil { if p.cmd == nil {
return return
} }
fmt.Println("stop 222", p)
p.SetState(Stopping) p.SetState(Stopping)
if p.cmd.Process != nil { if p.cmd.Process != nil {
p.cmd.Process.Signal(syscall.SIGTERM) // TODO(ssx): add it to config p.cmd.Process.Signal(syscall.SIGTERM) // TODO(ssx): add it to config
} }
fmt.Println("stop 333", p)
select { select {
case <-GoFunc(p.cmd.Wait): case <-GoFunc(p.cmd.Wait):
p.RunNotification(FSMState("quit normally")) p.RunNotification(FSMState("quit normally"))
@ -327,9 +324,7 @@ func (p *Process) stopCommand() {
log.Printf("program(%s) terminate all", p.Name) log.Printf("program(%s) terminate all", p.Name)
p.cmd.Terminate(syscall.SIGKILL) // cleanup p.cmd.Terminate(syscall.SIGKILL) // cleanup
} }
fmt.Println("stop 444", p)
err := p.cmd.Wait() // This is OK, because Signal KILL will definitely work err := p.cmd.Wait() // This is OK, because Signal KILL will definitely work
fmt.Println("stop 555", p)
prefixStr := "\n--- GOSUV LOG " + time.Now().Format("2006-01-02 15:04:05") prefixStr := "\n--- GOSUV LOG " + time.Now().Format("2006-01-02 15:04:05")
if err == nil { if err == nil {
io.WriteString(p.cmd.Stderr, fmt.Sprintf("%s exit success ---\n\n", prefixStr)) io.WriteString(p.cmd.Stderr, fmt.Sprintf("%s exit success ---\n\n", prefixStr))
@ -363,10 +358,8 @@ func (p *Process) startCommand() {
// 如果是running状态重置 retryLeft // 如果是running状态重置 retryLeft
p.retryLeft = p.StartRetries p.retryLeft = p.StartRetries
go func() { go func() {
log.Println("开始运行 1111")
errC := GoFunc(p.cmd.Wait) errC := GoFunc(p.cmd.Wait)
startTime := time.Now() startTime := time.Now()
log.Println("开始运行 2222")
select { select {
case <-errC: case <-errC:
// if p.cmd.Wait() returns, it means program and its sub process all quited. no need to kill again // if p.cmd.Wait() returns, it means program and its sub process all quited. no need to kill again
@ -385,7 +378,6 @@ func (p *Process) startCommand() {
log.Println("recv stop command") log.Println("recv stop command")
p.stopCommand() // clean up all process p.stopCommand() // clean up all process
} }
log.Println("开始运行 3333")
}() }()
} }

Loading…
Cancel
Save