cmd/swarm: handle SIGTERM unix signal for clean exit

This commit is contained in:
zelig 2017-02-07 00:38:38 +06:30
parent 0850f68fd1
commit 8883f36fe3
1 changed files with 10 additions and 0 deletions

View File

@ -21,9 +21,11 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"os/signal"
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
"syscall"
"github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/accounts/keystore"
@ -271,6 +273,14 @@ func bzzd(ctx *cli.Context) error {
stack := utils.MakeNode(ctx, clientIdentifier, gitCommit) stack := utils.MakeNode(ctx, clientIdentifier, gitCommit)
registerBzzService(ctx, stack) registerBzzService(ctx, stack)
utils.StartNode(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) networkId := ctx.GlobalUint64(SwarmNetworkIdFlag.Name)
// Add bootnodes as initial peers. // Add bootnodes as initial peers.
if ctx.GlobalIsSet(utils.BootnodesFlag.Name) { if ctx.GlobalIsSet(utils.BootnodesFlag.Name) {