Переделать связь нод в кластере на автоматическое обнаружение #9
This commit is contained in:
@@ -30,6 +30,11 @@ get_permissions(superadmin) ->
|
||||
<<"manage_calendars">>, <<"manage_reviews">>, <<"manage_reports">>,
|
||||
<<"manage_tickets">>, <<"manage_banned_words">>, <<"view_stats">>,
|
||||
<<"view_audit">>];
|
||||
get_permissions(admin) ->
|
||||
[<<"manage_users">>, <<"manage_events">>,
|
||||
<<"manage_calendars">>, <<"manage_reviews">>, <<"manage_reports">>,
|
||||
<<"manage_tickets">>, <<"manage_banned_words">>, <<"view_stats">>,
|
||||
<<"view_audit">>];
|
||||
get_permissions(moderator) ->
|
||||
[<<"manage_events">>, <<"manage_calendars">>, <<"manage_reviews">>,
|
||||
<<"manage_reports">>, <<"manage_tickets">>, <<"manage_banned_words">>,
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
-module(cluster_discovery).
|
||||
-export([discover/0]).
|
||||
|
||||
-define(DNS_ALIAS, "eventhub-node").
|
||||
-define(RETRY_INTERVAL, 5000).
|
||||
|
||||
discover() ->
|
||||
io:format("Starting cluster DNS discovery via epmd (~s)...~n", [?DNS_ALIAS]),
|
||||
discover_loop().
|
||||
|
||||
discover_loop() ->
|
||||
case inet:getaddrs(?DNS_ALIAS, inet) of
|
||||
{ok, IPs} when is_list(IPs) ->
|
||||
lists:foreach(fun(IP) ->
|
||||
IPStr = inet:ntoa(IP),
|
||||
%% io:format("Checking epmd on ~s...~n", [IPStr]),
|
||||
case erl_epmd:names(IP) of
|
||||
{ok, List} ->
|
||||
lists:foreach(fun({Name, _Port}) ->
|
||||
Node = list_to_atom(Name ++ "@" ++ Name),
|
||||
%% io:format(" Trying net_kernel:connect_node(~s)...~n", [Node]),
|
||||
case net_kernel:connect_node(Node) of
|
||||
true -> ok; %io:format(" *** Connected to ~s ***~n", [Node]);
|
||||
false -> io:format(" *** Failed to connect to ~s ***~n", [Node]);
|
||||
ignored -> ok
|
||||
end
|
||||
end, List);
|
||||
{error, Reason} ->
|
||||
io:format(" epmd error on ~s: ~p~n", [IPStr, Reason])
|
||||
end
|
||||
end, IPs);
|
||||
{error, Reason} ->
|
||||
io:format("DNS lookup failed (~p), retrying...~n", [Reason])
|
||||
end,
|
||||
timer:sleep(?RETRY_INTERVAL),
|
||||
discover_loop().
|
||||
Reference in New Issue
Block a user