| 29 | |
| 30 | @plugin.subscribe("shutdown") |
| 31 | def shutdown(plugin, **kwargs): |
| 32 | |
| 33 | # 'shutdown' notification can be called in two ways, from `plugin stop` or from |
| 34 | # lightningd's shutdown loop, we test which one by making `getinfo` call |
| 35 | try: |
| 36 | plugin.rpc.getinfo() |
| 37 | plugin.rpc.datastore(key='test', string='Allowed', mode="create-or-append") |
| 38 | plugin.log("via plugin stop, datastore success") |
| 39 | except RpcError as e: |
| 40 | if e.error == {'code': -5, 'message': 'lightningd is shutting down'}: |
| 41 | # JSON RPC is disabled by now, but can do logging |
| 42 | with pytest.raises(RpcError, match=r'-5.*lightningd is shutting down'): |
| 43 | plugin.rpc.datastore(key='test', string='Not allowed', mode="create-or-append") |
| 44 | plugin.log("via lightningd shutdown, datastore failed") |
| 45 | else: |
| 46 | raise |
| 47 | |
| 48 | sys.exit(0) |
| 49 | |
| 50 | |
| 51 | plugin.run() |