mirror of
https://github.com/aljazceru/plugins.git
synced 2025-12-20 06:34:20 +01:00
backup: Perform preflight checks before entering the plugin loop
This commit is contained in:
@@ -341,7 +341,33 @@ plugin.add_option(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def kill(message: str):
|
||||||
|
plugin.log(message)
|
||||||
|
time.sleep(1)
|
||||||
|
# Search for lightningd in my ancestor processes:
|
||||||
|
procs = [p for p in psutil.Process(os.getpid()).parents()]
|
||||||
|
for p in procs:
|
||||||
|
if p.name() != 'lightningd':
|
||||||
|
continue
|
||||||
|
plugin.log("Killing process {name} ({pid})".format(
|
||||||
|
name=p.name(),
|
||||||
|
pid=p.pid
|
||||||
|
))
|
||||||
|
p.kill()
|
||||||
|
|
||||||
|
# Sleep forever, just in case the master doesn't die on us...
|
||||||
|
while True:
|
||||||
|
time.sleep(30)
|
||||||
|
|
||||||
|
|
||||||
|
def preflight(plugin: Plugin):
|
||||||
|
"""Perform some preflight checks.
|
||||||
|
"""
|
||||||
|
if not os.path.exists("backup.lock"):
|
||||||
|
kill("Could not find backup.lock in the lightning-dir")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
preflight(plugin)
|
||||||
# Did we perform the version check of backend versus the first write?
|
# Did we perform the version check of backend versus the first write?
|
||||||
plugin.initialized = False
|
plugin.initialized = False
|
||||||
plugin.early_writes = []
|
plugin.early_writes = []
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ def test_start_no_init(nf, directory):
|
|||||||
options=opts, cleandir=False, may_fail=True, start=False
|
options=opts, cleandir=False, may_fail=True, start=False
|
||||||
)
|
)
|
||||||
|
|
||||||
with pytest.raises((RpcError, ConnectionRefusedError, ConnectionResetError)):
|
with pytest.raises(ValueError):
|
||||||
# The way we detect a failure to start is when we attempt to connect
|
# The way we detect a failure to start is when we attempt to connect
|
||||||
# to the RPC.
|
# to the RPC.
|
||||||
l1.start()
|
l1.start()
|
||||||
|
|||||||
Reference in New Issue
Block a user