diff --git a/rebar.config b/rebar.config index 0ce2b3602..834382f05 100644 --- a/rebar.config +++ b/rebar.config @@ -1,4 +1,4 @@ {deps, [ -{goldrush,".*",{git,"https://github.com/basho/goldrush","0.1.9"}},{gproc,".*",{git,"https://github.com/uwiger/gproc",""}},{lager,".*",{git,"https://github.com/basho/lager","master"}},{esockd,".*",{git,"https://github.com/emqtt/esockd","master"}},{ekka,".*",{git,"https://github.com/emqtt/ekka","master"}},{mochiweb,".*",{git,"https://github.com/emqtt/mochiweb","master"}},{pbkdf2,".*",{git,"https://github.com/emqtt/pbkdf2","2.0.1"}},{lager_syslog,".*",{git,"https://github.com/basho/lager_syslog",""}},{bcrypt,".*",{git,"https://github.com/smarkets/erlang-bcrypt","master"}} +{goldrush,".*",{git,"https://github.com/basho/goldrush","0.1.9"}},{gproc,".*",{git,"https://github.com/uwiger/gproc",""}},{lager,".*",{git,"https://github.com/basho/lager","master"}},{esockd,".*",{git,"https://github.com/emqtt/esockd","master"}},{ekka,".*",{git,"https://github.com/emqtt/ekka","develop"}},{mochiweb,".*",{git,"https://github.com/emqtt/mochiweb","master"}},{pbkdf2,".*",{git,"https://github.com/emqtt/pbkdf2","2.0.1"}},{lager_syslog,".*",{git,"https://github.com/basho/lager_syslog",""}},{bcrypt,".*",{git,"https://github.com/smarkets/erlang-bcrypt","master"}} ]}. {erl_opts, [debug_info,{parse_transform,lager_transform}]}. diff --git a/src/emqttd_app.erl b/src/emqttd_app.erl index acca547be..0ebb6b5c4 100644 --- a/src/emqttd_app.erl +++ b/src/emqttd_app.erl @@ -39,14 +39,14 @@ start(_Type, _Args) -> print_banner(), - ekka:start(), + %%ekka:start(), {ok, Sup} = emqttd_sup:start_link(), start_servers(Sup), emqttd_cli:load(), register_acl_mod(), emqttd_plugins:init(), emqttd_plugins:load(), - init_cluster(), + cluster_bootstrap(), start_listeners(), register(emqttd, self()), print_vsn(), @@ -148,12 +148,16 @@ register_acl_mod() -> end. %%-------------------------------------------------------------------- -%% Init Cluster +%% Cluster bootstrap %%-------------------------------------------------------------------- -init_cluster() -> +cluster_bootstrap() -> ekka:callback(prepare, fun emqttd:shutdown/1), - ekka:callback(reboot, fun emqttd:reboot/0). + ekka:callback(reboot, fun emqttd:reboot/0), + run_outside_application(5000, fun ekka_autocluster:bootstrap/0). + +run_outside_application(Delay, Fun) -> + spawn(fun() -> group_leader(whereis(init), self()), timer:sleep(Delay), Fun() end). %%-------------------------------------------------------------------- %% Start Listeners diff --git a/src/emqttd_router.erl b/src/emqttd_router.erl index 9efe8b612..8806e9904 100644 --- a/src/emqttd_router.erl +++ b/src/emqttd_router.erl @@ -218,7 +218,7 @@ stop() -> gen_server:call(?ROUTER, stop). init([]) -> ekka:monitor(membership), ets:new(mqtt_local_route, [set, named_table, protected]), - {ok, TRef} = timer:send_interval(timer:seconds(1), stats), + {ok, TRef} = timer:send_interval(timer:seconds(1), stats), {ok, #state{stats_timer = TRef}}. handle_call(stop, _From, State) ->