Skip to content

Commit

Permalink
exit with zero (0) code upon receiving SIGTERM/SIGINT
Browse files Browse the repository at this point in the history
Refs #3238
  • Loading branch information
melekes committed Feb 14, 2019
1 parent ea978d3 commit ac442f9
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Special thanks to external contributors on this release:
### FEATURES:

### IMPROVEMENTS:
- [libs/common] \#3238 exit with zero (0) code upon receiving SIGTERM/SIGINT

### BUG FIXES:
- [consensus] \#3297 Flush WAL on stop to prevent data corruption during
Expand Down
10 changes: 6 additions & 4 deletions abci/cmd/abci-cli/abci-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,7 @@ func cmdQuery(cmd *cobra.Command, args []string) error {
}

func cmdCounter(cmd *cobra.Command, args []string) error {

app := counter.NewCounterApplication(flagSerial)

logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))

// Start the listener
Expand All @@ -651,11 +649,15 @@ func cmdCounter(cmd *cobra.Command, args []string) error {
return err
}

// Wait forever
cmn.TrapSignal(func() {
// Stop upon receiving SIGTERM or CTRL-C.
cmn.TrapSignal(logger, func() {
// Cleanup
srv.Stop()
})

// Run forever.
select {}

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion libs/common/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TrapSignal(logger logger, cb func()) {
if cb != nil {
cb()
}
os.Exit(1)
os.Exit(0)
}
}()
}
Expand Down
4 changes: 2 additions & 2 deletions libs/common/os_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
)

func TestGoPath(t *testing.T) {
func TestOSGoPath(t *testing.T) {
// restore original gopath upon exit
path := os.Getenv("GOPATH")
defer func() {
Expand All @@ -28,7 +28,7 @@ func TestGoPath(t *testing.T) {
}
}

func TestGoPathWithoutEnvVar(t *testing.T) {
func TestOSGoPathWithoutEnvVar(t *testing.T) {
// restore original gopath upon exit
path := os.Getenv("GOPATH")
defer func() {
Expand Down
6 changes: 3 additions & 3 deletions rpc/lib/test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ type Result struct {
}

func main() {
// Stop upon receiving SIGTERM or CTRL-C.
cmn.TrapSignal(logger, func() {})

var (
mux = http.NewServeMux()
cdc = amino.NewCodec()
logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout))
)

// Stop upon receiving SIGTERM or CTRL-C.
cmn.TrapSignal(logger, func() {})

rpcserver.RegisterRPCFuncs(mux, routes, cdc, logger)
listener, err := rpcserver.Listen("0.0.0.0:8008", rpcserver.Config{})
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions tools/tm-bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import (
"flag"
"fmt"
"os"
"os/signal"
"strings"
"sync"
"syscall"
"time"

"github.com/go-kit/kit/log/term"

cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/log"
tmrpc "github.com/tendermint/tendermint/rpc/client"
)
Expand Down

0 comments on commit ac442f9

Please sign in to comment.