From 590a151bde53d319a21eb04a7fd5e5aa8a24d1b7 Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Thu, 26 Jan 2017 17:32:45 +0000 Subject: [PATCH] Move signal handling loop to common. --- .gitmodules | 3 +++ common/signals.go | 32 ----------------------------- prog/weaveproxy/main.go | 3 ++- prog/weaver/main.go | 3 ++- vendor/github.com/weaveworks/common | 1 + 5 files changed, 8 insertions(+), 34 deletions(-) delete mode 100644 common/signals.go create mode 160000 vendor/github.com/weaveworks/common diff --git a/.gitmodules b/.gitmodules index 1e3b0441..b3ee97cb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -124,3 +124,6 @@ [submodule "vendor/github.com/estesp/manifest-tool"] path = vendor/github.com/estesp/manifest-tool url = https://github.com/estesp/manifest-tool +[submodule "vendor/github.com/weaveworks/common"] + path = vendor/github.com/weaveworks/common + url = https://github.com/weaveworks/common diff --git a/common/signals.go b/common/signals.go deleted file mode 100644 index 1b99ec8e..00000000 --- a/common/signals.go +++ /dev/null @@ -1,32 +0,0 @@ -package common - -import ( - "os" - "os/signal" - "runtime" - "syscall" -) - -// A subsystem/server/... that can be stopped or queried about the status with a signal -type SignalReceiver interface { - Stop() error -} - -func SignalHandlerLoop(ss ...SignalReceiver) { - sigs := make(chan os.Signal, 1) - signal.Notify(sigs, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM) - buf := make([]byte, 1<<20) - for { - switch <-sigs { - case syscall.SIGINT, syscall.SIGTERM: - Log.Infof("=== received SIGINT/SIGTERM ===\n*** exiting") - for _, subsystem := range ss { - subsystem.Stop() - } - return - case syscall.SIGQUIT: - stacklen := runtime.Stack(buf, true) - Log.Infof("=== received SIGQUIT ===\n*** goroutine dump...\n%s\n*** end", buf[:stacklen]) - } - } -} diff --git a/prog/weaveproxy/main.go b/prog/weaveproxy/main.go index d8e58b21..acce3bad 100644 --- a/prog/weaveproxy/main.go +++ b/prog/weaveproxy/main.go @@ -5,6 +5,7 @@ import ( "os" "strings" + "github.com/weaveworks/common/signals" "github.com/weaveworks/docker/pkg/mflag" "github.com/weaveworks/weave/common" "github.com/weaveworks/weave/common/mflagext" @@ -79,5 +80,5 @@ func main() { p.AttachExistingContainers() go p.Serve(listeners) go p.ListenAndServeStatus("/home/weave/status.sock") - common.SignalHandlerLoop() + signals.SignalHandlerLoop(common.Log) } diff --git a/prog/weaver/main.go b/prog/weaver/main.go index 5c57c7f8..604a09fd 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -13,6 +13,7 @@ import ( "github.com/gorilla/mux" "github.com/pkg/profile" + "github.com/weaveworks/common/signals" "github.com/weaveworks/docker/pkg/mflag" "github.com/weaveworks/mesh" @@ -361,7 +362,7 @@ func main() { go listenAndServeHTTP(statusAddr, statusMux) } - common.SignalHandlerLoop(router) + signals.SignalHandlerLoop(common.Log, router) } func options() map[string]string { diff --git a/vendor/github.com/weaveworks/common b/vendor/github.com/weaveworks/common new file mode 160000 index 00000000..865a52c9 --- /dev/null +++ b/vendor/github.com/weaveworks/common @@ -0,0 +1 @@ +Subproject commit 865a52c9937cab1440aad535397c5f432f7dc1fc