Dmitrii Dushkin
Dmitrii Dushkin

Reputation: 3280

Erlang: how can I automatically start all necessary applications to app?

I have necessary applications in st_db.app file like this:

{application, st_db,
 [
  {description, ""},
  {vsn, "1.0.0"},
  {registered, []},
  {modules, [st_db_app, st_db_sup, st_db]},
  {applications, [
                  kernel,
                  stdlib,
          sasl,
          crypto,
          ibrowse,
          couchbeam
                 ]},
  {mod, { st_db_app, []}},
  {env, []}
 ]}.

I need to start them (crypto, sasl, etc.) automatically to run and debug the main app. The only solution I found is to start erl with such params:

erl -pa ./ebin -pa ./deps/*/ebin -boot start_sasl -s couchbeam -s crypto -s ibrowse 

Is that the only way?

PS: btw couchbeam doesn't starts on node. It just start the couchbeam's supervisor, so I have to run in shell it manually

=PROGRESS REPORT==== 15-Jun-2011::10:22:43 ===
          supervisor: {local,couchbeam_sup}
             started: [{pid,<0.62.0>},
                       {name,couchbeam},
                       {mfargs,{couchbeam,start_link,[]}},
                       {restart_type,permanent},
                       {shutdown,2000},
                       {child_type,worker}]

2> application:start(couchbeam).
ok
3> 
=PROGRESS REPORT==== 15-Jun-2011::10:23:25 ===
          supervisor: {local,couchbeam_sup}
             started: [{pid,<0.69.0>},
                       {name,couchbeam},
                       {mfargs,{couchbeam,start_link,[]}},
                       {restart_type,permanent},
                       {shutdown,2000},
                       {child_type,worker}]

=PROGRESS REPORT==== 15-Jun-2011::10:23:25 ===
         application: couchbeam
          started_at: nonode@nohost

Is there way to fix it?

Upvotes: 9

Views: 2829

Answers (4)

Lukas
Lukas

Reputation: 5327

You can either issue a series of -eval "application:start(coucnbeam)" commands to erl, or do it the proper OTP way and use reltool to generate a new boot file for you.

See info on reltool, also rebar does an excellent job at doing much of the heavy lifting for you so you might want to look into rebar3.

There is also a great chapter, from LYSE, on making releases.

Upvotes: 5

Pouriya
Pouriya

Reputation: 1626

In your application callback module, just write:

-module(st_db_app).
-behaviour(application).
-export([start/2, stop/1]).

start(_StartType, _StartArg) ->
    %% Get application name
    {ok, AppName} = application:get_application(),
    %% Start all dependencies that are not yet started for application name
    {ok, _StartedApps} = application:ensure_all_started(AppName),
    %% start application's root supervisor or do other initialization here
    %% and return root supervisor's pid.

Upvotes: 2

Girdhar Sojitra
Girdhar Sojitra

Reputation: 678

There is a way to start all dependent applications. Please go through application:ensure_all_started API at http://erlang.org/doc/apps/kernel/application.html#ensure_all_started-1

Upvotes: 1

toddg
toddg

Reputation: 351

If you are just messing around in the console and want to not have to type in all these 'application:start(...).' lines, just put these things in the .erlang file in your current working directory. Here's an example for what I'm working on right now:

$ cat .erlang 
application:start(crypto).
application:start(public_key).
application:start(ssl).
application:start(ibrowse).
application:start(foo).

This starts all my dependencies, and then the app I'm working on right now, foo.


If you want to generate a reltool release with rebar, this link might help:

When to use erlang application:start or included_applications and a supervisor?

Specifically, this gist:

https://gist.github.com/3728780

-Todd

Upvotes: 5

Related Questions