diff options
author | Tony Garnock-Jones <tonyg@kcbbs.gen.nz> | 2009-02-13 00:41:58 +0000 |
---|---|---|
committer | Tony Garnock-Jones <tonyg@kcbbs.gen.nz> | 2009-02-13 00:41:58 +0000 |
commit | 0bd4d4b762e6f2af5a35a858a71c1bec69ed13fe (patch) | |
tree | 5f55512ad285306c8d6fc2d2771174780df83e70 /src/rabbit_misc.erl | |
parent | e7abe601e1807c11bcec0261672eb23abbd7a9c9 (diff) | |
parent | eb9a12d44cb2ff6f95da572c838cfa304e819241 (diff) | |
download | rabbitmq-server-0bd4d4b762e6f2af5a35a858a71c1bec69ed13fe.tar.gz |
merge bug20348 into default
Diffstat (limited to 'src/rabbit_misc.erl')
-rw-r--r-- | src/rabbit_misc.erl | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 053bde54..5d176f8f 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -49,6 +49,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). @@ -104,6 +105,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. @@ -230,7 +233,7 @@ filter_exit_map(F, L) -> with_user(Username, Thunk) -> fun () -> - case mnesia:read({user, Username}) of + case mnesia:read({rabbit_user, Username}) of [] -> mnesia:abort({no_such_user, Username}); [_U] -> @@ -240,7 +243,7 @@ with_user(Username, Thunk) -> with_vhost(VHostPath, Thunk) -> fun () -> - case mnesia:read({vhost, VHostPath}) of + case mnesia:read({rabbit_vhost, VHostPath}) of [] -> mnesia:abort({no_such_vhost, VHostPath}); [_V] -> @@ -358,3 +361,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). + |