mirror of
https://github.com/fluencelabs/tendermint
synced 2025-07-30 19:51:58 +00:00
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:
committed by
Ethan Buchman
parent
41f91318e9
commit
cdf3a74f48
@@ -34,21 +34,24 @@ func GoPath() string {
|
||||
return path
|
||||
}
|
||||
|
||||
// TrapSignal catches the SIGTERM and executes cb function. After that it exits
|
||||
// with code 1.
|
||||
func TrapSignal(cb func()) {
|
||||
type logger interface {
|
||||
Info(msg string, keyvals ...interface{})
|
||||
}
|
||||
|
||||
// TrapSignal catches the SIGTERM/SIGINT and executes cb function. After that it exits
|
||||
// with code 0.
|
||||
func TrapSignal(logger logger, cb func()) {
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
go func() {
|
||||
for sig := range c {
|
||||
fmt.Printf("captured %v, exiting...\n", sig)
|
||||
logger.Info(fmt.Sprintf("captured %v, exiting...", sig))
|
||||
if cb != nil {
|
||||
cb()
|
||||
}
|
||||
os.Exit(1)
|
||||
os.Exit(0)
|
||||
}
|
||||
}()
|
||||
select {}
|
||||
}
|
||||
|
||||
// Kill the running process by sending itself SIGTERM.
|
||||
|
Reference in New Issue
Block a user