Skip to content

Commit

Permalink
Improve error message if we can't boot epmd, closes #196
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Apr 15, 2021
1 parent 5190e01 commit 59dee1b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
28 changes: 26 additions & 2 deletions lib/livebook/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule Livebook.Application do
@moduledoc false

use Application
require Logger

def start(_type, _args) do
ensure_distribution!()
Expand Down Expand Up @@ -39,16 +40,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
Expand Down
2 changes: 2 additions & 0 deletions lib/livebook/runtime/elixir_standalone.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/livebook/runtime/mix_standalone.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
])
Expand Down

0 comments on commit 59dee1b

Please sign in to comment.