Patch for windows

Made interrupt call os.Kill for windows
Added check for process still running before killing it
This commit is contained in:
NotZippy
2018-10-30 13:28:44 -07:00
parent 5f558aca4e
commit 98e771cd01
4 changed files with 25 additions and 5 deletions

View File

@@ -15,6 +15,7 @@ import (
"github.com/revel/cmd/model"
"github.com/revel/cmd/utils"
"runtime"
)
// App contains the configuration for running a Revel app. (Not for the app itself)
@@ -101,11 +102,30 @@ func (cmd AppCmd) Run() {
func (cmd AppCmd) Kill() {
if cmd.Cmd != nil && (cmd.ProcessState == nil || !cmd.ProcessState.Exited()) {
// Windows appears to send the kill to all threads, shutting down the
// server before this can, this check will ensure the process is still running
if _, err := os.FindProcess(int(cmd.Process.Pid));err!=nil {
// Server has already exited
utils.Logger.Info("Killing revel server pid", "pid", cmd.Process.Pid)
return
}
// Send an interrupt signal to allow for a graceful shutdown
utils.Logger.Info("Killing revel server pid", "pid", cmd.Process.Pid)
err := cmd.Process.Signal(os.Interrupt)
var err error
if runtime.GOOS == "windows" {
// os.Interrupt is not available on windows
err = cmd.Process.Signal(os.Kill)
} else {
err = cmd.Process.Signal(os.Interrupt)
}
if err != nil {
utils.Logger.Fatal("Failed to kill revel server:", "error", err)
utils.Logger.Error(
"Revel app failed to kill process.",
"processid", cmd.Process.Pid,"error",err,
"killerror", cmd.Process.Kill())
return
}
// Wait for the shutdown