Commit b3ea4995 authored by Matt Bell's avatar Matt Bell Committed by Juan Batiz-Benet

cmd/ipfs2: Handle SIGTERM

parent 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 is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment