summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2017-05-21 11:17:46 -0400
committerFred Hebert <mononcqc@ferd.ca>2017-05-21 11:17:46 -0400
commit3ac0e40181a3d747decbc6bca3017ed62dfd6368 (patch)
treed57d4cc42c555f6a0c535f9304ce1e7a6d00841d
parenteaf2e5496303cd75dc5939d4554942a8365f4777 (diff)
Try to start epmd when distribution fails
We do it by calling os:cmd on a named shell so that the automated daemon rules work for rebar3 as well.
-rw-r--r--src/rebar_dist_utils.erl25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/rebar_dist_utils.erl b/src/rebar_dist_utils.erl
index 93edf9d..5de858e 100644
--- a/src/rebar_dist_utils.erl
+++ b/src/rebar_dist_utils.erl
@@ -51,14 +51,27 @@ find_options(State) ->
%%% PRIVATE %%%
%%%%%%%%%%%%%%%
start(Name, Type, Opts) ->
- check_epmd(net_kernel:start([Name, Type])),
+ case dist_up(net_kernel:start([Name, Type])) of
+ false ->
+ start_epmd(),
+ dist_up(net_kernel:start([Name, Type])) orelse warn_dist();
+ true ->
+ ok
+ end,
setup_cookie(Opts).
-check_epmd({error,{{shutdown, {_,net_kernel,{'EXIT',nodistribution}}},_}}) ->
- ?ERROR("Erlang Distribution failed, falling back to nonode@nohost. "
- "Verify that epmd is running and try again.",[]);
-check_epmd(_) ->
- ok.
+dist_up({error,{{shutdown,{_,net_kernel,{'EXIT',nodistribution}}},_}}) -> false;
+dist_up(_) -> true.
+
+start_epmd() ->
+ %% Indirectly boot EPMD through calling Erlang so that we don't risk
+ %% attaching it to the current proc
+ ?CONSOLE("Attempting to start epmd...", []),
+ os:cmd("erl -sname a -eval 'halt(0).'").
+
+warn_dist() ->
+ ?ERROR("Erlang Distribution failed, falling back to nonode@nohost.", []).
+
setup_cookie(Opts) ->
case {node(), proplists:get_value(setcookie, Opts, nocookie)} of