From 8883f36fe38fc9701f707f9cac8ebcb34d418c46 Mon Sep 17 00:00:00 2001 From: zelig Date: Tue, 7 Feb 2017 00:38:38 +0630 Subject: [PATCH] cmd/swarm: handle SIGTERM unix signal for clean exit --- cmd/swarm/main.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/swarm/main.go b/cmd/swarm/main.go index 14adc3b10..5661b3f6e 100644 --- a/cmd/swarm/main.go +++ b/cmd/swarm/main.go @@ -21,9 +21,11 @@ import ( "fmt" "io/ioutil" "os" + "os/signal" "runtime" "strconv" "strings" + "syscall" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts/keystore" @@ -271,6 +273,14 @@ func bzzd(ctx *cli.Context) error { stack := utils.MakeNode(ctx, clientIdentifier, gitCommit) registerBzzService(ctx, stack) utils.StartNode(stack) + go func() { + sigc := make(chan os.Signal, 1) + signal.Notify(sigc, syscall.SIGTERM) + defer signal.Stop(sigc) + <-sigc + glog.V(logger.Info).Infoln("Got sigterm, shutting down...") + stack.Stop() + }() networkId := ctx.GlobalUint64(SwarmNetworkIdFlag.Name) // Add bootnodes as initial peers. if ctx.GlobalIsSet(utils.BootnodesFlag.Name) {