From 74a82f9374bbfeb377f143cca19af6b22ecb42ab Mon Sep 17 00:00:00 2001 From: ieQu1 <99872536+ieQu1@users.noreply.github.com> Date: Fri, 30 Jun 2023 13:11:44 +0200 Subject: [PATCH] fix(cluster): Don't generate random node names --- src/conf/emqttb_conf_model.erl | 6 +++--- src/framework/emqttb_app.erl | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/conf/emqttb_conf_model.erl b/src/conf/emqttb_conf_model.erl index 3313089..f598ea7 100644 --- a/src/conf/emqttb_conf_model.erl +++ b/src/conf/emqttb_conf_model.erl @@ -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 => diff --git a/src/framework/emqttb_app.erl b/src/framework/emqttb_app.erl index abe4b71..588cc3f 100644 --- a/src/framework/emqttb_app.erl +++ b/src/framework/emqttb_app.erl @@ -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.