diff --git a/agent/proxy/daemon.go b/agent/proxy/daemon.go index ca11ecce03..c00b98136c 100644 --- a/agent/proxy/daemon.go +++ b/agent/proxy/daemon.go @@ -8,7 +8,6 @@ import ( "reflect" "strconv" "sync" - "syscall" "time" "github.com/hashicorp/consul/lib/file" @@ -255,9 +254,9 @@ func (p *Daemon) start() (*os.Process, error) { cmd.Args = []string{cmd.Path} } - // Start it in a new sessions (and hence process group) so that killing agent - // (even with Ctrl-C) won't kill proxy. - cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true} + // Perform system-specific setup. In particular, Unix-like systems + // shuld set sid so that killing the agent doesn't kill the daemon. + configureDaemon(&cmd) // Start it p.Logger.Printf("[DEBUG] agent/proxy: starting proxy: %q %#v", cmd.Path, cmd.Args[1:]) diff --git a/agent/proxy/process_unix.go b/agent/proxy/process_unix.go index 9bca07c2b8..665b0d09e5 100644 --- a/agent/proxy/process_unix.go +++ b/agent/proxy/process_unix.go @@ -5,6 +5,7 @@ package proxy import ( "fmt" "os" + "os/exec" "syscall" ) @@ -28,3 +29,10 @@ func findProcess(pid int) (*os.Process, error) { return nil, fmt.Errorf("process %d is dead or running as another user", pid) } + +// configureDaemon is called prior to Start to allow system-specific setup. +func configureDaemon(cmd *exec.Cmd) { + // Start it in a new sessions (and hence process group) so that killing agent + // (even with Ctrl-C) won't kill proxy. + cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true} +} diff --git a/agent/proxy/process_windows.go b/agent/proxy/process_windows.go index 0a00d81ee0..99e2248d50 100644 --- a/agent/proxy/process_windows.go +++ b/agent/proxy/process_windows.go @@ -4,6 +4,7 @@ package proxy import ( "os" + "os/exec" ) func findProcess(pid int) (*os.Process, error) { @@ -12,3 +13,7 @@ func findProcess(pid int) (*os.Process, error) { // non-nil means it seems to be healthy. return os.FindProcess(pid) } + +func configureDaemon(cmd *exec.Cmd) { + // Do nothing +}