Unclean shutdown on SIGINT / SIGTERM (#3308)

* libs/common: TrapSignal accepts logger as a first parameter

 and does not block anymore
* previously it was dumping "captured ..." msg to os.Stdout
* TrapSignal should not be responsible for blocking thread of execution

Refs #3238

* exit with zero (0) code upon receiving SIGTERM/SIGINT

Refs #3238

* fix formatting in docs/app-dev/abci-cli.md

Co-Authored-By: melekes <anton.kalyaev@gmail.com>

* fix formatting in docs/app-dev/abci-cli.md

Co-Authored-By: melekes <anton.kalyaev@gmail.com>
This commit is contained in:
Anton Kaliaev
2019-02-23 19:48:28 +04:00
committed by Ethan Buchman
parent 41f91318e9
commit cdf3a74f48
12 changed files with 103 additions and 86 deletions

View File

@ -24,17 +24,19 @@ type Result struct {
}
func main() {
mux := http.NewServeMux()
cdc := amino.NewCodec()
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
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 {
cmn.Exit(err.Error())
}
go rpcserver.StartHTTPServer(listener, mux, logger)
// Wait forever
cmn.TrapSignal(func() {
})
rpcserver.StartHTTPServer(listener, mux, logger)
}