提交 b3ea4995 作者: Matt Bell 提交者: Juan Batiz-Benet

cmd/ipfs2: Handle SIGTERM

上级 cc519c47
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"os/signal"
"runtime/pprof" "runtime/pprof"
logging "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-logging" logging "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-logging"
...@@ -31,6 +32,8 @@ const ( ...@@ -31,6 +32,8 @@ const (
var ofi io.WriteCloser var ofi io.WriteCloser
func main() { func main() {
handleInterrupt()
args := os.Args[1:] args := os.Args[1:]
req, root := createRequest(args) req, root := createRequest(args)
handleOptions(req, root) handleOptions(req, root)
...@@ -299,6 +302,19 @@ func writeHeapProfileToFile() error { ...@@ -299,6 +302,19 @@ func writeHeapProfileToFile() error {
return pprof.WriteHeapProfile(mprof) return pprof.WriteHeapProfile(mprof)
} }
// listen for and handle SIGTERM
func handleInterrupt() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for _ = range c {
log.Info("Received interrupt signal, terminating...")
exit(0)
}
}()
}
func exit(code int) { func exit(code int) {
if u.Debug { if u.Debug {
pprof.StopCPUProfile() pprof.StopCPUProfile()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论