Skip to content

Commit

Permalink
Handle SIGTERM when running commands
Browse files Browse the repository at this point in the history
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 #797
  • Loading branch information
mfischer-zd committed Mar 30, 2015
1 parent efb374e commit 1d5c0a2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"os"
"os/signal"
"syscall"

"github.com/hashicorp/consul/command"
"github.com/hashicorp/consul/command/agent"
Expand Down Expand Up @@ -136,12 +137,12 @@ func init() {

// makeShutdownCh returns a channel that can be used for shutdown
// notifications for commands. This channel will send a message for every
// interrupt received.
// interrupt or SIGTERM received.
func makeShutdownCh() <-chan struct{} {
resultCh := make(chan struct{})

signalCh := make(chan os.Signal, 4)
signal.Notify(signalCh, os.Interrupt)
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)
go func() {
for {
<-signalCh
Expand Down

0 comments on commit 1d5c0a2

Please sign in to comment.