|
19 | 19 | -behaviour(application).
|
20 | 20 |
|
21 | 21 | -export([start/0, boot/0, stop/0,
|
22 |
| - stop_and_halt/0, await_startup/0, status/0, is_running/0, alarms/0, |
| 22 | + stop_and_halt/0, await_startup/0, await_startup/1, |
| 23 | + status/0, is_running/0, alarms/0, |
23 | 24 | is_running/1, environment/0, rotate_logs/0, force_event_refresh/1,
|
24 | 25 | start_fhc/0]).
|
25 | 26 | -export([start/2, stop/1, prep_stop/1]).
|
26 |
| --export([start_apps/1, stop_apps/1]). |
| 27 | +-export([start_apps/1, start_apps/2, stop_apps/1]). |
27 | 28 | -export([log_locations/0, config_files/0, decrypt_config/2]). %% for testing and mgmt-agent
|
28 | 29 |
|
29 | 30 | -ifdef(TEST).
|
|
266 | 267 | -spec boot_delegate() -> 'ok'.
|
267 | 268 | -spec recover() -> 'ok'.
|
268 | 269 | -spec start_apps([app_name()]) -> 'ok'.
|
| 270 | +-spec start_apps([app_name()], |
| 271 | + #{app_name() => permanent|transient|temporary}) -> 'ok'. |
269 | 272 | -spec stop_apps([app_name()]) -> 'ok'.
|
270 | 273 |
|
271 | 274 | %%----------------------------------------------------------------------------
|
@@ -467,7 +470,7 @@ stop() ->
|
467 | 470 | undefined -> ok;
|
468 | 471 | _ ->
|
469 | 472 | rabbit_log:info("RabbitMQ hasn't finished starting yet. Waiting for startup to finish before stopping..."),
|
470 |
| - wait_for_boot_to_finish() |
| 473 | + ok = wait_for_boot_to_finish(node()) |
471 | 474 | end,
|
472 | 475 | rabbit_log:info("RabbitMQ is asked to stop...~n", []),
|
473 | 476 | Apps = ?APPS ++ rabbit_plugins:active(),
|
@@ -502,6 +505,9 @@ stop_and_halt() ->
|
502 | 505 | ok.
|
503 | 506 |
|
504 | 507 | start_apps(Apps) ->
|
| 508 | + start_apps(Apps, #{}). |
| 509 | + |
| 510 | +start_apps(Apps, AppModes) -> |
505 | 511 | app_utils:load_applications(Apps),
|
506 | 512 |
|
507 | 513 | ConfigEntryDecoder = case application:get_env(rabbit, config_entry_decoder) of
|
@@ -541,7 +547,8 @@ start_apps(Apps) ->
|
541 | 547 | true -> ok %% will run during start of rabbit app
|
542 | 548 | end,
|
543 | 549 | ok = app_utils:start_applications(OrderedApps,
|
544 |
| - handle_app_error(could_not_start)). |
| 550 | + handle_app_error(could_not_start), |
| 551 | + AppModes). |
545 | 552 |
|
546 | 553 | %% This function retrieves the correct IoDevice for requesting
|
547 | 554 | %% input. The problem with using the default IoDevice is that
|
@@ -637,32 +644,52 @@ handle_app_error(Term) ->
|
637 | 644 | end.
|
638 | 645 |
|
639 | 646 | await_startup() ->
|
640 |
| - case is_booting() of |
641 |
| - true -> wait_for_boot_to_finish(); |
| 647 | + await_startup(node()). |
| 648 | + |
| 649 | +await_startup(Node) -> |
| 650 | + case is_booting(Node) of |
| 651 | + true -> wait_for_boot_to_finish(Node); |
642 | 652 | false ->
|
643 |
| - case is_running() of |
| 653 | + case is_running(Node) of |
644 | 654 | true -> ok;
|
645 |
| - false -> wait_for_boot_to_start(), |
646 |
| - wait_for_boot_to_finish() |
| 655 | + false -> wait_for_boot_to_start(Node), |
| 656 | + wait_for_boot_to_finish(Node) |
647 | 657 | end
|
648 | 658 | end.
|
649 | 659 |
|
650 |
| -is_booting() -> |
651 |
| - whereis(rabbit_boot) /= undefined. |
| 660 | +is_booting(Node) -> |
| 661 | + case rpc:call(Node, erlang, whereis, [rabbit_boot]) of |
| 662 | + {badrpc, _} = Err -> Err; |
| 663 | + undefined -> false; |
| 664 | + P when is_pid(P) -> true |
| 665 | + end. |
652 | 666 |
|
653 |
| -wait_for_boot_to_start() -> |
654 |
| - case whereis(rabbit_boot) of |
655 |
| - undefined -> timer:sleep(100), |
656 |
| - wait_for_boot_to_start(); |
657 |
| - _ -> ok |
| 667 | +wait_for_boot_to_start(Node) -> |
| 668 | + case is_booting(Node) of |
| 669 | + false -> |
| 670 | + timer:sleep(100), |
| 671 | + wait_for_boot_to_start(Node); |
| 672 | + {badrpc, _} = Err -> |
| 673 | + Err; |
| 674 | + true -> |
| 675 | + ok |
658 | 676 | end.
|
659 | 677 |
|
660 |
| -wait_for_boot_to_finish() -> |
661 |
| - case whereis(rabbit_boot) of |
662 |
| - undefined -> true = is_running(), |
663 |
| - ok; |
664 |
| - _ -> timer:sleep(100), |
665 |
| - wait_for_boot_to_finish() |
| 678 | +wait_for_boot_to_finish(Node) -> |
| 679 | + case is_booting(Node) of |
| 680 | + false -> |
| 681 | + %% We don't want badrpc error to be interpreted as false, |
| 682 | + %% so we don't call rabbit:is_running(Node) |
| 683 | + case rpc:call(Node, rabbit, is_running, []) of |
| 684 | + true -> ok; |
| 685 | + false -> {error, rabbit_is_not_running}; |
| 686 | + {badrpc, _} = Err -> Err |
| 687 | + end; |
| 688 | + {badrpc, _} = Err -> |
| 689 | + Err; |
| 690 | + true -> |
| 691 | + timer:sleep(100), |
| 692 | + wait_for_boot_to_finish(Node) |
666 | 693 | end.
|
667 | 694 |
|
668 | 695 | status() ->
|
|
0 commit comments