From a467bf431334ee21a8282f957fed164554884553 Mon Sep 17 00:00:00 2001 From: Bart Jeukendrup Date: Sat, 30 Nov 2019 15:25:51 +0100 Subject: [PATCH] First interrupt before killing a daemon on shutdown --- shell/shell.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/shell/shell.go b/shell/shell.go index c0b6aec..ea4483c 100644 --- a/shell/shell.go +++ b/shell/shell.go @@ -7,7 +7,9 @@ import ( "io" "os" "os/exec" + "runtime" "sync" + "time" "github.com/cortesi/termlog" ) @@ -157,6 +159,22 @@ func (e *Executor) Signal(sig os.Signal) error { } func (e *Executor) Stop() error { + // Windows does not support Interrupt + if runtime.GOOS == "windows" { + return e.Signal(os.Kill) + } + + err := e.Signal(os.Interrupt) + if err != nil { + return err + } + + time.Sleep(2 * time.Second) + + if !e.Running() { + return nil + } + return e.Signal(os.Kill) }