forked from cerc-io/plugeth
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
|
return err
|
||||||
}
|
}
|
||||||
defer stack.Close()
|
defer stack.Close()
|
||||||
|
defer pluginsOnShutdown()
|
||||||
stack.RegisterAPIs(pluginGetAPIs(stack, wrapperBackend))
|
stack.RegisterAPIs(pluginGetAPIs(stack, wrapperBackend))
|
||||||
//end PluGeth code injection
|
//end PluGeth code injection
|
||||||
startNode(ctx, stack, backend, false)
|
startNode(ctx, stack, backend, false)
|
||||||
|
@ -84,3 +84,21 @@ func pluginsInitializeNode(stack *node.Node, backend restricted.Backend) {
|
|||||||
}
|
}
|
||||||
InitializeNode(plugins.DefaultPluginLoader, stack, 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