|
|
@@ -157,7 +157,7 @@ cluster(["join", SNode]) ->
|
|
|
ignore ->
|
|
|
emqx_ctl:print("Ignore.~n");
|
|
|
{error, Error} ->
|
|
|
- emqx_ctl:print("Failed to join the cluster: ~p~n", [Error])
|
|
|
+ emqx_ctl:print("Failed to join the cluster: ~0p~n", [Error])
|
|
|
end;
|
|
|
|
|
|
cluster(["leave"]) ->
|
|
|
@@ -166,7 +166,7 @@ cluster(["leave"]) ->
|
|
|
emqx_ctl:print("Leave the cluster successfully.~n"),
|
|
|
cluster(["status"]);
|
|
|
{error, Error} ->
|
|
|
- emqx_ctl:print("Failed to leave the cluster: ~p~n", [Error])
|
|
|
+ emqx_ctl:print("Failed to leave the cluster: ~0p~n", [Error])
|
|
|
end;
|
|
|
|
|
|
cluster(["force-leave", SNode]) ->
|
|
|
@@ -177,7 +177,7 @@ cluster(["force-leave", SNode]) ->
|
|
|
ignore ->
|
|
|
emqx_ctl:print("Ignore.~n");
|
|
|
{error, Error} ->
|
|
|
- emqx_ctl:print("Failed to remove the node from cluster: ~p~n", [Error])
|
|
|
+ emqx_ctl:print("Failed to remove the node from cluster: ~0p~n", [Error])
|
|
|
end;
|
|
|
|
|
|
cluster(["status"]) ->
|
|
|
@@ -510,49 +510,73 @@ trace_off(Who, Name) ->
|
|
|
|
|
|
listeners([]) ->
|
|
|
foreach(fun({{Protocol, ListenOn}, _Pid}) ->
|
|
|
- Info = [{acceptors, esockd:get_acceptors({Protocol, ListenOn})},
|
|
|
+ Info = [{listen_on, {string, emqx_listeners:format_listen_on(ListenOn)}},
|
|
|
+ {acceptors, esockd:get_acceptors({Protocol, ListenOn})},
|
|
|
{max_conns, esockd:get_max_connections({Protocol, ListenOn})},
|
|
|
{current_conn, esockd:get_current_connections({Protocol, ListenOn})},
|
|
|
- {shutdown_count, esockd:get_shutdown_count({Protocol, ListenOn})}],
|
|
|
- emqx_ctl:print("listener on ~s:~s~n", [Protocol, esockd:to_string(ListenOn)]),
|
|
|
- foreach(fun({Key, Val}) ->
|
|
|
- emqx_ctl:print(" ~-16s: ~w~n", [Key, Val])
|
|
|
- end, Info)
|
|
|
+ {shutdown_count, esockd:get_shutdown_count({Protocol, ListenOn})}
|
|
|
+ ],
|
|
|
+ emqx_ctl:print("~s~n", [listener_identifier(Protocol, ListenOn)]),
|
|
|
+ foreach(fun indent_print/1, Info)
|
|
|
end, esockd:listeners()),
|
|
|
foreach(fun({Protocol, Opts}) ->
|
|
|
- Info = [{acceptors, maps:get(num_acceptors, proplists:get_value(transport_options, Opts, #{}), 0)},
|
|
|
+ Port = proplists:get_value(port, Opts),
|
|
|
+ Info = [{listen_on, {string, emqx_listeners:format_listen_on(Port)}},
|
|
|
+ {acceptors, maps:get(num_acceptors, proplists:get_value(transport_options, Opts, #{}), 0)},
|
|
|
{max_conns, proplists:get_value(max_connections, Opts)},
|
|
|
{current_conn, proplists:get_value(all_connections, Opts)},
|
|
|
{shutdown_count, []}],
|
|
|
- emqx_ctl:print("listener on ~s:~p~n", [Protocol, proplists:get_value(port, Opts)]),
|
|
|
- foreach(fun({Key, Val}) ->
|
|
|
- emqx_ctl:print(" ~-16s: ~w~n", [Key, Val])
|
|
|
- end, Info)
|
|
|
+ emqx_ctl:print("~s~n", [listener_identifier(Protocol, Port)]),
|
|
|
+ foreach(fun indent_print/1, Info)
|
|
|
end, ranch:info());
|
|
|
|
|
|
-listeners(["stop", Name = "http" ++ _N, ListenOn]) ->
|
|
|
+listeners(["stop", Name = "http" ++ _N | _MaybePort]) ->
|
|
|
+ %% _MaybePort is to be backward compatible, to stop http listener, there is no need for the port number
|
|
|
case minirest:stop_http(list_to_atom(Name)) of
|
|
|
ok ->
|
|
|
- emqx_ctl:print("Stop ~s listener on ~s successfully.~n", [Name, ListenOn]);
|
|
|
+ emqx_ctl:print("Stop ~s listener successfully.~n", [Name]);
|
|
|
{error, Error} ->
|
|
|
- emqx_ctl:print("Failed to stop ~s listener on ~s, error:~p~n", [Name, ListenOn, Error])
|
|
|
+ emqx_ctl:print("Failed to stop ~s listener: ~0p~n", [Name, Error])
|
|
|
end;
|
|
|
|
|
|
-listeners(["stop", Proto, ListenOn]) ->
|
|
|
+listeners(["stop", "mqtt:" ++ _ = Identifier]) ->
|
|
|
+ stop_listener(emqx_listeners:find_by_id(Identifier), Identifier);
|
|
|
+
|
|
|
+listeners(["stop", _Proto, ListenOn]) ->
|
|
|
+ %% this clause is kept to be backward compatible
|
|
|
ListenOn1 = case string:tokens(ListenOn, ":") of
|
|
|
[Port] -> list_to_integer(Port);
|
|
|
[IP, Port] -> {IP, list_to_integer(Port)}
|
|
|
end,
|
|
|
- case emqx_listeners:stop_listener({list_to_atom(Proto), ListenOn1, []}) of
|
|
|
+ stop_listener(emqx_listeners:find_by_listen_on(ListenOn1), ListenOn1);
|
|
|
+
|
|
|
+listeners(["restart", Identifier]) ->
|
|
|
+ case emqx_listeners:restart_listener(Identifier) of
|
|
|
ok ->
|
|
|
- emqx_ctl:print("Stop ~s listener on ~s successfully.~n", [Proto, ListenOn]);
|
|
|
+ emqx_ctl:print("Restarted ~s listener successfully.~n", [Identifier]);
|
|
|
{error, Error} ->
|
|
|
- emqx_ctl:print("Failed to stop ~s listener on ~s, error:~p~n", [Proto, ListenOn, Error])
|
|
|
+ emqx_ctl:print("Failed to restart ~s listener: ~0p~n", [Identifier, Error])
|
|
|
end;
|
|
|
|
|
|
listeners(_) ->
|
|
|
emqx_ctl:usage([{"listeners", "List listeners"},
|
|
|
- {"listeners stop <Proto> <Port>", "Stop a listener"}]).
|
|
|
+ {"listeners stop <Identifier>", "Stop a listener"},
|
|
|
+ {"listeners stop <Proto> <Port>", "Stop a listener"},
|
|
|
+ {"listeners restart <Identifier>", "Restart a listener"}
|
|
|
+ ]).
|
|
|
+
|
|
|
+stop_listener(false, Input) ->
|
|
|
+ emqx_ctl:print("No such listener ~p~n", [Input]);
|
|
|
+stop_listener(#{listen_on := ListenOn} = Listener, _Input) ->
|
|
|
+ ID = emqx_listeners:identifier(Listener),
|
|
|
+ ListenOnStr = emqx_listeners:format_listen_on(ListenOn),
|
|
|
+ case emqx_listeners:stop_listener(Listener) of
|
|
|
+ ok ->
|
|
|
+ emqx_ctl:print("Stop ~s listener on ~s successfully.~n", [ID, ListenOnStr]);
|
|
|
+ {error, Reason} ->
|
|
|
+ emqx_ctl:print("Failed to stop ~s listener on ~s: ~0p~n",
|
|
|
+ [ID, ListenOnStr, Reason])
|
|
|
+ end.
|
|
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
%% @doc data Command
|
|
|
@@ -707,3 +731,16 @@ format(_, Val) ->
|
|
|
Val.
|
|
|
|
|
|
bin(S) -> iolist_to_binary(S).
|
|
|
+
|
|
|
+indent_print({Key, {string, Val}}) ->
|
|
|
+ emqx_ctl:print(" ~-16s: ~s~n", [Key, Val]);
|
|
|
+indent_print({Key, Val}) ->
|
|
|
+ emqx_ctl:print(" ~-16s: ~w~n", [Key, Val]).
|
|
|
+
|
|
|
+listener_identifier(Protocol, ListenOn) ->
|
|
|
+ case emqx_listeners:find_id_by_listen_on(ListenOn) of
|
|
|
+ false ->
|
|
|
+ "http" ++ _ = atom_to_list(Protocol); %% assert
|
|
|
+ ID ->
|
|
|
+ ID
|
|
|
+ end.
|