aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2017-02-07 02:08:38 +0800
committerzelig <viktor.tron@gmail.com>2017-02-13 23:45:14 +0800
commit8883f36fe38fc9701f707f9cac8ebcb34d418c46 (patch)
tree8af47183d07f664ab821a677401bc11a1b67db89
parent0850f68fd17586370b102aa516739476db4913c2 (diff)
downloaddexon-8883f36fe38fc9701f707f9cac8ebcb34d418c46.tar
dexon-8883f36fe38fc9701f707f9cac8ebcb34d418c46.tar.gz
dexon-8883f36fe38fc9701f707f9cac8ebcb34d418c46.tar.bz2
dexon-8883f36fe38fc9701f707f9cac8ebcb34d418c46.tar.lz
dexon-8883f36fe38fc9701f707f9cac8ebcb34d418c46.tar.xz
dexon-8883f36fe38fc9701f707f9cac8ebcb34d418c46.tar.zst
dexon-8883f36fe38fc9701f707f9cac8ebcb34d418c46.zip
cmd/swarm: handle SIGTERM unix signal for clean exit
-rw-r--r--cmd/swarm/main.go10
1 files changed, 10 insertions, 0 deletions
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) {