1
0
mirror of https://github.com/beego/bee.git synced 2024-11-21 23:50:54 +00:00

Kill the server process gracefully on Windows

See discussion in pull request #569
This commit is contained in:
Faissal Elamraoui 2019-01-23 10:21:40 +01:00
parent 4b7edb7235
commit 231e90d274

View File

@ -183,17 +183,24 @@ func Kill() {
} }
}() }()
if cmd != nil && cmd.Process != nil { if cmd != nil && cmd.Process != nil {
cmd.Process.Signal(os.Interrupt) // Windows does not support Interrupt
if runtime.GOOS == "windows" {
cmd.Process.Signal(os.Kill)
} else {
cmd.Process.Signal(os.Interrupt)
}
ch := make(chan struct{}, 1) ch := make(chan struct{}, 1)
go func() { go func() {
cmd.Wait() cmd.Wait()
ch <- struct{}{} ch <- struct{}{}
}() }()
select { select {
case <-ch: case <-ch:
return return
case <-time.After(10 * time.Second): case <-time.After(10 * time.Second):
beeLogger.Log.Info("Timeout; Force kill cmd process") beeLogger.Log.Info("Timeout. Force kill cmd process")
err := cmd.Process.Kill() err := cmd.Process.Kill()
if err != nil { if err != nil {
beeLogger.Log.Errorf("Error while killing cmd process: %s", err) beeLogger.Log.Errorf("Error while killing cmd process: %s", err)