From 15a081c9bb8187cfe9d5ddde90351735c93eb4ac Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Sun, 23 Jul 2017 18:07:53 +0800 Subject: [PATCH] Improve the Autocluster design --- src/emqttd_app.erl | 34 ++++------------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/src/emqttd_app.erl b/src/emqttd_app.erl index b35614cd7..b85834722 100644 --- a/src/emqttd_app.erl +++ b/src/emqttd_app.erl @@ -145,45 +145,19 @@ register_acl_mod() -> end. %%-------------------------------------------------------------------- -%% AutoCluster +%% Autocluster %%-------------------------------------------------------------------- start_autocluster() -> - case application:get_env(?APP, autocluster_lock) of - undefined -> - application:set_env(?APP, autocluster_lock, true), - 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. + ekka:callback(prepare, fun emqttd:shutdown/1), + ekka:callback(reboot, fun emqttd:reboot/0), + ekka:autocluster(fun after_autocluster/0). after_autocluster() -> emqttd_plugins:init(), emqttd_plugins:load(), 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 %%--------------------------------------------------------------------