Handle SIGTERM when running commands
Make Consul treat SIGTERM like it does SIGINT when running commands. This is especially important when running Consul as a daemon, since Unix process managers send SIGTERM to restart or terminate a process. This change is untested on Windows. Fixes hashicorp/consul#797
This commit is contained in:
parent
4d4c631fd6
commit
4200a3d04a
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/command"
|
"github.com/hashicorp/consul/command"
|
||||||
"github.com/hashicorp/consul/command/agent"
|
"github.com/hashicorp/consul/command/agent"
|
||||||
|
@ -136,12 +137,12 @@ func init() {
|
||||||
|
|
||||||
// makeShutdownCh returns a channel that can be used for shutdown
|
// makeShutdownCh returns a channel that can be used for shutdown
|
||||||
// notifications for commands. This channel will send a message for every
|
// notifications for commands. This channel will send a message for every
|
||||||
// interrupt received.
|
// interrupt or SIGTERM received.
|
||||||
func makeShutdownCh() <-chan struct{} {
|
func makeShutdownCh() <-chan struct{} {
|
||||||
resultCh := make(chan struct{})
|
resultCh := make(chan struct{})
|
||||||
|
|
||||||
signalCh := make(chan os.Signal, 4)
|
signalCh := make(chan os.Signal, 4)
|
||||||
signal.Notify(signalCh, os.Interrupt)
|
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
<-signalCh
|
<-signalCh
|
||||||
|
|
Loading…
Reference in New Issue