diff --git a/doc/developers-guide/plugin-development/event-notifications.md b/doc/developers-guide/plugin-development/event-notifications.md index 7d3aeba994af..5e6836664c4e 100644 --- a/doc/developers-guide/plugin-development/event-notifications.md +++ b/doc/developers-guide/plugin-development/event-notifications.md @@ -483,3 +483,51 @@ In the shutdown case, plugins should not interact with lightnind except via (id- } } ``` + +### `plugin_started` and + +Emitted when a plugin has completed startup. + +```json +{ + "plugin_started": { + "plugin_name": "example_plugin", + "plugin_path": "/path/to/example_plugin.py", + "methods": [ + "example_method1", + "example_method2", + "example_method3" + ] + } +} +``` + +Where: + +- `plugin_name`: The short name of the plugin. +- `plugin_path`: The full file path to the plugin executable. +- `methods`: An array of RPC method names that the plugin registered. + +### `plugin_stopped` + +Emitted when a plugin has been stopped or has exited. + +```json +{ + "plugin_stopped": { + "plugin_name": "example_plugin", + "plugin_path": "/path/to/example_plugin.py", + "methods": [ + "example_method1", + "example_method2", + "example_method3" + ] + } +} +``` + +Where: + +- `plugin_name`: The short name of the plugin. +- `plugin_path`: The full file path to the plugin executable. +- `methods`: An array of RPC method names that the plugin registered. \ No newline at end of file diff --git a/lightningd/notification.c b/lightningd/notification.c index cdaa24c9ab59..bc4c499bf656 100644 --- a/lightningd/notification.c +++ b/lightningd/notification.c @@ -638,3 +638,33 @@ void notify_log(struct lightningd *ld, const struct log_entry *l) log_notification_serialize(n->stream, l); notify_send(ld, n); } + +static void plugin_notification_serialize(struct json_stream *stream, + struct plugin *plugin) +{ + json_add_string(stream, "plugin_name", plugin->shortname); + json_add_string(stream, "plugin_path", plugin->cmd); + json_array_start(stream, "methods"); + for (size_t i = 0; i < tal_count(plugin->methods); i++) { + json_add_string(stream, NULL, plugin->methods[i]); + } + json_array_end(stream); +} + +REGISTER_NOTIFICATION(plugin_started); + +void notify_plugin_started(struct lightningd *ld, struct plugin *plugin) +{ + struct jsonrpc_notification *n = notify_start("plugin_started"); + plugin_notification_serialize(n->stream, plugin); + notify_send(ld, n); +} + +REGISTER_NOTIFICATION(plugin_stopped); + +void notify_plugin_stopped(struct lightningd *ld, struct plugin *plugin) +{ + struct jsonrpc_notification *n = notify_start("plugin_stopped"); + plugin_notification_serialize(n->stream, plugin); + notify_send(ld, n); +} diff --git a/lightningd/notification.h b/lightningd/notification.h index 1c676f7eb0d6..8bf93447614c 100644 --- a/lightningd/notification.h +++ b/lightningd/notification.h @@ -109,4 +109,7 @@ bool notify_deprecated_oneshot(struct lightningd *ld, bool notify_plugin_shutdown(struct lightningd *ld, struct plugin *p); /* Inform the plugin when a log line is emitted */ void notify_log(struct lightningd *ld, const struct log_entry *l); + +void notify_plugin_started(struct lightningd *ld, struct plugin *plugin); +void notify_plugin_stopped(struct lightningd *ld, struct plugin *plugin); #endif /* LIGHTNING_LIGHTNINGD_NOTIFICATION_H */ diff --git a/lightningd/plugin.c b/lightningd/plugin.c index 68d500c8f27e..9f05dc64446d 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -305,6 +305,8 @@ static void destroy_plugin(struct plugin *p) if (tal_count(p->custom_msgs)) tell_connectd_custommsgs(p->plugins); + + notify_plugin_stopped(p->plugins->ld, p); } static u32 file_checksum(struct lightningd *ld, const char *path) @@ -2140,6 +2142,7 @@ static void plugin_config_cb(const char *buffer, } if (tal_count(plugin->custom_msgs)) tell_connectd_custommsgs(plugin->plugins); + notify_plugin_started(plugin->plugins->ld, plugin); check_plugins_initted(plugin->plugins); }