def on_init(options: Mapping[str, str], plugin: Plugin, **kwargs): # Reach into the DB and configs = plugin.rpc.listconfigs() plugin.db_path = configs['wallet'] destination = options['backup-destination'] # Ensure that we don't inadventently switch the destination if not os.path.exists("backup.lock"): print("Files in the current directory {}".format(", ".join( os.listdir(".")))) return abort( "Could not find backup.lock in the lightning-dir, have you initialized using the backup-cli utility?" ) d = json.load(open("backup.lock", 'r')) if destination is None or destination == 'null': destination = d['backend_url'] elif destination != d['backend_url']: abort("The destination specified as option does not match the one " "specified in backup.lock. Please check your settings") if not plugin.db_path.startswith('sqlite3'): abort("The backup plugin only works with the sqlite3 database.") plugin.backend = get_backend(destination, require_init=True) for c in plugin.early_writes: apply_write(plugin, c)
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) plugin.add_option( 'backup-destination', None, 'UNUSED. Kept for backward compatibility only. Please update your configuration to remove this option.' ) if __name__ == "__main__": # Did we perform the first write check? plugin.initialized = False if not os.path.exists("backup.lock"): kill("Could not find backup.lock in the lightning-dir") d = json.load(open("backup.lock", 'r')) destination = d['backend_url'] plugin.backend = get_backend(destination, require_init=True) plugin.run()