12
12
13
13
from launcher .table import ServiceTable
14
14
from launcher .utils import yes_or_no , normalize_path
15
- from launcher .errors import NoWaiting
15
+ from launcher .errors import NoWaiting , FatalError
16
16
from .base import Node , CliBackend , CliError
17
17
from .lnd import CFHeaderState
18
18
@@ -484,6 +484,25 @@ def _wait_tls_cert(self, stop: threading.Event):
484
484
break
485
485
stop .wait (1 )
486
486
487
+ def _wait_xud_ready (self , stop : threading .Event ):
488
+ # Error: ENOENT: no such file or directory, open '/root/.xud/tls.cert'
489
+ # xud is starting... try again in a few seconds
490
+ # xud is locked, run 'xucli unlock', 'xucli create', or 'xucli restore' then try again
491
+ cmd = self ._cli + " getinfo -j"
492
+ while not stop .is_set ():
493
+ try :
494
+ if not self .is_running :
495
+ raise FatalError ("XUD container \" %s\" stopped unexpectedly" % self .container_name )
496
+ exit_code , output = self .exec (cmd )
497
+ if exit_code == 0 :
498
+ break
499
+ if "xud is locked" in output :
500
+ break
501
+ logger .debug ("[Execute] %s (exit_code=%s)\n %s" , cmd , exit_code , output .rstrip ())
502
+ except docker .errors .APIError :
503
+ logger .exception ("Failed to getinfo" )
504
+ stop .wait (1 )
505
+
487
506
def ensure_ready (self , stop : threading .Event ):
488
507
logger .info ("Ensuring XUD is ready" )
489
508
@@ -496,33 +515,30 @@ def ensure_ready(self, stop: threading.Event):
496
515
497
516
logger .info ("Waiting for XUD to be ready" )
498
517
executor = self .config .executor
499
- f = executor .submit (self ._wait_tls_cert , stop )
500
518
519
+ f = executor .submit (self ._wait_tls_cert , stop )
501
520
while not stop .is_set ():
502
521
logger .info ("Waiting for XUD tls.cert to be created" )
503
522
try :
504
523
f .result (30 )
524
+ break
505
525
except TimeoutError :
506
- print ("XUD should not take so much time to create \" tls.cert\" file. please check container \" %s\" logs for more details." % self .container_name )
526
+ print ("XUD should not take so long to create \" tls.cert\" file. please check container \" %s\" logs for more details." % self .container_name )
507
527
reply = yes_or_no ("Would you like to keep waiting?" )
508
528
if reply == "no" :
509
529
raise NoWaiting
510
530
511
- # Error: ENOENT: no such file or directory, open '/root/.xud/tls.cert'
512
- # xud is starting... try again in a few seconds
513
- # xud is locked, run 'xucli unlock', 'xucli create', or 'xucli restore' then try again
514
- cmd = self ._cli + " getinfo -j"
531
+ f = executor .submit (self ._wait_xud_ready , stop )
515
532
while not stop .is_set ():
533
+ logger .info ("Waiting for XUD to be ready" )
516
534
try :
517
- exit_code , output = self .exec (cmd )
518
- if exit_code == 0 :
519
- break
520
- if "xud is locked" in output :
521
- break
522
- logger .debug ("[Execute] %s (exit_code=%s)\n %s" , cmd , exit_code , output .rstrip ())
523
- except docker .errors .APIError :
524
- logger .exception ("Failed to getinfo" )
525
- stop .wait (1 )
535
+ f .result (10 )
536
+ break
537
+ except TimeoutError :
538
+ print ("XUD should not take so long to be ready. please check container \" %s\" logs for more details." % self .container_name )
539
+ reply = yes_or_no ("Would you like to keep waiting?" )
540
+ if reply == "no" :
541
+ raise NoWaiting
526
542
527
543
if not self .has_wallets ():
528
544
logger .info ("Setting up XUD wallets" )
0 commit comments