From d6c9ab1783efa083aea2ead81e078bb920d57ad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Fri, 28 May 2021 13:41:08 +0200 Subject: [PATCH] Ensure hostname is properly resolved when running in shortname distribution (#303) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Ensure hostname is properly resolved when running in shortname distribution * Update lib/livebook/application.ex Co-authored-by: José Valim * Pretty print host resolution error * Add missing env var Co-authored-by: José Valim --- lib/livebook/application.ex | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/livebook/application.ex b/lib/livebook/application.ex index 0843ee52b..3a68508a8 100644 --- a/lib/livebook/application.ex +++ b/lib/livebook/application.ex @@ -7,6 +7,7 @@ defmodule Livebook.Application do def start(_type, _args) do ensure_distribution!() + validate_hostname_resolution!() set_cookie() # We register our own :standard_error below @@ -83,6 +84,27 @@ defmodule Livebook.Application do end end + # See https://github.com/elixir-nx/livebook/issues/302 + defp validate_hostname_resolution!() do + unless Livebook.Config.longname() do + hostname = Livebook.Utils.node_host() |> to_charlist() + + if :inet.gethostbyname(hostname) == {:error, :nxdomain} do + Livebook.Config.abort!(""" + your hostname "#{hostname}" does not resolve to any IP address, which indicates something wrong in your OS configuration. + + Make sure your computer's name resolves locally or start Livebook using a long distribution name. If you are using Livebook's CLI, you can: + + livebook server --name livebook@127.0.0.1 + + If you are running it from source, do instead: + + MIX_ENV=prod elixir --name livebook@127.0.0.1 -S mix phx.server + """) + end + end + end + defp set_cookie() do cookie = Application.fetch_env!(:livebook, :cookie) Node.set_cookie(cookie)