summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexey Lebedeff <alebedev@mirantis.com>2016-01-12 14:31:45 +0300
committerAlexey Lebedeff <alebedev@mirantis.com>2016-01-12 17:03:19 +0300
commitdbbe3d6e473fcfaa725e7aa0dda10601b63b9c27 (patch)
tree32200abb039cb773039c3ae2ba3573eeaa649b61 /src
parent1dcaad8f4859a04d2e6e427e9aaf4e948bdd417e (diff)
downloadrabbitmq-server-git-dbbe3d6e473fcfaa725e7aa0dda10601b63b9c27.tar.gz
Fix 'rabbitmqctl rotate_logs' behaviour
When 'rabbitmqctl rotate_logs' is called without any parameters, it clears logs unconditionally. And given that this form is used in logrotate config files, this could result in data loss. This could be reproduced with following scenario: 1) 'max_size' is set globally in lograte config 2) One of two rabbitmq logs is greater than that limit 3) Daily logrotate run was already performed today, and now we are calling it manually. In this case logrotate will copy only file that is bigger than max_size, but 'rabbitmqctl rotate_logs' will clear both of them - leading to data loss.
Diffstat (limited to 'src')
-rw-r--r--src/rabbit.erl7
-rw-r--r--src/rabbit_error_logger_file_h.erl3
-rw-r--r--src/rabbit_sasl_report_file_h.erl2
3 files changed, 11 insertions, 1 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl
index e4cf7bcbbd..1c4480b3e7 100644
--- a/src/rabbit.erl
+++ b/src/rabbit.erl
@@ -442,9 +442,14 @@ environment(App) ->
lists:keysort(1, [P || P = {K, _} <- application:get_all_env(App),
not lists:member(K, Ignore)]).
+rotate_logs_info("") ->
+ rabbit_log:info("Reopening logs", []);
+rotate_logs_info(Suffix) ->
+ rabbit_log:info("Rotating logs with suffix '~s'~n", [Suffix]).
+
rotate_logs(BinarySuffix) ->
Suffix = binary_to_list(BinarySuffix),
- rabbit_log:info("Rotating logs with suffix '~s'~n", [Suffix]),
+ rotate_logs_info(Suffix),
log_rotation_result(rotate_logs(log_location(kernel),
Suffix,
rabbit_error_logger_file_h),
diff --git a/src/rabbit_error_logger_file_h.erl b/src/rabbit_error_logger_file_h.erl
index 9268c10a35..930aead392 100644
--- a/src/rabbit_error_logger_file_h.erl
+++ b/src/rabbit_error_logger_file_h.erl
@@ -55,6 +55,9 @@ get_depth() ->
%% lib/stdlib/src/error_logger_file_h.erl from R14B3 was copied as
%% init_file/2 and changed so that it opens the file in 'append' mode.
+%% Log rotation with empty suffix should result only in file re-opening.
+init({{File, ""}, _}) ->
+ init(File);
%% Used only when swapping handlers in log rotation, pre OTP 18.1
init({{File, Suffix}, []}) ->
rotate_logs(File, Suffix),
diff --git a/src/rabbit_sasl_report_file_h.erl b/src/rabbit_sasl_report_file_h.erl
index 9ba24ab325..9c6d7657f2 100644
--- a/src/rabbit_sasl_report_file_h.erl
+++ b/src/rabbit_sasl_report_file_h.erl
@@ -36,6 +36,8 @@
%% Used only when swapping handlers and performing
%% log rotation
+init({{File, ""}, _}) ->
+ init(File);
init({{File, Suffix}, []}) ->
case rabbit_file:append_file(File, Suffix) of
ok -> file:delete(File),