Improve the Autocluster design
This commit is contained in:
parent
c83b9e6124
commit
15a081c9bb
|
@ -145,45 +145,19 @@ register_acl_mod() ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% AutoCluster
|
%% Autocluster
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
start_autocluster() ->
|
start_autocluster() ->
|
||||||
case application:get_env(?APP, autocluster_lock) of
|
ekka:callback(prepare, fun emqttd:shutdown/1),
|
||||||
undefined ->
|
ekka:callback(reboot, fun emqttd:reboot/0),
|
||||||
application:set_env(?APP, autocluster_lock, true),
|
ekka:autocluster(fun after_autocluster/0).
|
||||||
ekka:callback(prepare, fun emqttd:shutdown/1),
|
|
||||||
ekka:callback(reboot, fun emqttd:reboot/0),
|
|
||||||
run_outside_application({ekka_autocluster, start, [fun after_autocluster/0]});
|
|
||||||
{ok, _Lock} ->
|
|
||||||
ignore
|
|
||||||
end.
|
|
||||||
|
|
||||||
after_autocluster() ->
|
after_autocluster() ->
|
||||||
emqttd_plugins:init(),
|
emqttd_plugins:init(),
|
||||||
emqttd_plugins:load(),
|
emqttd_plugins:load(),
|
||||||
start_listeners().
|
start_listeners().
|
||||||
|
|
||||||
run_outside_application({M, F, Args}) ->
|
|
||||||
spawn(fun() ->
|
|
||||||
group_leader(whereis(init), self()),
|
|
||||||
wait_app_ready(5),
|
|
||||||
try erlang:apply(M, F, Args)
|
|
||||||
catch
|
|
||||||
_:Error -> lager:error("Autocluster exception: ~p", [Error])
|
|
||||||
end,
|
|
||||||
application:unset_env(?APP, autocluster_lock)
|
|
||||||
end).
|
|
||||||
|
|
||||||
wait_app_ready(0) ->
|
|
||||||
timeout;
|
|
||||||
wait_app_ready(Retries) ->
|
|
||||||
case lists:keymember(?APP, 1, application:which_applications()) of
|
|
||||||
true -> ok;
|
|
||||||
false -> timer:sleep(1000),
|
|
||||||
wait_app_ready(Retries - 1)
|
|
||||||
end.
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Start Listeners
|
%% Start Listeners
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue