From 7e9c119c9ae291e42073e5cf92ad7b79a55f4320 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Sun, 3 May 2015 21:27:28 +0800 Subject: [PATCH 1/6] detailed --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ec2dca6dd..8d2463ad3 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ cd emqttd && make && make dist ## GetStarted -Read [emqtt wiki](https://github.com/emqtt/emqttd/wiki) for detaied installation and configuration guide. +Read [emqtt wiki](https://github.com/emqtt/emqttd/wiki) for detailed installation and configuration guide. ## Benchmark From a18bd4998404eb66f44e51d136a4ddafc509b434 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Sun, 3 May 2015 22:01:07 +0800 Subject: [PATCH 2/6] ACL --- rel/files/acl.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rel/files/acl.config b/rel/files/acl.config index e17d28cef..c1985f1d4 100644 --- a/rel/files/acl.config +++ b/rel/files/acl.config @@ -1,6 +1,6 @@ %%%----------------------------------------------------------------------------- %% -%% [ACL Design](https://github.com/emqtt/emqttd/wiki/ACL-Design) +%% [ACL](https://github.com/emqtt/emqttd/wiki/ACL) %% %% -type who() :: all | binary() | %% {ipaddr, esockd_access:cidr()} | From 21f5d730d95a7a5328ae0854ebf47abe4e950c11 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Mon, 4 May 2015 11:34:24 +0800 Subject: [PATCH 3/6] rm placeholder --- plugins/emqttd_auth_mysql/.placehodler | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 plugins/emqttd_auth_mysql/.placehodler diff --git a/plugins/emqttd_auth_mysql/.placehodler b/plugins/emqttd_auth_mysql/.placehodler deleted file mode 100644 index e69de29bb..000000000 From f0b544369b414df1aeda2434558d3d438c9326c5 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Mon, 4 May 2015 19:58:54 +0800 Subject: [PATCH 4/6] fix issue #123 --- apps/emqttd/src/emqttd.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/emqttd/src/emqttd.erl b/apps/emqttd/src/emqttd.erl index c14bef228..cbec8e384 100644 --- a/apps/emqttd/src/emqttd.erl +++ b/apps/emqttd/src/emqttd.erl @@ -162,7 +162,7 @@ loaded_plugins() -> -spec unload_all_plugins() -> [{App :: atom(), ok | {error, any()}}]. unload_all_plugins() -> PluginApps = application:get_env(emqttd, plugins, []), - [{App, unload_plugin(App)} || {App, _Env} <- PluginApps]. + [{App, unload_plugin(App)} || App <- PluginApps]. %%------------------------------------------------------------------------------ From 14421dae5bfc0de57c9cf6ffef739649ffc3d912 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Mon, 4 May 2015 20:02:51 +0800 Subject: [PATCH 5/6] prep_stop to close listeners --- apps/emqttd/src/emqttd_app.erl | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/apps/emqttd/src/emqttd_app.erl b/apps/emqttd/src/emqttd_app.erl index 52a737f74..80bbd968e 100644 --- a/apps/emqttd/src/emqttd_app.erl +++ b/apps/emqttd/src/emqttd_app.erl @@ -31,7 +31,7 @@ -behaviour(application). %% Application callbacks --export([start/2, stop/1]). +-export([start/2, prep_stop/1, stop/1]). -define(PRINT_MSG(Msg), io:format(Msg)). @@ -47,24 +47,24 @@ State :: term(), Reason :: term(). start(_StartType, _StartArgs) -> - print_banner(), + print_banner(), emqttd_mnesia:start(), {ok, Sup} = emqttd_sup:start_link(), - start_servers(Sup), - {ok, Listeners} = application:get_env(listeners), + start_servers(Sup), + {ok, Listeners} = application:get_env(listeners), emqttd:load_all_plugins(), emqttd:open_listeners(Listeners), - register(emqttd, self()), + register(emqttd, self()), print_vsn(), - {ok, Sup}. + {ok, Sup}. print_banner() -> - ?PRINT("starting emqttd on node '~s'~n", [node()]). + ?PRINT("starting emqttd on node '~s'~n", [node()]). print_vsn() -> - {ok, Vsn} = application:get_key(vsn), - {ok, Desc} = application:get_key(description), - ?PRINT("~s ~s is running now~n", [Desc, Vsn]). + {ok, Vsn} = application:get_key(vsn), + {ok, Desc} = application:get_key(description), + ?PRINT("~s ~s is running now~n", [Desc, Vsn]). start_servers(Sup) -> Servers = [{"emqttd event", emqttd_event}, @@ -128,10 +128,16 @@ worker_spec(Name, Opts) -> {Name, start_link, [Opts]}, permanent, 10000, worker, [Name]}. +%% close all listeners first... +prep_stop(State) -> + %%TODO: esockd app should be running... + {ok, Listeners} = application:get_env(listeners), + emqttd:close_listeners(Listeners), + timer:sleep(2), + State. + -spec stop(State :: term()) -> term(). stop(_State) -> - {ok, Listeners} = application:get_env(listeners), - emqttd:close_listeners(Listeners), - emqttd:unload_all_plugins(), ok. + From a7344248e48b55def191746011992a1612d513f6 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Mon, 4 May 2015 20:05:16 +0800 Subject: [PATCH 6/6] fix issue #121, unload plugins, stop/start gproc app when clustering... --- apps/emqttd/src/emqttd_ctl.erl | 43 ++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/apps/emqttd/src/emqttd_ctl.erl b/apps/emqttd/src/emqttd_ctl.erl index 8a236d35a..3499c3855 100644 --- a/apps/emqttd/src/emqttd_ctl.erl +++ b/apps/emqttd/src/emqttd_ctl.erl @@ -57,10 +57,10 @@ status([]) -> {InternalStatus, _ProvidedStatus} = init:get_status(), ?PRINT("Node ~p is ~p~n", [node(), InternalStatus]), case lists:keysearch(emqttd, 1, application:which_applications()) of - false -> - ?PRINT_MSG("emqttd is not running~n"); - {value,_Version} -> - ?PRINT_MSG("emqttd is running~n") + false -> + ?PRINT_MSG("emqttd is not running~n"); + {value,_Version} -> + ?PRINT_MSG("emqttd is running~n") end. %%------------------------------------------------------------------------------ @@ -72,32 +72,41 @@ cluster([]) -> ?PRINT("cluster nodes: ~p~n", [Nodes]); cluster([SNode]) -> - Node = node_name(SNode), - case net_adm:ping(Node) of - pong -> - application:stop(emqttd), - application:stop(esockd), - emqttd_mnesia:cluster(Node), - application:start(esockd), - application:start(emqttd), - ?PRINT("cluster with ~p successfully.~n", [Node]); - pang -> + Node = node_name(SNode), + case net_adm:ping(Node) of + pong -> + case emqttd:is_running(Node) of + true -> + %%TODO: should not unload here. + emqttd:unload_all_plugins(), + application:stop(emqttd), + application:stop(esockd), + application:stop(gproc), + emqttd_mnesia:cluster(Node), + application:start(gproc), + application:start(esockd), + application:start(emqttd), + ?PRINT("cluster with ~p successfully.~n", [Node]); + false -> + ?PRINT("emqttd is not running on ~p~n", [Node]) + end; + pang -> ?PRINT("failed to connect to ~p~n", [Node]) - end. + end. %%------------------------------------------------------------------------------ %% @doc Add usern %% @end %%------------------------------------------------------------------------------ useradd([Username, Password]) -> - ?PRINT("~p~n", [emqttd_auth_username:add_user(bin(Username), bin(Password))]). + ?PRINT("~p~n", [emqttd_auth_username:add_user(bin(Username), bin(Password))]). %%------------------------------------------------------------------------------ %% @doc Delete user %% @end %%------------------------------------------------------------------------------ userdel([Username]) -> - ?PRINT("~p~n", [emqttd_auth_username:remove_user(bin(Username))]). + ?PRINT("~p~n", [emqttd_auth_username:remove_user(bin(Username))]). vm([]) -> [vm([Name]) || Name <- ["load", "memory", "process", "io"]];