When restarting, terminate process gracefully

This commit is contained in:
sanghee 2019-01-04 23:04:38 +09:00
parent e3e401cadd
commit 8252ea9f88
1 changed files with 15 additions and 4 deletions

View File

@ -148,7 +148,7 @@ func AutoBuild(files []string, isgenerate bool) {
} }
appName := appname appName := appname
if err == nil { if err == nil {
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
appName += ".exe" appName += ".exe"
} }
@ -183,9 +183,20 @@ func Kill() {
} }
}() }()
if cmd != nil && cmd.Process != nil { if cmd != nil && cmd.Process != nil {
err := cmd.Process.Kill() //err := cmd.Process.Kill()
if err != nil { cmd.Process.Signal(os.Interrupt)
beeLogger.Log.Errorf("Error while killing cmd process: %s", err) ch := make(chan struct{}, 1)
go func() {
cmd.Wait()
ch <- struct{}{}
}()
select {
case <-ch:
return
case <-time.After(10 * time.Second):
beeLogger.Log.Info("Timeout; Force kill cmd process")
cmd.Process.Kill()
return
} }
} }
} }