How to run erlang (rebar build) application
Asked Answered
I

4

17

I am new to Erlang world and currently can't figure out how to start my dummy erlang application. Probably, I am just missing something... So, I created an application with rebar (rebar create-app appid=dummys).

Currently I have

  • rebar.config
  • src/dummys.app.src
  • src/dummys_app.erl
  • src/dummys_sup.erl

I have found that in order to run an application during a development it is better to create an additional start method which should call application:start(module).

I added some basic logging to my start methods..

start() ->
    error_logger:info_msg("Starting app(dev)..~n"),
    application:start(dummys_app).

start(_StartType, _StartArgs) ->
    error_logger:info_msg("Starting app..~n"),
    dummys_sup:start_link().

If I try

erl -noshell -pa ebin -s application start dummys
erl -noshell -pa ebin -s application start dummys_app

there are no output..

If I try

erl -noshell -pa ebin -s dummys start

erl crashes with an error..

If I try

erl -noshell -pa ebin -s dummys_app start

it outputs just "Starting app(dev).." and that's all. But I also expect to see "Starting app.."

What I am missing or doing wrong??

=============

And another question: How to add a new module to my dummy application correctly? For example I have an additional module called "*dummys_cool*" which has a "start" method. How to tell my application to run that "dummys_cool#start" method?

Thank you!

Indoeuropean answered 21/5, 2013 at 17:14 Comment(0)
K
15

For quick development, if you just want to ensure your appliction can start, start a shell, then start the application:

erl -pa ebin
1> dummys_app:start().

That will give you a clean indication of what is wrong and right without the shell bombing out after.

Since you're making an application to run, rather than just a library to share, you'll want to make a release. Rebar can get you most of the way there:

mkdir rel
cd rel
rebar create-node nodeid=dummysnode

After you've compiled your application, you can create a release:

rebar generate

This will build a portable release which includes all the required libraries and even the erlang runtime system. This is put by default in the rel/ directory; in your case rel/dummys.

Within that directory there will be a control script that you can use to start, stop, and attach to the application:

rel/dummys/bin/dummys start
rel/dummys/bin/dummys stop
rel/dummys/bin/dummys start
rel/dummys/bin/dummys attach
Ketose answered 23/5, 2013 at 17:11 Comment(2)
Thank you for explanation! Finally, I figured out how it works all together.Indoeuropean
This is solid advice. It appears that the semantics has changed a bit with rebar3. The documentation is great (rebar3.org/docs/releases). Specifically check out {dev_mode, true}.Spiller
S
2

Have a look at your dummys.app.src file. The meaning of all the directives is explained in the 'app' manpage, but the one I suspect is missing here is mod, which indicates the name of your application callback module. So make sure that this line is present:

{mod, {dummys_app, []}}

The empty list in there will be passed as the StartArgs argument to dummys_app:start/2.


To make a new module start along with your application, add it to the supervision tree in dummys_sup:init. This function should look something like:
init(_) ->
    {ok, {{one_for_one, 10, 10},
         [{dummys_cool, {dummys_cool, start_link, []},
           permanent, brutal_kill, worker, [dummys_cool]}]}.

This is described in the 'supervisor' manpage, but basically this means that on startup, this supervisor will start one child process. dummys_cool:start_link() will be called, and that function is expected to spawn a new process, link to it, and return its process id. If you need more processes, just add more child specifications to the list.

Screenplay answered 21/5, 2013 at 17:50 Comment(1)
Thank you @legoscia. I've checked my app.src file and mod is there {application, dummys, [ {description, "dummy application"}, {vsn, "1"}, {registered, []}, {applications, [ kernel, stdlib ]}, {mod, { dummys_app, []}}, {env, []} ]}.Indoeuropean
M
1
erl -noshell -pa ebin -s application start dummys

The code above will not work because application:start([dummys]) will be called.

You can take a reference of the Erlang documentation for details.

For your case,

erl -noshell -pa ebin -s dummys
Maidenhead answered 24/10, 2014 at 19:21 Comment(0)
G
1

I ran into this problem, and this was the first answer on Google.

If you are using rebar3, the standard configuration will have a shell command that compiles your project and opens a shell:

$ rebar3 shell
===> Analyzing applications...
===> Compiling myapp
Erlang/OTP 21 [erts-10.2.4] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1]

Eshell V10.2.4  (abort with ^G)
1> ===> Booted myapp
Gemina answered 22/10, 2020 at 23:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.