Improve error message if we can't boot epmd, closes #196 (#197)

This commit is contained in:
José Valim 2021-04-15 11:42:56 +02:00 committed by GitHub
parent 5190e01db7
commit dee372c623
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 2 deletions

View file

@ -39,16 +39,39 @@ defmodule Livebook.Application do
defp ensure_distribution!() do
unless Node.alive?() do
System.cmd("epmd", ["-daemon"])
case System.cmd("epmd", ["-daemon"]) do
{_, 0} ->
:ok
_ ->
abort!("""
could not start epmd (Erlang Port Mapper Driver). Livebook uses epmd to \
talk to different runtimes. You may have to start epmd explicitly by calling:
epmd -daemon
Or by calling:
elixir --sname test -e "IO.puts node()"
Then you can try booting Livebook again
""")
end
{type, name} = get_node_type_and_name()
case Node.start(name, type) do
{:ok, _} -> :ok
{:error, _} -> raise "failed to start distributed node"
{:error, reason} -> abort!("could not start distributed node: #{inspect(reason)}")
end
end
end
defp abort!(message) do
IO.puts("\nERROR!!! [Livebook] " <> message)
System.halt(1)
end
defp get_node_type_and_name() do
Application.get_env(:livebook, :node) || {:shortnames, random_short_name()}
end

View file

@ -55,7 +55,9 @@ defmodule Livebook.Runtime.ElixirStandalone do
defp start_elixir_node(elixir_path, node_name, eval) do
# Here we create a port to start the system process in a non-blocking way.
Port.open({:spawn_executable, elixir_path}, [
:binary,
:nouse_stdio,
:hide,
args: elixir_flags(node_name) ++ ["--eval", eval]
])
end

View file

@ -91,6 +91,7 @@ defmodule Livebook.Runtime.MixStandalone do
Port.open({:spawn_executable, elixir_path}, [
:binary,
:stderr_to_stdout,
:hide,
args: elixir_flags(node_name) ++ ["-S", "mix", "run", "--eval", eval],
cd: project_path
])