Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b59a6bd

Browse filesBrowse files
committed
Retargets revel#593 and cleans up the code a bit
2 parents e65023b + eceec1f commit b59a6bd
Copy full SHA for b59a6bd

File tree

Expand file treeCollapse file tree

3 files changed

+39
-3
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+39
-3
lines changed

‎harness/app.go

Copy file name to clipboardExpand all lines: harness/app.go
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,23 @@ func (cmd AppCmd) Kill() {
9191
}
9292
}
9393

94+
// Gracefully terminate the app server if it's running
95+
func (cmd *AppCmd) Terminate() {
96+
if cmd.Cmd != nil && (cmd.ProcessState == nil || !cmd.ProcessState.Exited()) {
97+
revel.TRACE.Println("Terminating revel server pid", cmd.Process.Pid)
98+
cmd.Process.Signal(os.Interrupt)
99+
select {
100+
case <-cmd.waitChan():
101+
return
102+
case <-time.After(10 * time.Second):
103+
revel.TRACE.Println("Timeout; Force kill revel server pid", cmd.Process.Pid)
104+
cmd.Process.Kill()
105+
return
106+
}
107+
panic("Impossible")
108+
}
109+
}
110+
94111
// Return a channel that is notified when Wait() returns.
95112
func (cmd AppCmd) waitChan() <-chan struct{} {
96113
ch := make(chan struct{}, 1)

‎harness/build.go

Copy file name to clipboardExpand all lines: harness/build.go
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ package main
311311
312312
import (
313313
"flag"
314+
"os"
315+
"os/signal"
314316
"reflect"
315317
"github.com/revel/revel"{{range $k, $v := $.ImportPaths}}
316318
{{$v}} "{{$k}}"{{end}}
@@ -356,6 +358,20 @@ func main() {
356358
(*{{index $.ImportPaths .ImportPath}}.{{.StructName}})(nil),{{end}}
357359
}
358360
361+
signalChannel := make(chan os.Signal, 1)
362+
signal.Notify(signalChannel,
363+
os.Interrupt, os.Kill)
364+
365+
go func() {
366+
sig := <- signalChannel
367+
revel.INFO.Println("Server interrupt")
368+
switch sig {
369+
case os.Interrupt, os.Kill:
370+
revel.StopServer()
371+
break
372+
}
373+
} ()
374+
359375
revel.Run(*port)
360376
}
361377
`

‎harness/harness.go

Copy file name to clipboardExpand all lines: harness/harness.go
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ func NewHarness() *Harness {
120120
// Rebuild the Revel application and run it on the given port.
121121
func (h *Harness) Refresh() (err *revel.Error) {
122122
if h.app != nil {
123-
h.app.Kill()
123+
//h.app.Kill()
124+
h.app.cmd.Terminate()
124125
}
125126

126127
revel.TRACE.Println("Rebuild")
@@ -176,12 +177,14 @@ func (h *Harness) Run() {
176177
}
177178
}()
178179

179-
// Kill the app on signal.
180+
// Kill the app on signal
181+
// TODO: can we make this work if the app is being run directly instead of via the `revel run` command aka the harness?
180182
ch := make(chan os.Signal)
181183
signal.Notify(ch, os.Interrupt, os.Kill)
182184
<-ch
183185
if h.app != nil {
184-
h.app.Kill()
186+
//h.app.Kill()
187+
h.app.cmd.Terminate()
185188
}
186189
os.Exit(1)
187190
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.