From 13522a2240c9ff9d32dc91b1518c4675df4db87e Mon Sep 17 00:00:00 2001 From: Simon MacMullen Date: Wed, 9 Apr 2014 13:29:16 +0100 Subject: Make sure we have complete command output if we actually can't parse it. --- src/rabbit_disk_monitor.erl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/rabbit_disk_monitor.erl b/src/rabbit_disk_monitor.erl index ab443780..17d8e2f2 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({not_found, Str}) + end; + _ -> exit({not_found, Str}) + end. parse_free_win32(CommandResult) -> LastLine = lists:last(string:tokens(CommandResult, "\r\n")), -- cgit v1.2.1 From ae0e47d4a8fe4925bff698131e74d140e1a8576a Mon Sep 17 00:00:00 2001 From: Simon MacMullen Date: Wed, 9 Apr 2014 14:01:04 +0100 Subject: Delayed restart of the disk monitor. --- src/rabbit_alarm.erl | 3 ++- src/rabbit_restartable_sup.erl | 19 ++++++++++++------- src/rabbit_sup.erl | 15 +++++++++++---- 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) -> -- cgit v1.2.1 From 6dfd4d2964faebda2668312cc4b3c43f3945618c Mon Sep 17 00:00:00 2001 From: Simon MacMullen Date: Wed, 9 Apr 2014 16:44:46 +0100 Subject: More unique atom --- src/rabbit_disk_monitor.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rabbit_disk_monitor.erl b/src/rabbit_disk_monitor.erl index 17d8e2f2..fbf13a90 100644 --- a/src/rabbit_disk_monitor.erl +++ b/src/rabbit_disk_monitor.erl @@ -192,9 +192,9 @@ parse_free_unix(Str) -> case string:tokens(Str, "\n") of [_, S | _] -> case string:tokens(S, " \t") of [_, _, _, Free | _] -> list_to_integer(Free) * 1024; - _ -> exit({not_found, Str}) + _ -> exit({unparseable, Str}) end; - _ -> exit({not_found, Str}) + _ -> exit({unparseable, Str}) end. parse_free_win32(CommandResult) -> -- cgit v1.2.1