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

cmd/ipfs2: Handle SIGTERM

上级 cc519c47
......@@ -4,6 +4,7 @@ import (
"fmt"
"io"
"os"
"os/signal"
"runtime/pprof"
logging "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-logging"
......@@ -31,6 +32,8 @@ const (
var ofi io.WriteCloser
func main() {
handleInterrupt()
args := os.Args[1:]
req, root := createRequest(args)
handleOptions(req, root)
......@@ -299,6 +302,19 @@ func writeHeapProfileToFile() error {
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) {
if u.Debug {
pprof.StopCPUProfile()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论