Add OnShutdown hook
This will allow plugins to clean up resources that need to be properly shutdown before Geth terminates.
This commit is contained in:
parent
66a0d514c4
commit
b45c9e8e03
@ -357,6 +357,7 @@ func geth(ctx *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
defer stack.Close()
|
||||
defer pluginsOnShutdown()
|
||||
stack.RegisterAPIs(pluginGetAPIs(stack, wrapperBackend))
|
||||
//end PluGeth code injection
|
||||
startNode(ctx, stack, backend, false)
|
||||
|
@ -84,3 +84,21 @@ func pluginsInitializeNode(stack *node.Node, backend restricted.Backend) {
|
||||
}
|
||||
InitializeNode(plugins.DefaultPluginLoader, stack, backend)
|
||||
}
|
||||
|
||||
func OnShutdown(pl *plugins.PluginLoader) {
|
||||
fnList := pl.Lookup("OnShutdown", func(item interface{}) bool {
|
||||
_, ok := item.(func())
|
||||
return ok
|
||||
})
|
||||
for _, fni := range fnList {
|
||||
fni.(func())()
|
||||
}
|
||||
}
|
||||
|
||||
func pluginsOnShutdown() {
|
||||
if plugins.DefaultPluginLoader == nil {
|
||||
log.Warn("Attempting OnShutdown, but default PluginLoader has not been initialized")
|
||||
return
|
||||
}
|
||||
OnShutdown(plugins.DefaultPluginLoader)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user