[erlang-questions] Debugging apps with dependencies

Juan Jose Comellas juanjo@REDACTED
Wed May 2 13:55:20 CEST 2012


Sorry, there was a small typo in my previous copy. Here's the correct
version that also includes the function that stops the module and its
dependencies:


-define(APP, ?MODULE).

%% @doc Start the application and all its dependencies.
-spec start() -> ok.
start() ->
    start_deps(?APP).

-spec start_deps(App :: atom()) -> ok.
start_deps(App) ->
    application:load(App),
    {ok, Deps} = application:get_key(App, applications),
    lists:foreach(fun start_deps/1, Deps),
    start_app(App).

-spec start_app(App :: atom()) -> ok.
start_app(App) ->
    case application:start(App) of
        {error, {already_started, _}} -> ok;
        ok                            -> ok
    end.


%% @doc Stop the application and all its dependencies.
-spec stop() -> ok.
stop() ->
    stop_deps(?APP).

-spec stop_deps(App :: atom()) -> ok.
stop_deps(App) ->
    stop_app(App),
    {ok, Deps} = application:get_key(App, applications),
    lists:foreach(fun stop_deps/1, lists:reverse(Deps)).

-spec stop_app(App :: atom()) -> ok.
stop_app(kernel) ->
    ok;
stop_app(stdlib) ->
    ok;
stop_app(App) ->
    case application:stop(App) of
        {error, {not_started, _}} -> ok;
        ok                        -> ok
    end.



On Wed, May 2, 2012 at 8:42 AM, Juan Jose Comellas <juanjo@REDACTED>wrote:

> BTW, I use a variant of what you showed that also starts dependencies
> recursively. I normally create a module with the name of the project and
> export the following functions to start it. That's what I use while testing.
>
> -define(APP, ?MODULE).
>
> %% @doc Start the application and all its dependencies.
> -spec start() -> ok.
> start() ->
>     start_deps(?APP),
>     application:start(?APP).
>
> -spec start_deps(App :: atom()) -> ok.
> start_deps(App) ->
>     application:load(App),
>     {ok, Deps} = application:get_key(App, applications),
>     lists:foreach(fun start_deps/1, Deps),
>     start_app(App).
>
> -spec start_app(App :: atom()) -> ok.
> start_app(App) ->
>     case application:start(App) of
>         {error, {already_started, _}} -> ok;
>         ok                            -> ok
>     end.
>
>
> Juanjo
>
>
> On Mon, Apr 30, 2012 at 3:39 PM, Bob Ippolito <bob@REDACTED> wrote:
>
>> I haven't discovered a great workflow for developing with releases
>> either, but you can start dependencies in a slightly cleaner way by looking
>> at the app file:
>>
>> This would go in some module with the same name as the application, and
>> you would call it with "erl ... -s modname"
>>
>> -export([start/0]).
>>
>> start() -> start(?MODULE).
>>
>> start(App) ->
>>     application:load(App),
>>     {ok, Deps} = application:get_key(App, applications),
>>     lists:foreach(fun start_app/1, Deps),
>>     application:start(App).
>>
>> start_app(App) ->
>>     case application:start(App) of
>>         {error, {already_started, _}} -> ok;
>>         ok -> ok
>>     end.
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120502/ceb3d022/attachment.htm>


More information about the erlang-questions mailing list