fix issue #121, unload plugins, stop/start gproc app when clustering...

This commit is contained in:
Feng Lee 2015-05-04 20:05:16 +08:00
parent 14421dae5b
commit a7344248e4
1 changed files with 26 additions and 17 deletions

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"]];