tags:

views:

93

answers:

2

I am in the process of writing my first erlang application and I don't understand yet some parts of the erlang ecosystem and how things should be done in it. For example if my app depends on some other apps what is the way to start and stop them at once ? Actually, I've figured out how to start, just put application:start/1 calls in the start/2 function of the application module:

-module(myapp).
-behaviour(application).

-export([start/0, start/2, stop/1]).

start(_Type, _StartArgs) ->
    ok = application:start(ssl),
    ok = application:start(inets),
    ok = application:start(log4erl),
    myapp_sup:start_link().

stop(_State) ->
    ok.

But when I tried to put corresponding application:stop/1 calls into the myapp:stop/1 function and called from the erlang shell application:stop(myapp) the later just stopped responding to any command.

+3  A: 

Reading from the official doc:

stop/1 is called after the application has been stopped and should do any necessary cleaning up. Note that the actual stopping of the application, that is the shutdown of the supervision tree, is handled automatically as described in Starting and Stopping Applications.

More information here and there.

Usually, when I have some dependent applications, I use a .app resource file, where I list all applications that need to be started (or loaded) by my application to work correctly.

Roberto Aloi
+2  A: 

I suggest checking out erlware.org and using the tools sinan and faxien for your Erlang development. If you stick to strict OTP compliance for your apps and releases it not only makes development easier and less error prone but it makes sharing your apps much much easier. The upcoming book http://www.manning.com/logan/ answers much more, you can read an early copy in pdf form.

Putting starts and stops "randomly" in your modules is a bad idea.

Tristan Sloughter