summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2014-04-09 14:01:04 +0100
committerSimon MacMullen <simon@rabbitmq.com>2014-04-09 14:01:04 +0100
commitae0e47d4a8fe4925bff698131e74d140e1a8576a (patch)
tree83cd056ef061f422fd20ef8a248315e5b4c4c54f
parent13522a2240c9ff9d32dc91b1518c4675df4db87e (diff)
downloadrabbitmq-server-ae0e47d4a8fe4925bff698131e74d140e1a8576a.tar.gz
Delayed restart of the disk monitor.
-rw-r--r--src/rabbit_alarm.erl3
-rw-r--r--src/rabbit_restartable_sup.erl19
-rw-r--r--src/rabbit_sup.erl15
3 files changed, 25 insertions, 12 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_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) ->