|
|
@@ -29,10 +29,9 @@
|
|
|
-include("emqtt_log.hrl").
|
|
|
|
|
|
-export([status/1,
|
|
|
- cluster_info/1,
|
|
|
cluster/1,
|
|
|
- add_user/1,
|
|
|
- delete_user/1]).
|
|
|
+ useradd/1,
|
|
|
+ userdel/1]).
|
|
|
|
|
|
status([]) ->
|
|
|
{InternalStatus, _ProvidedStatus} = init:get_status(),
|
|
|
@@ -44,26 +43,47 @@ status([]) ->
|
|
|
?PRINT_MSG("emqtt is running~n")
|
|
|
end.
|
|
|
|
|
|
-cluster_info([]) ->
|
|
|
+cluster([]) ->
|
|
|
Nodes = [node()|nodes()],
|
|
|
- ?PRINT("cluster nodes: ~p~n", [Nodes]).
|
|
|
+ ?PRINT("cluster nodes: ~p~n", [Nodes]);
|
|
|
|
|
|
cluster([SNode]) ->
|
|
|
- Node = list_to_atom(SNode),
|
|
|
+ Node = node_name(SNode),
|
|
|
case net_adm:ping(Node) of
|
|
|
pong ->
|
|
|
application:stop(emqtt),
|
|
|
+ application:stop(esockd),
|
|
|
mnesia:stop(),
|
|
|
mnesia:start(),
|
|
|
mnesia:change_config(extra_db_nodes, [Node]),
|
|
|
+ application:start(esockd),
|
|
|
application:start(emqtt),
|
|
|
?PRINT("cluster with ~p successfully.~n", [Node]);
|
|
|
pang ->
|
|
|
?PRINT("failed to connect to ~p~n", [Node])
|
|
|
end.
|
|
|
|
|
|
-add_user([Username, Password]) ->
|
|
|
+
|
|
|
+useradd([Username, Password]) ->
|
|
|
?PRINT("~p", [emqtt_auth:add(list_to_binary(Username), list_to_binary(Password))]).
|
|
|
|
|
|
-delete_user([Username]) ->
|
|
|
+userdel([Username]) ->
|
|
|
?PRINT("~p", [emqtt_auth:delete(list_to_binary(Username))]).
|
|
|
+
|
|
|
+node_name(SNode) ->
|
|
|
+ SNode1 =
|
|
|
+ case string:tokens(SNode, "@") of
|
|
|
+ [_Node, _Server] ->
|
|
|
+ SNode;
|
|
|
+ _ ->
|
|
|
+ case net_kernel:longnames() of
|
|
|
+ true ->
|
|
|
+ SNode ++ "@" ++ inet_db:gethostname() ++
|
|
|
+ "." ++ inet_db:res_option(domain);
|
|
|
+ false ->
|
|
|
+ SNode ++ "@" ++ inet_db:gethostname();
|
|
|
+ _ ->
|
|
|
+ SNode
|
|
|
+ end
|
|
|
+ end,
|
|
|
+ list_to_atom(SNode1).
|