Skip to content

Commit

Permalink
feat: add --xud.debug option
Browse files Browse the repository at this point in the history
This option will run xud with NodeJS --inspect option on 0.0.0.0:9229
by default. But you could use --xud.debug=<any port> to customize it.
  • Loading branch information
reliveyy committed Sep 22, 2020
1 parent 178b477 commit 5b80583
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 39 deletions.
15 changes: 7 additions & 8 deletions images/utils/launcher/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import shlex
import traceback
import os

from .config import Config, ConfigLoader
from .shell import Shell
Expand Down Expand Up @@ -266,17 +265,17 @@ def launch(self):
print()
except ConfigError as e:
if e.scope == ConfigErrorScope.COMMAND_LINE_ARGS:
print("Failed to parse command-line arguments, exiting.")
print(f"Error details: {e.__cause__}")
print("Failed to parse command-line arguments, exiting.")
traceback.print_exc()
elif e.scope == ConfigErrorScope.GENERAL_CONF:
print("Failed to parse config file {}, exiting.".format(e.conf_file))
print(f"Error details: {e.__cause__}")
print("Failed to parse config file {}, exiting.".format(e.conf_file))
traceback.print_exc()
elif e.scope == ConfigErrorScope.NETWORK_CONF:
print("Failed to parse config file {}, exiting.".format(e.conf_file))
print(f"Error details: {e.__cause__}")
print("Failed to parse config file {}, exiting.".format(e.conf_file))
traceback.print_exc()
except FatalError as e:
if config and config.logfile:
print(f"Error: {e}. For more details, see {config.logfile}")
print(f"Error: {e}. For more details, see {config.logfile}")
else:
traceback.print_exc()
except Exception: # exclude system exceptions like SystemExit
Expand Down
30 changes: 30 additions & 0 deletions images/utils/launcher/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ def parse_command_line_arguments(self):
action="store_true",
help="Preserve xud xud.conf file during updates"
)
group.add_argument(
"--xud.debug",
nargs='?',
metavar="<port>",
help="Run xud with NodeJS --inspect option on specific port (default: 9229)"
)

group = parser.add_argument_group("arby")
group.add_argument(
Expand Down Expand Up @@ -425,6 +431,29 @@ def update_ports(self, node, parsed, mapping=None):
if p not in node["ports"]:
node["ports"].append(p)

def update_debug(self, node, parsed):
node_name = node["name"]

def process(value):
if not value:
if node_name == "xud":
value = 9229
else:
raise RuntimeError("No default debug port for node %s" % node_name)
if isinstance(value, str):
value = int(value)
assert isinstance(value, int)
node["debug"] = value
p = PortPublish("%s" % value)
if p not in node["ports"]:
node["ports"].append(p)

if "debug" in parsed:
process(parsed["debug"])
opt = "{}.debug".format(node_name)
if hasattr(self.args, opt):
process(getattr(self.args, opt))

def update_bitcoind_kind(self, node, parsed):
if "external" in parsed:
print("Warning: Using deprecated option \"external\". Please use \"mode\" instead.")
Expand Down Expand Up @@ -655,6 +684,7 @@ def update_xud(self, parsed):
"""
node = self.nodes["xud"]
self.update_ports(node, parsed)
self.update_debug(node, parsed)

def update_disabled(self, node, parsed, opt):
if "disabled" in parsed:
Expand Down
1 change: 1 addition & 0 deletions images/utils/launcher/config/mainnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
# 8886 - gRPC port
# 8080 - webproxy port
#expose-ports = ["8885", "8886", "8080"]
#debug = 9229

[arby]
#live-cex="false"
Expand Down
1 change: 1 addition & 0 deletions images/utils/launcher/config/simnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
# 28886 - gRPC port
# 28080 - webproxy port
#expose-ports = ["28885", "28886", "28080:8080"]
#debug = 9229

[arby]
#live-cex="false"
Expand Down
1 change: 1 addition & 0 deletions images/utils/launcher/config/testnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
# 18886 - gRPC port
# 18080 - webproxy port
#expose-ports = ["18885", "18886", "18080:8080"]
#debug = 9229

[arby]
#live-cex="false"
Expand Down
4 changes: 4 additions & 0 deletions images/utils/launcher/node/xud.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def __init__(self, name, ctx):

self.container_spec.environment.append("NODE_ENV=production")

if "debug" in self.node_config:
debug_port = self.node_config["debug"]
self.container_spec.environment.append(f"DEBUG_PORT={debug_port}")

self._cli = "xucli"

self.api = XudApi(CliBackend(self.client, self.container_name, self._logger, self._cli))
Expand Down
8 changes: 7 additions & 1 deletion images/xud/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,10 @@ cat $XUD_CONF
/xud-backup.sh &

# use exec to properly respond to SIGINT
exec xud $@
if [[ -n ${DEBUG_PORT:-} ]]; then
export NODE_ENV=development
exec node --inspect-brk=0.0.0.0:$DEBUG_PORT bin/xud
else
exec xud $@
fi

1 change: 1 addition & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Connext options:
Xud options:
--xud.expose-ports <port>[,<port>] Expose xud service ports to your host machine
--xud.preserve-config Preserve xud xud.conf file during updates
--xud.debug [<port>] Run xud with NodeJS --inspect option on specific port (default: 9229)
Arby options:
--arby.live-cex [true|false] Production/Demo mode (default: false)
Expand Down
68 changes: 38 additions & 30 deletions tools/core/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,36 +140,44 @@ def repo(self) -> Optional[str]:
def _run_command(self, cmd):
self._logger.info(cmd)

stop = threading.Event()

def f():
nonlocal stop
counter = 0
on_travis = "TRAVIS_BRANCH" in os.environ
while not stop.is_set():
counter = counter + 1

if on_travis:
print("Still building... ({})".format(counter), flush=True)
stop.wait(10)
continue

print(".", end="", flush=True)
stop.wait(1)
if not on_travis:
print()
threading.Thread(target=f).start()
try:
output = execute(cmd)
self._logger.debug("$ %s\n%s", cmd, output)
stop.set()
except CalledProcessError as e:
stop.set()
print(e.output.decode(), end="", flush=True)
raise SystemExit(1)
except:
stop.set()
raise
on_travis = "TRAVIS_BRANCH" in os.environ

if on_travis:
stop = threading.Event()

def f():
nonlocal stop
counter = 0

while not stop.is_set():
counter = counter + 1

if on_travis:
print("Still building... ({})".format(counter), flush=True)
stop.wait(10)
continue

print(".", end="", flush=True)
stop.wait(1)
if not on_travis:
print()
threading.Thread(target=f).start()
try:
output = execute(cmd)
self._logger.debug("$ %s\n%s", cmd, output)
stop.set()
except CalledProcessError as e:
stop.set()
print(e.output.decode(), end="", flush=True)
raise SystemExit(1)
except:
stop.set()
raise
else:
print("\033[1m$ %s\033[0m" % cmd)
exit_code = os.system(cmd)
if exit_code != 0:
raise RuntimeError("The command exits with non-zero code %s" % exit_code)

def _build(self, args: List[str], build_dir: str, build_tag: str) -> None:
cmd = "docker build {} {}".format(" ".join(args), build_dir)
Expand Down

0 comments on commit 5b80583

Please sign in to comment.