diff options
| author | Tony Garnock-Jones <tonyg@lshift.net> | 2009-12-14 22:55:00 +0000 |
|---|---|---|
| committer | Tony Garnock-Jones <tonyg@lshift.net> | 2009-12-14 22:55:00 +0000 |
| commit | b44cdb699d8b89b978f21d76c01b64411877b3db (patch) | |
| tree | 809ee68765643fd87c1c938dba1eb59cb2b6104b | |
| parent | babf9d28807d3b5aad8e9f2ad609f5e6e5c9d64f (diff) | |
| download | rabbitmq-server-git-b44cdb699d8b89b978f21d76c01b64411877b3db.tar.gz | |
Split up and tweak startup order.
| -rw-r--r-- | src/rabbit.erl | 81 | ||||
| -rw-r--r-- | src/rabbit_error_logger.erl | 6 | ||||
| -rw-r--r-- | src/rabbit_sup.erl | 11 |
3 files changed, 48 insertions, 50 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl index a78806fda6..3665c4c19d 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -41,31 +41,43 @@ %%--------------------------------------------------------------------------- %% Boot steps. --export([boot_database/0, boot_core_processes/0, boot_recovery/0, - boot_persister/0, boot_guid_generator/0, - boot_builtin_applications/0, boot_tcp_listeners/0, +-export([boot_core_processes/0, + boot_recovery/0, + boot_tcp_listeners/0, boot_ssl_listeners/0]). --rabbit_boot_step({database, [{mfa, {?MODULE, boot_database, []}}]}). +-rabbit_boot_step({database, [{mfa, {rabbit_mnesia, init, []}}]}). -rabbit_boot_step({core_processes, [{description, "core processes"}, {mfa, {?MODULE, boot_core_processes, []}}, - {post, database}]}). + {post, database}, + {pre, core_initialized}]}). +-rabbit_boot_step({core_initialized, [{description, "core initialized"}]}). + -rabbit_boot_step({recovery, [{mfa, {?MODULE, boot_recovery, []}}, - {post, core_processes}]}). --rabbit_boot_step({persister, [{mfa, {?MODULE, boot_persister, []}}, + {post, core_initialized}]}). +-rabbit_boot_step({persister, [{mfa, {rabbit_sup, start_child, [rabbit_persister]}}, {post, recovery}]}). -rabbit_boot_step({guid_generator, [{description, "guid generator"}, - {mfa, {?MODULE, boot_guid_generator, []}}, - {post, persister}]}). --rabbit_boot_step({builtin_applications, [{description, "builtin applications"}, - {mfa, {?MODULE, boot_builtin_applications, []}}, - {post, guid_generator}]}). + {mfa, {rabbit_sup, start_child, [rabbit_guid]}}, + {post, persister}, + {pre, routing_ready}]}). +-rabbit_boot_step({routing_ready, [{description, "message delivery logic ready"}]}). + +-rabbit_boot_step({log_relay, [{description, "error log relay"}, + {mfa, {rabbit_error_logger, boot, []}}, + {post, routing_ready}]}). + -rabbit_boot_step({tcp_listeners, [{description, "TCP listeners"}, {mfa, {?MODULE, boot_tcp_listeners, []}}, - {post, builtin_applications}]}). + {post, log_relay}, + {pre, networking_listening}]}). -rabbit_boot_step({ssl_listeners, [{description, "SSL listeners"}, {mfa, {?MODULE, boot_ssl_listeners, []}}, - {post, tcp_listeners}]}). + {post, tcp_listeners}, + {pre, networking_listening}]}). + +-rabbit_boot_step({networking_listening, [{description, "network listeners available"}]}). + %%--------------------------------------------------------------------------- -import(application). @@ -177,9 +189,9 @@ run_boot_step({StepName, Attributes}) -> end, case [MFA || {mfa, MFA} <- Attributes] of [] -> - io:format("progress: ~s~n", [Description]); + io:format("progress -- ~s~n", [Description]); MFAs -> - io:format("starting: ~-20s ...", [Description]), + io:format("starting ~-20s ...", [Description]), [case catch apply(M,F,A) of {'EXIT', Reason} -> boot_error("FAILED~nReason: ~p~n", [Reason]); ok -> ok @@ -258,11 +270,8 @@ add_boot_step_dep(G, RunsSecond, RunsFirst) -> %%--------------------------------------------------------------------------- -boot_database() -> - ok = rabbit_mnesia:init(). - boot_core_processes() -> - ok = start_child(rabbit_log), + ok = rabbit_sup:start_child(rabbit_log), ok = rabbit_hooks:start(), ok = rabbit_binary_generator:check_empty_content_body_frame_size(), @@ -274,30 +283,19 @@ boot_core_processes() -> true -> ok; false -> - start_child(vm_memory_monitor, [MemoryWatermark]) + rabbit_sup:start_child(vm_memory_monitor, [MemoryWatermark]) end, ok = rabbit_amqqueue:start(), - ok = start_child(rabbit_router), - ok = start_child(rabbit_node_monitor). + ok = rabbit_sup:start_child(rabbit_router), + ok = rabbit_sup:start_child(rabbit_node_monitor). boot_recovery() -> ok = maybe_insert_default_data(), ok = rabbit_exchange:recover(), ok = rabbit_amqqueue:recover(). -boot_persister() -> - ok = start_child(rabbit_persister). - -boot_guid_generator() -> - ok = start_child(rabbit_guid). - -boot_builtin_applications() -> - {ok, DefaultVHost} = application:get_env(default_vhost), - ok = error_logger:add_report_handler(rabbit_error_logger, [DefaultVHost]), - ok = start_builtin_amq_applications(). - boot_tcp_listeners() -> ok = rabbit_networking:start(), {ok, TcpListeners} = application:get_env(tcp_listeners), @@ -376,15 +374,6 @@ print_banner() -> lists:foreach(fun ({K, V}) -> io:format(Format, [K, V]) end, Settings), io:nl(). -start_child(Mod) -> - start_child(Mod, []). - -start_child(Mod, Args) -> - {ok,_} = supervisor:start_child(rabbit_sup, - {Mod, {Mod, start_link, Args}, - transient, 100, worker, [Mod]}), - ok. - ensure_working_log_handlers() -> Handlers = gen_event:which_handlers(error_logger), ok = ensure_working_log_handler(error_logger_file_h, @@ -442,12 +431,6 @@ insert_default_data() -> DefaultReadPerm), ok. -start_builtin_amq_applications() -> - %%TODO: we may want to create a separate supervisor for these so - %%they don't bring down the entire app when they die and fail to - %%restart - ok. - rotate_logs(File, Suffix, Handler) -> rotate_logs(File, Suffix, Handler, Handler). diff --git a/src/rabbit_error_logger.erl b/src/rabbit_error_logger.erl index 297ed5aa9e..9651ae12ac 100644 --- a/src/rabbit_error_logger.erl +++ b/src/rabbit_error_logger.erl @@ -37,8 +37,14 @@ -behaviour(gen_event). +-export([boot/0]). + -export([init/1, terminate/2, code_change/3, handle_call/2, handle_event/2, handle_info/2]). +boot() -> + {ok, DefaultVHost} = application:get_env(default_vhost), + ok = error_logger:add_report_handler(?MODULE, [DefaultVHost]). + init([DefaultVHost]) -> #exchange{} = rabbit_exchange:declare( rabbit_misc:r(DefaultVHost, exchange, ?LOG_EXCH_NAME), diff --git a/src/rabbit_sup.erl b/src/rabbit_sup.erl index 730d7909bc..ef32544cc4 100644 --- a/src/rabbit_sup.erl +++ b/src/rabbit_sup.erl @@ -33,7 +33,7 @@ -behaviour(supervisor). --export([start_link/0]). +-export([start_link/0, start_child/1, start_child/2]). -export([init/1]). @@ -42,5 +42,14 @@ start_link() -> supervisor:start_link({local, ?SERVER}, ?MODULE, []). +start_child(Mod) -> + start_child(Mod, []). + +start_child(Mod, Args) -> + {ok, _} = supervisor:start_child(?SERVER, + {Mod, {Mod, start_link, Args}, + transient, 100, worker, [Mod]}), + ok. + init([]) -> {ok, {{one_for_one, 10, 10}, []}}. |
