Skip to content

Commit 9b16118

Browse files
authored
Merge pull request ethereum#3649 from ethersphere/swarm-sigterm-fix
cmd/swarm: handle SIGTERM unix signal for clean exit
2 parents 0850f68 + 8883f36 commit 9b16118

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

cmd/swarm/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ import (
2121
"fmt"
2222
"io/ioutil"
2323
"os"
24+
"os/signal"
2425
"runtime"
2526
"strconv"
2627
"strings"
28+
"syscall"
2729

2830
"github.com/ethereum/go-ethereum/accounts"
2931
"github.com/ethereum/go-ethereum/accounts/keystore"
@@ -271,6 +273,14 @@ func bzzd(ctx *cli.Context) error {
271273
stack := utils.MakeNode(ctx, clientIdentifier, gitCommit)
272274
registerBzzService(ctx, stack)
273275
utils.StartNode(stack)
276+
go func() {
277+
sigc := make(chan os.Signal, 1)
278+
signal.Notify(sigc, syscall.SIGTERM)
279+
defer signal.Stop(sigc)
280+
<-sigc
281+
glog.V(logger.Info).Infoln("Got sigterm, shutting down...")
282+
stack.Stop()
283+
}()
274284
networkId := ctx.GlobalUint64(SwarmNetworkIdFlag.Name)
275285
// Add bootnodes as initial peers.
276286
if ctx.GlobalIsSet(utils.BootnodesFlag.Name) {

0 commit comments

Comments
 (0)