@@ -169,6 +169,17 @@ impl CoffeeManager {
169
169
Ok ( ( ) )
170
170
}
171
171
172
+ pub async fn stop_plugin ( & self , path : & str ) -> Result < ( ) , CoffeeError > {
173
+ let mut payload = json_utils:: init_payload ( ) ;
174
+ json_utils:: add_str ( & mut payload, "subcommand" , "stop" ) ;
175
+ json_utils:: add_str ( & mut payload, "plugin" , path) ;
176
+ let response = self
177
+ . cln :: < serde_json:: Value , serde_json:: Value > ( "plugin" , payload)
178
+ . await ?;
179
+ log:: debug!( "plugin stopped: {response}" ) ;
180
+ Ok ( ( ) )
181
+ }
182
+
172
183
pub fn storage_info ( & self ) -> CoffeeStorageInfo {
173
184
CoffeeStorageInfo :: from ( self )
174
185
}
@@ -300,6 +311,8 @@ impl PluginManager for CoffeeManager {
300
311
self . flush ( ) . await ?;
301
312
self . update_conf ( ) . await ?;
302
313
} else {
314
+ self . config . plugins . push ( plugin) ;
315
+ self . flush ( ) . await ?;
303
316
self . start_plugin ( & path) . await ?;
304
317
}
305
318
return Ok ( ( ) ) ;
@@ -328,9 +341,19 @@ impl PluginManager for CoffeeManager {
328
341
log:: debug!( "runnable plugin path: {exec_path}" ) ;
329
342
plugins. remove ( index) ;
330
343
log:: debug!( "coffee cln config: {}" , self . coffee_cln_config) ;
331
- self . coffee_cln_config
332
- . rm_conf ( "plugin" , Some ( & exec_path. to_owned ( ) ) )
333
- . map_err ( |err| error ! ( "{}" , & err. cause) ) ?;
344
+ let remove_config = self
345
+ . coffee_cln_config
346
+ . rm_conf ( "plugin" , Some ( & exec_path. to_owned ( ) ) ) ;
347
+ if let Err ( err) = remove_config {
348
+ // if this is true, we are probably a dynamic plugin:
349
+ if err. cause . contains ( "field with `plugin` not present" ) {
350
+ if let Err ( e) = self . stop_plugin ( & exec_path) . await {
351
+ log:: warn!( "{}" , e) ;
352
+ } ;
353
+ } else {
354
+ return Err ( error ! ( "{}" , & err. cause) ) ;
355
+ }
356
+ }
334
357
self . flush ( ) . await ?;
335
358
self . update_conf ( ) . await ?;
336
359
Ok ( CoffeeRemove { plugin } )
0 commit comments