1
0
mirror of https://github.com/beego/bee.git synced 2024-12-22 10:00:50 +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 {
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)
go func() {
cmd.Wait()
ch <- struct{}{}
}()
select {
case <-ch:
return
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()
if err != nil {
beeLogger.Log.Errorf("Error while killing cmd process: %s", err)