forked from cerc-io/plugeth
Merge pull request #50 from openrelayxyz/feature/onshutdown
Add OnShutdown hook
This commit is contained in:
commit
1dfed7aed8
@ -362,6 +362,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