mirror of
https://github.com/processone/ejabberd.git
synced 2024-07-04 23:15:31 +02:00
New ejabberd command: migrate
Example usage: $ ejabberdctl migrate 60
This commit is contained in:
parent
21c75ebce5
commit
2ea9e6ed59
|
@ -30,7 +30,7 @@
|
|||
-export([start/0, stop/0,
|
||||
%% Server
|
||||
status/0, reopen_log/0,
|
||||
stop_migrate/1,
|
||||
stop_migrate/1, migrate/1,
|
||||
stop_kindly/2, send_service_message_all_mucs/2,
|
||||
%% Erlang
|
||||
update_list/0, update/1,
|
||||
|
@ -91,6 +91,11 @@ commands() ->
|
|||
module = ?MODULE, function = stop_kindly,
|
||||
args = [{delay, integer}, {announcement, string}],
|
||||
result = {res, rescode}},
|
||||
#ejabberd_commands{name = migrate, tags = [server],
|
||||
desc = "Try to migrate C2S/BOSH/MUC sessions to other nodes",
|
||||
module = ?MODULE, function = migrate,
|
||||
args = [{delay, integer}],
|
||||
result = {res, rescode}},
|
||||
#ejabberd_commands{name = stop_migrate, tags = [server],
|
||||
desc = "Try to migrate C2S/BOSH/MUC sessions to other"
|
||||
"nodes and then stop",
|
||||
|
@ -329,6 +334,35 @@ send_service_message_all_mucs(Subject, AnnouncementText) ->
|
|||
end,
|
||||
?MYHOSTS).
|
||||
|
||||
%%%
|
||||
%%% Migrate w/o stopping
|
||||
%%%
|
||||
migrate(DelaySeconds) ->
|
||||
WaitingDesc = io_lib:format("Starting migration, this will take ~p seconds",
|
||||
[DelaySeconds]),
|
||||
Steps = [
|
||||
{"Stopping ejabberd port listeners",
|
||||
ejabberd_listener, stop_listeners, []},
|
||||
{WaitingDesc, ejabberd_cluster, shutdown_migrate,
|
||||
[DelaySeconds * 1000]}
|
||||
],
|
||||
NumberLast = length(Steps),
|
||||
TimestampStart = calendar:datetime_to_gregorian_seconds({date(), time()}),
|
||||
lists:foldl(
|
||||
fun({Desc, Mod, Func, Args}, NumberThis) ->
|
||||
SecondsDiff =
|
||||
calendar:datetime_to_gregorian_seconds({date(), time()})
|
||||
- TimestampStart,
|
||||
io:format("[~p/~p ~ps] ~s... ",
|
||||
[NumberThis, NumberLast, SecondsDiff, Desc]),
|
||||
Result = apply(Mod, Func, Args),
|
||||
io:format("~p~n", [Result]),
|
||||
NumberThis+1
|
||||
end,
|
||||
1,
|
||||
Steps),
|
||||
ok.
|
||||
|
||||
%%%
|
||||
%%% Migrate and stop
|
||||
%%%
|
||||
|
|
Loading…
Reference in New Issue
Block a user