Skip to content

Commit

Permalink
fix(cluster): Don't generate random node names
Browse files Browse the repository at this point in the history
  • Loading branch information
ieQu1 committed Jun 30, 2023
1 parent 2e527eb commit 74a82f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/conf/emqttb_conf_model.erl
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ model() ->
, prog_name => "emqttb"
}}
, cluster =>
#{ enabled =>
#{ node_name =>
{[value, os_env],
#{ oneliner => "Enable clustering"
, type => boolean()
, default => true
, type => atom()
, default => undefined
}}
}
, interval =>
Expand Down
18 changes: 10 additions & 8 deletions src/framework/emqttb_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ post_init() ->
, {emqttb_pushgw, start_link, []}
),
emqttb_logger:setup(),
?CFG([cluster, enabled]) andalso
start_distr(),
maybe_start_distr(),
ok.

start_distr() ->
os:cmd("epmd -daemon"),
Opts = #{dist_listen => true, name_domain => shortnames},
Name = list_to_atom("emqttb-" ++ [$A + rand:uniform($Z-$A) - 1 || _ <- lists:seq(1, 5)]),
net_kernel:start(Name, Opts),
logger:notice("Started distribution with name: ~p", [node()]).
maybe_start_distr() ->
case ?CFG([cluster, node_name]) of
undefined ->
ok;
Name ->
os:cmd("epmd -daemon"),
Opts = #{dist_listen => true, name_domain => shortnames},
net_kernel:start(Name, Opts)
end.

0 comments on commit 74a82f9

Please sign in to comment.