diff options
author | Matthias Radestock <matthias@lshift.net> | 2009-01-07 19:31:41 +0000 |
---|---|---|
committer | Matthias Radestock <matthias@lshift.net> | 2009-01-07 19:31:41 +0000 |
commit | a48c3dd7d69115f780b7efc81aebf7ff6f77f1fc (patch) | |
tree | 91e7c51fd0cc2a8f5e7a78f96da481a295d41d6c | |
parent | cd69f807e6546b115c92728ef38ced6a1978577f (diff) | |
download | rabbitmq-server-a48c3dd7d69115f780b7efc81aebf7ff6f77f1fc.tar.gz |
minor refactoring
export {start,stop}_applications from rabbit_misc, so that other code,
notably the Erlang client, can call them.
-rw-r--r-- | src/rabbit.erl | 32 | ||||
-rw-r--r-- | src/rabbit_misc.erl | 32 |
2 files changed, 34 insertions, 30 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl index 41064c77..30b8c394 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -75,14 +75,14 @@ start() -> try ok = ensure_working_log_handlers(), ok = rabbit_mnesia:ensure_mnesia_dir(), - ok = start_applications(?APPS) + ok = rabbit_misc:start_applications(?APPS) after %%give the error loggers some time to catch up timer:sleep(100) end. stop() -> - ok = stop_applications(?APPS). + ok = rabbit_misc:stop_applications(?APPS). stop_and_halt() -> spawn(fun () -> @@ -109,34 +109,6 @@ rotate_logs(BinarySuffix) -> %%-------------------------------------------------------------------- -manage_applications(Iterate, Do, Undo, SkipError, ErrorTag, Apps) -> - Iterate(fun (App, Acc) -> - case Do(App) of - ok -> [App | Acc]; - {error, {SkipError, _}} -> Acc; - {error, Reason} -> - lists:foreach(Undo, Acc), - throw({error, {ErrorTag, App, Reason}}) - end - end, [], Apps), - ok. - -start_applications(Apps) -> - manage_applications(fun lists:foldl/3, - fun application:start/1, - fun application:stop/1, - already_started, - cannot_start_application, - Apps). - -stop_applications(Apps) -> - manage_applications(fun lists:foldr/3, - fun application:stop/1, - fun application:start/1, - not_started, - cannot_stop_application, - Apps). - start(normal, []) -> {ok, SupPid} = rabbit_sup:start_link(), diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 973e163b..85db50d7 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -50,6 +50,7 @@ -export([dirty_read_all/1, dirty_foreach_key/2, dirty_dump_log/1]). -export([append_file/2, ensure_parent_dirs_exist/1]). -export([format_stderr/2]). +-export([start_applications/1, stop_applications/1]). -import(mnesia). -import(lists). @@ -108,6 +109,8 @@ -spec(append_file/2 :: (string(), string()) -> 'ok' | {'error', any()}). -spec(ensure_parent_dirs_exist/1 :: (string()) -> 'ok'). -spec(format_stderr/2 :: (string(), [any()]) -> 'true'). +-spec(start_applications/1 :: ([atom()]) -> 'ok'). +-spec(stop_applications/1 :: ([atom()]) -> 'ok'). -endif. @@ -398,3 +401,32 @@ format_stderr(Fmt, Args) -> Port = open_port({fd, 0, 2}, [out]), port_command(Port, io_lib:format(Fmt, Args)), port_close(Port). + +manage_applications(Iterate, Do, Undo, SkipError, ErrorTag, Apps) -> + Iterate(fun (App, Acc) -> + case Do(App) of + ok -> [App | Acc]; + {error, {SkipError, _}} -> Acc; + {error, Reason} -> + lists:foreach(Undo, Acc), + throw({error, {ErrorTag, App, Reason}}) + end + end, [], Apps), + ok. + +start_applications(Apps) -> + manage_applications(fun lists:foldl/3, + fun application:start/1, + fun application:stop/1, + already_started, + cannot_start_application, + Apps). + +stop_applications(Apps) -> + manage_applications(fun lists:foldr/3, + fun application:stop/1, + fun application:start/1, + not_started, + cannot_stop_application, + Apps). + |