diff --git a/cmd/geth/main.go b/cmd/geth/main.go index d198f5e4b..e4b82f26c 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -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) diff --git a/cmd/geth/plugin_hooks.go b/cmd/geth/plugin_hooks.go index 0c0038f96..80187a028 100644 --- a/cmd/geth/plugin_hooks.go +++ b/cmd/geth/plugin_hooks.go @@ -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) +}