summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2014-04-09 16:45:03 +0100
committerSimon MacMullen <simon@rabbitmq.com>2014-04-09 16:45:03 +0100
commitec052f41f5fec2eec85192b69fee6d4e75ae3252 (patch)
tree3bdf3644276b1c0e7d58defb194112eff5e44ecf
parentb053b9ad0d50423c59c0f10d8e2b42b2565b2854 (diff)
parent6dfd4d2964faebda2668312cc4b3c43f3945618c (diff)
downloadrabbitmq-server-ec052f41f5fec2eec85192b69fee6d4e75ae3252.tar.gz
Merge bug25855
-rw-r--r--src/rabbit_alarm.erl3
-rw-r--r--src/rabbit_disk_monitor.erl14
-rw-r--r--src/rabbit_restartable_sup.erl19
-rw-r--r--src/rabbit_sup.erl15
4 files changed, 34 insertions, 17 deletions
diff --git a/src/rabbit_alarm.erl b/src/rabbit_alarm.erl
index 983ab2e4..308f9a2e 100644
--- a/src/rabbit_alarm.erl
+++ b/src/rabbit_alarm.erl
@@ -62,7 +62,8 @@ start() ->
end,
fun clear_alarm/1]),
{ok, DiskLimit} = application:get_env(disk_free_limit),
- rabbit_sup:start_restartable_child(rabbit_disk_monitor, [DiskLimit]),
+ rabbit_sup:start_delayed_restartable_child(
+ rabbit_disk_monitor, [DiskLimit]),
ok.
stop() -> ok.
diff --git a/src/rabbit_disk_monitor.erl b/src/rabbit_disk_monitor.erl
index ab443780..fbf13a90 100644
--- a/src/rabbit_disk_monitor.erl
+++ b/src/rabbit_disk_monitor.erl
@@ -103,7 +103,7 @@ init([Limit]) ->
{ok, start_timer(set_disk_limits(State, Limit))};
Err ->
rabbit_log:info("Disabling disk free space monitoring "
- "on unsupported platform: ~p~n", [Err]),
+ "on unsupported platform:~n~p~n", [Err]),
{stop, unsupported_platform}
end.
@@ -188,10 +188,14 @@ get_disk_free(Dir, {unix, _}) ->
get_disk_free(Dir, {win32, _}) ->
parse_free_win32(rabbit_misc:os_cmd("dir /-C /W \"" ++ Dir ++ "\"")).
-parse_free_unix(CommandResult) ->
- [_, Stats | _] = string:tokens(CommandResult, "\n"),
- [_FS, _Total, _Used, Free | _] = string:tokens(Stats, " \t"),
- list_to_integer(Free) * 1024.
+parse_free_unix(Str) ->
+ case string:tokens(Str, "\n") of
+ [_, S | _] -> case string:tokens(S, " \t") of
+ [_, _, _, Free | _] -> list_to_integer(Free) * 1024;
+ _ -> exit({unparseable, Str})
+ end;
+ _ -> exit({unparseable, Str})
+ end.
parse_free_win32(CommandResult) ->
LastLine = lists:last(string:tokens(CommandResult, "\r\n")),
diff --git a/src/rabbit_restartable_sup.erl b/src/rabbit_restartable_sup.erl
index c6111c43..3366bad7 100644
--- a/src/rabbit_restartable_sup.erl
+++ b/src/rabbit_restartable_sup.erl
@@ -16,28 +16,33 @@
-module(rabbit_restartable_sup).
--behaviour(supervisor).
+-behaviour(supervisor2).
--export([start_link/2]).
+-export([start_link/3]).
-export([init/1]).
-include("rabbit.hrl").
+-define(DELAY, 2).
+
%%----------------------------------------------------------------------------
-ifdef(use_specs).
--spec(start_link/2 :: (atom(), rabbit_types:mfargs()) ->
+-spec(start_link/3 :: (atom(), rabbit_types:mfargs(), boolean()) ->
rabbit_types:ok_pid_or_error()).
-endif.
%%----------------------------------------------------------------------------
-start_link(Name, {_M, _F, _A} = Fun) ->
- supervisor:start_link({local, Name}, ?MODULE, [Fun]).
+start_link(Name, {_M, _F, _A} = Fun, Delay) ->
+ supervisor2:start_link({local, Name}, ?MODULE, [Fun, Delay]).
-init([{Mod, _F, _A} = Fun]) ->
+init([{Mod, _F, _A} = Fun, Delay]) ->
{ok, {{one_for_one, 10, 10},
- [{Mod, Fun, transient, ?MAX_WAIT, worker, [Mod]}]}}.
+ [{Mod, Fun, case Delay of
+ true -> {transient, 1};
+ false -> transient
+ end, ?MAX_WAIT, worker, [Mod]}]}}.
diff --git a/src/rabbit_sup.erl b/src/rabbit_sup.erl
index 63c5e465..c90bb94c 100644
--- a/src/rabbit_sup.erl
+++ b/src/rabbit_sup.erl
@@ -21,7 +21,9 @@
-export([start_link/0, start_child/1, start_child/2, start_child/3,
start_supervisor_child/1, start_supervisor_child/2,
start_supervisor_child/3,
- start_restartable_child/1, start_restartable_child/2, stop_child/1]).
+ start_restartable_child/1, start_restartable_child/2,
+ start_delayed_restartable_child/1, start_delayed_restartable_child/2,
+ stop_child/1]).
-export([init/1]).
@@ -42,6 +44,8 @@
-spec(start_supervisor_child/3 :: (atom(), atom(), [any()]) -> 'ok').
-spec(start_restartable_child/1 :: (atom()) -> 'ok').
-spec(start_restartable_child/2 :: (atom(), [any()]) -> 'ok').
+-spec(start_delayed_restartable_child/1 :: (atom()) -> 'ok').
+-spec(start_delayed_restartable_child/2 :: (atom(), [any()]) -> 'ok').
-spec(stop_child/1 :: (atom()) -> rabbit_types:ok_or_error(any())).
-endif.
@@ -70,14 +74,17 @@ start_supervisor_child(ChildId, Mod, Args) ->
{ChildId, {Mod, start_link, Args},
transient, infinity, supervisor, [Mod]})).
-start_restartable_child(Mod) -> start_restartable_child(Mod, []).
+start_restartable_child(M) -> start_restartable_child(M, [], false).
+start_restartable_child(M, A) -> start_restartable_child(M, A, false).
+start_delayed_restartable_child(M) -> start_restartable_child(M, [], true).
+start_delayed_restartable_child(M, A) -> start_restartable_child(M, A, true).
-start_restartable_child(Mod, Args) ->
+start_restartable_child(Mod, Args, Delay) ->
Name = list_to_atom(atom_to_list(Mod) ++ "_sup"),
child_reply(supervisor:start_child(
?SERVER,
{Name, {rabbit_restartable_sup, start_link,
- [Name, {Mod, start_link, Args}]},
+ [Name, {Mod, start_link, Args}, Delay]},
transient, infinity, supervisor, [rabbit_restartable_sup]})).
stop_child(ChildId) ->