Merge branch 'master' into dev

This commit is contained in:
Feng Lee 2015-05-04 20:12:08 +08:00
commit 04e4205444
6 changed files with 48 additions and 33 deletions

View File

@ -75,7 +75,7 @@ cd emqttd && make && make dist
## GetStarted ## 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 ## Benchmark

View File

@ -162,7 +162,7 @@ loaded_plugins() ->
-spec unload_all_plugins() -> [{App :: atom(), ok | {error, any()}}]. -spec unload_all_plugins() -> [{App :: atom(), ok | {error, any()}}].
unload_all_plugins() -> unload_all_plugins() ->
PluginApps = application:get_env(emqttd, plugins, []), PluginApps = application:get_env(emqttd, plugins, []),
[{App, unload_plugin(App)} || {App, _Env} <- PluginApps]. [{App, unload_plugin(App)} || App <- PluginApps].
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------

View File

@ -31,7 +31,7 @@
-behaviour(application). -behaviour(application).
%% Application callbacks %% Application callbacks
-export([start/2, stop/1]). -export([start/2, prep_stop/1, stop/1]).
-define(PRINT_MSG(Msg), io:format(Msg)). -define(PRINT_MSG(Msg), io:format(Msg)).
@ -47,24 +47,24 @@
State :: term(), State :: term(),
Reason :: term(). Reason :: term().
start(_StartType, _StartArgs) -> start(_StartType, _StartArgs) ->
print_banner(), print_banner(),
emqttd_mnesia:start(), emqttd_mnesia:start(),
{ok, Sup} = emqttd_sup:start_link(), {ok, Sup} = emqttd_sup:start_link(),
start_servers(Sup), start_servers(Sup),
{ok, Listeners} = application:get_env(listeners), {ok, Listeners} = application:get_env(listeners),
emqttd:load_all_plugins(), emqttd:load_all_plugins(),
emqttd:open_listeners(Listeners), emqttd:open_listeners(Listeners),
register(emqttd, self()), register(emqttd, self()),
print_vsn(), print_vsn(),
{ok, Sup}. {ok, Sup}.
print_banner() -> print_banner() ->
?PRINT("starting emqttd on node '~s'~n", [node()]). ?PRINT("starting emqttd on node '~s'~n", [node()]).
print_vsn() -> print_vsn() ->
{ok, Vsn} = application:get_key(vsn), {ok, Vsn} = application:get_key(vsn),
{ok, Desc} = application:get_key(description), {ok, Desc} = application:get_key(description),
?PRINT("~s ~s is running now~n", [Desc, Vsn]). ?PRINT("~s ~s is running now~n", [Desc, Vsn]).
start_servers(Sup) -> start_servers(Sup) ->
Servers = [{"emqttd event", emqttd_event}, Servers = [{"emqttd event", emqttd_event},
@ -128,10 +128,16 @@ worker_spec(Name, Opts) ->
{Name, start_link, [Opts]}, {Name, start_link, [Opts]},
permanent, 10000, worker, [Name]}. 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(). -spec stop(State :: term()) -> term().
stop(_State) -> stop(_State) ->
{ok, Listeners} = application:get_env(listeners),
emqttd:close_listeners(Listeners),
emqttd:unload_all_plugins(),
ok. ok.

View File

@ -57,10 +57,10 @@ status([]) ->
{InternalStatus, _ProvidedStatus} = init:get_status(), {InternalStatus, _ProvidedStatus} = init:get_status(),
?PRINT("Node ~p is ~p~n", [node(), InternalStatus]), ?PRINT("Node ~p is ~p~n", [node(), InternalStatus]),
case lists:keysearch(emqttd, 1, application:which_applications()) of case lists:keysearch(emqttd, 1, application:which_applications()) of
false -> false ->
?PRINT_MSG("emqttd is not running~n"); ?PRINT_MSG("emqttd is not running~n");
{value,_Version} -> {value,_Version} ->
?PRINT_MSG("emqttd is running~n") ?PRINT_MSG("emqttd is running~n")
end. end.
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
@ -72,32 +72,41 @@ cluster([]) ->
?PRINT("cluster nodes: ~p~n", [Nodes]); ?PRINT("cluster nodes: ~p~n", [Nodes]);
cluster([SNode]) -> cluster([SNode]) ->
Node = node_name(SNode), Node = node_name(SNode),
case net_adm:ping(Node) of case net_adm:ping(Node) of
pong -> pong ->
application:stop(emqttd), case emqttd:is_running(Node) of
application:stop(esockd), true ->
emqttd_mnesia:cluster(Node), %%TODO: should not unload here.
application:start(esockd), emqttd:unload_all_plugins(),
application:start(emqttd), application:stop(emqttd),
?PRINT("cluster with ~p successfully.~n", [Node]); application:stop(esockd),
pang -> 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]) ?PRINT("failed to connect to ~p~n", [Node])
end. end.
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
%% @doc Add usern %% @doc Add usern
%% @end %% @end
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
useradd([Username, Password]) -> 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 %% @doc Delete user
%% @end %% @end
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
userdel([Username]) -> userdel([Username]) ->
?PRINT("~p~n", [emqttd_auth_username:remove_user(bin(Username))]). ?PRINT("~p~n", [emqttd_auth_username:remove_user(bin(Username))]).
vm([]) -> vm([]) ->
[vm([Name]) || Name <- ["load", "memory", "process", "io"]]; [vm([Name]) || Name <- ["load", "memory", "process", "io"]];

View File

@ -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() | %% -type who() :: all | binary() |
%% {ipaddr, esockd_access:cidr()} | %% {ipaddr, esockd_access:cidr()} |