mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 23:02:16 +00:00
node: Respond always to OS interrupts (#2479)
* stop node upon receiving SIGTERM or CTRL-Ceven during genesis sleep by setting up interrupt before starting a node Closes #2434 * call Start, not OnStart when starting a component to avoid: ``` E[09-24|10:13:15.805] Not stopping PubSub -- have not been started yet module=pubsub impl=PubSub ``` being printed on exit
This commit is contained in:
parent
d297f02227
commit
d12e55c494
@ -9,9 +9,11 @@ BREAKING CHANGES:
|
|||||||
* Apps
|
* Apps
|
||||||
|
|
||||||
* Go API
|
* Go API
|
||||||
|
- [node] Remove node.RunForever
|
||||||
|
|
||||||
FEATURES:
|
FEATURES:
|
||||||
|
|
||||||
IMPROVEMENTS:
|
IMPROVEMENTS:
|
||||||
|
|
||||||
BUG FIXES:
|
BUG FIXES:
|
||||||
|
- [node] \#2434 Make node respond to signal interrupts while sleeping for genesis time
|
||||||
|
@ -2,6 +2,9 @@ package commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
@ -49,19 +52,31 @@ func NewRunNodeCmd(nodeProvider nm.NodeProvider) *cobra.Command {
|
|||||||
Use: "node",
|
Use: "node",
|
||||||
Short: "Run the tendermint node",
|
Short: "Run the tendermint node",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
// Create & start node
|
|
||||||
n, err := nodeProvider(config, logger)
|
n, err := nodeProvider(config, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to create node: %v", err)
|
return fmt.Errorf("Failed to create node: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop upon receiving SIGTERM or CTRL-C
|
||||||
|
c := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
|
go func() {
|
||||||
|
for sig := range c {
|
||||||
|
logger.Error(fmt.Sprintf("captured %v, exiting...", sig))
|
||||||
|
if n.IsRunning() {
|
||||||
|
n.Stop()
|
||||||
|
}
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if err := n.Start(); err != nil {
|
if err := n.Start(); err != nil {
|
||||||
return fmt.Errorf("Failed to start node: %v", err)
|
return fmt.Errorf("Failed to start node: %v", err)
|
||||||
}
|
}
|
||||||
logger.Info("Started node", "nodeInfo", n.Switch().NodeInfo())
|
logger.Info("Started node", "nodeInfo", n.Switch().NodeInfo())
|
||||||
|
|
||||||
// Trap signal, run forever.
|
// Run forever
|
||||||
n.RunForever()
|
select {}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
@ -586,14 +586,6 @@ func (n *Node) OnStop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunForever waits for an interrupt signal and stops the node.
|
|
||||||
func (n *Node) RunForever() {
|
|
||||||
// Sleep forever and then...
|
|
||||||
cmn.TrapSignal(func() {
|
|
||||||
n.Stop()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// ConfigureRPC sets all variables in rpccore so they will serve
|
// ConfigureRPC sets all variables in rpccore so they will serve
|
||||||
// rpc calls from this node
|
// rpc calls from this node
|
||||||
func (n *Node) ConfigureRPC() {
|
func (n *Node) ConfigureRPC() {
|
||||||
|
@ -207,9 +207,13 @@ func (mt *MultiplexTransport) Dial(
|
|||||||
func (mt *MultiplexTransport) Close() error {
|
func (mt *MultiplexTransport) Close() error {
|
||||||
close(mt.closec)
|
close(mt.closec)
|
||||||
|
|
||||||
|
if mt.listener != nil {
|
||||||
return mt.listener.Close()
|
return mt.listener.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Listen implements transportLifecycle.
|
// Listen implements transportLifecycle.
|
||||||
func (mt *MultiplexTransport) Listen(addr NetAddress) error {
|
func (mt *MultiplexTransport) Listen(addr NetAddress) error {
|
||||||
ln, err := net.Listen("tcp", addr.DialString())
|
ln, err := net.Listen("tcp", addr.DialString())
|
||||||
|
@ -45,7 +45,7 @@ func (b *EventBus) SetLogger(l log.Logger) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *EventBus) OnStart() error {
|
func (b *EventBus) OnStart() error {
|
||||||
return b.pubsub.OnStart()
|
return b.pubsub.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *EventBus) OnStop() {
|
func (b *EventBus) OnStop() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user