Merge pull request #569 from sangheee/develop

Kill the server process gracefully
This commit is contained in:
Faissal Elamraoui 2019-01-10 08:30:18 +01:00 committed by GitHub
commit 12019e22af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 3 deletions

View File

@ -183,9 +183,22 @@ func Kill() {
}
}()
if cmd != nil && cmd.Process != nil {
err := cmd.Process.Kill()
if err != nil {
beeLogger.Log.Errorf("Error while killing cmd process: %s", err)
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")
err := cmd.Process.Kill()
if err != nil {
beeLogger.Log.Errorf("Error while killing cmd process: %s", err)
}
return
}
}
}