aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/src
diff options
context:
space:
mode:
authorFredrik Gustafsson <[email protected]>2013-08-21 11:06:01 +0200
committerFredrik Gustafsson <[email protected]>2013-08-21 11:06:01 +0200
commit3cc53db7071988cd8dad0d67c85b3e08a7c6818e (patch)
tree273584caa1d8004737cf04a11a4fc6059118634d /lib/kernel/src
parent5960967a506c2eeadb3cbf66a1e21fff5000f08b (diff)
parentaf48b10b5d8628ecec95643dfec297b30d3b7810 (diff)
downloadotp-3cc53db7071988cd8dad0d67c85b3e08a7c6818e.tar.gz
otp-3cc53db7071988cd8dad0d67c85b3e08a7c6818e.tar.bz2
otp-3cc53db7071988cd8dad0d67c85b3e08a7c6818e.zip
Merge branch 'fh/start-all/OTP-11250' into maint
* fh/start-all/OTP-11250: kernel: fix documentation regarding ensure_all_started endtag Updated primary bootstrap Add application:ensure_all_started/1-2
Diffstat (limited to 'lib/kernel/src')
-rw-r--r--lib/kernel/src/application.erl43
1 files changed, 42 insertions, 1 deletions
diff --git a/lib/kernel/src/application.erl b/lib/kernel/src/application.erl
index 5dd6b73857..4e8ba1b78a 100644
--- a/lib/kernel/src/application.erl
+++ b/lib/kernel/src/application.erl
@@ -18,7 +18,8 @@
%%
-module(application).
--export([start/1, start/2, start_boot/1, start_boot/2, stop/1,
+-export([ensure_all_started/1, ensure_all_started/2, start/1, start/2,
+ start_boot/1, start_boot/2, stop/1,
load/1, load/2, unload/1, takeover/2,
which_applications/0, which_applications/1,
loaded_applications/0, permit/2]).
@@ -113,6 +114,46 @@ load1(Application, DistNodes) ->
unload(Application) ->
application_controller:unload_application(Application).
+
+-spec ensure_all_started(Application) -> {'ok', Started} | {'error', Reason} when
+ Application :: atom(),
+ Started :: [atom()],
+ Reason :: term().
+ensure_all_started(Application) ->
+ ensure_all_started(Application, temporary).
+
+-spec ensure_all_started(Application, Type) -> {'ok', Started} | {'error', Reason} when
+ Application :: atom(),
+ Type :: restart_type(),
+ Started :: [atom()],
+ Reason :: term().
+ensure_all_started(Application, Type) ->
+ case ensure_all_started(Application, Type, []) of
+ {ok, Started} ->
+ {ok, lists:reverse(Started)};
+ {error, Reason, Started} ->
+ [stop(App) || App <- Started],
+ {error, Reason}
+ end.
+
+ensure_all_started(Application, Type, Started) ->
+ case start(Application, Type) of
+ ok ->
+ {ok, [Application | Started]};
+ {error, {already_started, Application}} ->
+ {ok, Started};
+ {error, {not_started, Dependency}} ->
+ case ensure_all_started(Dependency, Type, Started) of
+ {ok, NewStarted} ->
+ ensure_all_started(Application, Type, NewStarted);
+ Error ->
+ Error
+ end;
+ {error, Reason} ->
+ {error, {Application, Reason}, Started}
+ end.
+
+
-spec start(Application) -> 'ok' | {'error', Reason} when
Application :: atom(),
Reason :: term().