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
|
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