From 98e771cd015e3399cdae0eea744db22a6af06218 Mon Sep 17 00:00:00 2001 From: NotZippy Date: Tue, 30 Oct 2018 13:28:44 -0700 Subject: [PATCH] Patch for windows Made interrupt call os.Kill for windows Added check for process still running before killing it --- harness/app.go | 24 ++++++++++++++++++++++-- model/command_config.go | 2 +- parser/appends.go | 2 +- version.go | 2 +- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/harness/app.go b/harness/app.go index 1ae5f81..3b855b8 100644 --- a/harness/app.go +++ b/harness/app.go @@ -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 diff --git a/model/command_config.go b/model/command_config.go index e46366a..1593226 100644 --- a/model/command_config.go +++ b/model/command_config.go @@ -88,7 +88,7 @@ type ( // The version command Version struct { ImportPath string `short:"a" long:"application-path" description:"Path to application folder" required:"false"` - Update bool `short:"u" long:"Update the framework and modules" required:"false"` + Update bool `short:"u" long:"update" description:"Update the framework and modules" required:"false"` } `command:"version"` } ) diff --git a/parser/appends.go b/parser/appends.go index 2990795..2dcc562 100644 --- a/parser/appends.go +++ b/parser/appends.go @@ -134,7 +134,7 @@ func appendAction(fset *token.FileSet, mm methodMap, decl ast.Decl, pkgImportPat var importPath string typeExpr := model.NewTypeExprFromAst(pkgName, field.Type) if !typeExpr.Valid { - utils.Logger.Warn("Warn: Didn't understand argument '%s' of action %s. Ignoring.", name, getFuncName(funcDecl)) + utils.Logger.Warnf("Warn: Didn't understand argument '%s' of action %s. Ignoring.", name, getFuncName(funcDecl)) return // We didn't understand one of the args. Ignore this action. } // Local object diff --git a/version.go b/version.go index 1fe6f42..253e085 100644 --- a/version.go +++ b/version.go @@ -6,7 +6,7 @@ package cmd const ( // Version current Revel version - Version = "0.21.0" + Version = "0.21.1" // BuildDate latest commit/release date BuildDate = "2018-10-30"