server: run cleanupFunc before Exit (#4324)
Ensure gaiad shutdown Tendermint gracefully upon receiving SIGINT and SIGTERM. Closes: #4323
This commit is contained in:
parent
829ce17d06
commit
77c04202a2
|
@ -216,14 +216,17 @@ func TrapSignal(cleanupFunc func()) {
|
|||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
||||
go func() {
|
||||
sig := <-sigs
|
||||
switch sig {
|
||||
case syscall.SIGTERM:
|
||||
defer cleanupFunc()
|
||||
os.Exit(128 + int(syscall.SIGTERM))
|
||||
case syscall.SIGINT:
|
||||
defer cleanupFunc()
|
||||
os.Exit(128 + int(syscall.SIGINT))
|
||||
if cleanupFunc != nil {
|
||||
cleanupFunc()
|
||||
}
|
||||
exitCode := 128
|
||||
switch sig {
|
||||
case syscall.SIGINT:
|
||||
exitCode += int(syscall.SIGINT)
|
||||
case syscall.SIGTERM:
|
||||
exitCode += int(syscall.SIGTERM)
|
||||
}
|
||||
os.Exit(exitCode)
|
||||
}()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue