Merge pull request #2753 from weaveworks/mv-signal-to-common
Move signal handling loop to common.
This commit is contained in:
commit
8a5a15d5e9
5 files changed
+8
-34
No files matched your search
@@ -124,3 +124,6 @@
|
|||||||
[submodule "vendor/github.com/estesp/manifest-tool"]
|
[submodule "vendor/github.com/estesp/manifest-tool"]
|
||||||
path = vendor/github.com/estesp/manifest-tool
|
path = vendor/github.com/estesp/manifest-tool
|
||||||
url = https://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
|
||||||
@@ -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])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/weaveworks/common/signals"
|
||||||
"github.com/weaveworks/docker/pkg/mflag"
|
"github.com/weaveworks/docker/pkg/mflag"
|
||||||
"github.com/weaveworks/weave/common"
|
"github.com/weaveworks/weave/common"
|
||||||
"github.com/weaveworks/weave/common/mflagext"
|
"github.com/weaveworks/weave/common/mflagext"
|
||||||
@@ -79,5 +80,5 @@ func main() {
|
|||||||
p.AttachExistingContainers()
|
p.AttachExistingContainers()
|
||||||
go p.Serve(listeners)
|
go p.Serve(listeners)
|
||||||
go p.ListenAndServeStatus("/home/weave/status.sock")
|
go p.ListenAndServeStatus("/home/weave/status.sock")
|
||||||
common.SignalHandlerLoop()
|
signals.SignalHandlerLoop(common.Log)
|
||||||
}
|
}
|
||||||
+2
-1
@@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/pkg/profile"
|
"github.com/pkg/profile"
|
||||||
|
"github.com/weaveworks/common/signals"
|
||||||
"github.com/weaveworks/docker/pkg/mflag"
|
"github.com/weaveworks/docker/pkg/mflag"
|
||||||
"github.com/weaveworks/mesh"
|
"github.com/weaveworks/mesh"
|
||||||
|
|
||||||
@@ -361,7 +362,7 @@ func main() {
|
|||||||
go listenAndServeHTTP(statusAddr, statusMux)
|
go listenAndServeHTTP(statusAddr, statusMux)
|
||||||
}
|
}
|
||||||
|
|
||||||
common.SignalHandlerLoop(router)
|
signals.SignalHandlerLoop(common.Log, router)
|
||||||
}
|
}
|
||||||
|
|
||||||
func options() map[string]string {
|
func options() map[string]string {
|
||||||
|
|||||||
+1
Submodule vendor/github.com/weaveworks/common added at 865a52c993.
Reference in new issue
Block a user