Skip to content

Commit b154de5

Browse files
gudnufrustyrussell
authored andcommitted
new notifications: plugin_stopped and plugin_started
[Added version tag into documentation, to show it was added in 25.02 --RR] Changelog-Added: Plugins: new nofitications `plugin_stopped` and `plugin_started`
1 parent 1820423 commit b154de5

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

doc/developers-guide/plugin-development/event-notifications.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,3 +519,51 @@ In the shutdown case, plugins should not interact with lightnind except via (id-
519519
}
520520
}
521521
```
522+
523+
### `plugin_started` (v25.02 onward)
524+
525+
Emitted when a plugin has completed startup.
526+
527+
```json
528+
{
529+
"plugin_started": {
530+
"plugin_name": "example_plugin",
531+
"plugin_path": "/path/to/example_plugin.py",
532+
"methods": [
533+
"example_method1",
534+
"example_method2",
535+
"example_method3"
536+
]
537+
}
538+
}
539+
```
540+
541+
Where:
542+
543+
- `plugin_name`: The short name of the plugin.
544+
- `plugin_path`: The full file path to the plugin executable.
545+
- `methods`: An array of RPC method names that the plugin registered.
546+
547+
### `plugin_stopped` (v25.02 onward)
548+
549+
Emitted when a plugin has been stopped or has exited.
550+
551+
```json
552+
{
553+
"plugin_stopped": {
554+
"plugin_name": "example_plugin",
555+
"plugin_path": "/path/to/example_plugin.py",
556+
"methods": [
557+
"example_method1",
558+
"example_method2",
559+
"example_method3"
560+
]
561+
}
562+
}
563+
```
564+
565+
Where:
566+
567+
- `plugin_name`: The short name of the plugin.
568+
- `plugin_path`: The full file path to the plugin executable.
569+
- `methods`: An array of RPC method names that the plugin registered.

lightningd/notification.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,3 +677,45 @@ void notify_log(struct lightningd *ld, const struct log_entry *l)
677677
log_notification_serialize(n->stream, l);
678678
notify_send(ld, n);
679679
}
680+
681+
static void plugin_started_notification_serialize(struct json_stream *stream,
682+
struct plugin *plugin)
683+
{
684+
json_add_string(stream, "plugin_name", plugin->shortname);
685+
json_add_string(stream, "plugin_path", plugin->cmd);
686+
json_array_start(stream, "methods");
687+
for (size_t i = 0; i < tal_count(plugin->methods); i++) {
688+
json_add_string(stream, NULL, plugin->methods[i]);
689+
}
690+
json_array_end(stream);
691+
}
692+
693+
REGISTER_NOTIFICATION(plugin_started);
694+
695+
void notify_plugin_started(struct lightningd *ld, struct plugin *plugin)
696+
{
697+
struct jsonrpc_notification *n = notify_start("plugin_started");
698+
plugin_started_notification_serialize(n->stream, plugin);
699+
notify_send(ld, n);
700+
}
701+
702+
static void plugin_stopped_notification_serialize(struct json_stream *stream,
703+
struct plugin *plugin)
704+
{
705+
json_add_string(stream, "plugin_name", plugin->shortname);
706+
json_add_string(stream, "plugin_path", plugin->cmd);
707+
json_array_start(stream, "methods");
708+
for (size_t i = 0; i < tal_count(plugin->methods); i++) {
709+
json_add_string(stream, NULL, plugin->methods[i]);
710+
}
711+
json_array_end(stream);
712+
}
713+
714+
REGISTER_NOTIFICATION(plugin_stopped);
715+
716+
void notify_plugin_stopped(struct lightningd *ld, struct plugin *plugin)
717+
{
718+
struct jsonrpc_notification *n = notify_start("plugin_stopped");
719+
plugin_stopped_notification_serialize(n->stream, plugin);
720+
notify_send(ld, n);
721+
}

lightningd/notification.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,7 @@ bool notify_deprecated_oneshot(struct lightningd *ld,
116116
bool notify_plugin_shutdown(struct lightningd *ld, struct plugin *p);
117117
/* Inform the plugin when a log line is emitted */
118118
void notify_log(struct lightningd *ld, const struct log_entry *l);
119+
120+
void notify_plugin_started(struct lightningd *ld, struct plugin *plugin);
121+
void notify_plugin_stopped(struct lightningd *ld, struct plugin *plugin);
119122
#endif /* LIGHTNING_LIGHTNINGD_NOTIFICATION_H */

lightningd/plugin.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ static void destroy_plugin(struct plugin *p)
301301

302302
if (tal_count(p->custom_msgs))
303303
tell_connectd_custommsgs(p->plugins);
304+
305+
notify_plugin_stopped(p->plugins->ld, p);
304306
}
305307

306308
static u32 file_checksum(struct lightningd *ld, const char *path)
@@ -2136,6 +2138,7 @@ static void plugin_config_cb(const char *buffer,
21362138
}
21372139
if (tal_count(plugin->custom_msgs))
21382140
tell_connectd_custommsgs(plugin->plugins);
2141+
notify_plugin_started(plugin->plugins->ld, plugin);
21392142
check_plugins_initted(plugin->plugins);
21402143
}
21412144

0 commit comments

Comments
 (0)