Merge pull request #10616 from hashicorp/b-catch-sigterm
Forward SIGTERM and handle that as an interrupt
This commit is contained in:
commit
c002de9cf9
|
@ -223,7 +223,8 @@ func makeShutdownCh() <-chan struct{} {
|
|||
resultCh := make(chan struct{})
|
||||
|
||||
signalCh := make(chan os.Signal, 4)
|
||||
signal.Notify(signalCh, interruptSignals...)
|
||||
signal.Notify(signalCh, ignoreSignals...)
|
||||
signal.Notify(signalCh, forwardSignals...)
|
||||
go func() {
|
||||
for {
|
||||
<-signalCh
|
||||
|
|
3
main.go
3
main.go
|
@ -60,7 +60,8 @@ func realMain() int {
|
|||
wrapConfig.Handler = panicHandler(logTempFile)
|
||||
wrapConfig.Writer = io.MultiWriter(logTempFile, logWriter)
|
||||
wrapConfig.Stdout = outW
|
||||
wrapConfig.IgnoreSignals = interruptSignals
|
||||
wrapConfig.IgnoreSignals = ignoreSignals
|
||||
wrapConfig.ForwardSignals = forwardSignals
|
||||
exitStatus, err := panicwrap.Wrap(&wrapConfig)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Couldn't start Terraform: %s", err)
|
||||
|
|
|
@ -7,7 +7,5 @@ import (
|
|||
"syscall"
|
||||
)
|
||||
|
||||
var interruptSignals []os.Signal = []os.Signal{
|
||||
os.Interrupt,
|
||||
syscall.SIGTERM,
|
||||
}
|
||||
var ignoreSignals = []os.Signal{os.Interrupt}
|
||||
var forwardSignals = []os.Signal{syscall.SIGTERM}
|
||||
|
|
|
@ -6,4 +6,5 @@ import (
|
|||
"os"
|
||||
)
|
||||
|
||||
var interruptSignals []os.Signal = []os.Signal{os.Interrupt}
|
||||
var ignoreSignals = []os.Signal{os.Interrupt}
|
||||
var forwardSignals []os.Signal
|
||||
|
|
|
@ -68,6 +68,13 @@ type WrapConfig struct {
|
|||
// Catch and igore these signals in the parent process, let the child
|
||||
// handle them gracefully.
|
||||
IgnoreSignals []os.Signal
|
||||
|
||||
// Catch these signals in the parent process and manually forward
|
||||
// them to the child process. Some signals such as SIGINT are usually
|
||||
// sent to the entire process group so setting it isn't necessary. Other
|
||||
// signals like SIGTERM are only sent to the parent process and need
|
||||
// to be forwarded. This defaults to empty.
|
||||
ForwardSignals []os.Signal
|
||||
}
|
||||
|
||||
// BasicWrap calls Wrap with the given handler function, using defaults
|
||||
|
@ -166,16 +173,23 @@ func Wrap(c *WrapConfig) (int, error) {
|
|||
// Listen to signals and capture them forever. We allow the child
|
||||
// process to handle them in some way.
|
||||
sigCh := make(chan os.Signal)
|
||||
fwdSigCh := make(chan os.Signal)
|
||||
if len(c.IgnoreSignals) == 0 {
|
||||
c.IgnoreSignals = []os.Signal{os.Interrupt}
|
||||
}
|
||||
signal.Notify(sigCh, c.IgnoreSignals...)
|
||||
signal.Notify(sigCh, c.ForwardSignals...)
|
||||
go func() {
|
||||
defer signal.Stop(sigCh)
|
||||
defer signal.Stop(fwdSigCh)
|
||||
for {
|
||||
select {
|
||||
case <-doneCh:
|
||||
return
|
||||
case s := <-fwdSigCh:
|
||||
if cmd.Process != nil {
|
||||
cmd.Process.Signal(s)
|
||||
}
|
||||
case <-sigCh:
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2079,10 +2079,10 @@
|
|||
"revision": "314aad379a39f6ad5bcca278e6757d9abbb3a52e"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "kTntIB9SdU1NsCqKwDkUr99qaj0=",
|
||||
"checksumSHA1": "AykrbOR+O+Yp6DQHfwe31+iyFi0=",
|
||||
"path": "github.com/mitchellh/panicwrap",
|
||||
"revision": "fde185d0dfb5ecac6e6b201e8855da798ebcd76f",
|
||||
"revisionTime": "2016-11-21T18:34:54Z"
|
||||
"revision": "ba9e1a65e0f7975f055d50a2c0201c50d941c24c",
|
||||
"revisionTime": "2016-12-08T17:03:02Z"
|
||||
},
|
||||
{
|
||||
"path": "github.com/mitchellh/prefixedio",
|
||||
|
|
Loading…
Reference in New Issue