How to get an Erlang app to run at starting rebar3
Asked Answered
S

2

6

I can start the application manually from the rebar3 shell by doing application:start(lager) followed by application:start(myapp). I'd like this to happen without having to type it out, for example by executing a shell script that tells rebar3 to run those commands. Is this possible?

Spelldown answered 24/10, 2016 at 6:14 Comment(0)
F
13

Assuming that you want to run the application during development you can do it like this:

  • either you specify the apps at commandline like this: rebar3 shell --apps lager myapp

  • or you specify in rebar.config {shell, [{apps, [lager, myapp]}]}. and then simply run it with rebar3 shell. For example I have an application named tron and have the following line in my rebar.config: {shell, [{apps, [kernel,stdlib,cowboy,lager,tron]}]}. Now when I run rebar3 shell my erlang application is started together with all dependencies.

For more information about rebar3 shell and how you can use it, see this awesome blogpost from the creator, or the official documentation here.

But as you probably know, the proper way to run the application for deployment is to first build a release and then simply run it as an executable (It was a while since I built a release but back then it was harder than it sounds, unfortunately! Although it looks like rebar3 have perhaps made it abit easier: rebar3 releases.

Frier answered 30/10, 2016 at 6:58 Comment(1)
thanks for the good answer - it was surprisingly difficult to get an answer to this seemingly simple question.Spelldown
I
-1

I would like to add, that you can also specify apps to be booted on startup inside the myapp.app.src file.

...
{applications,
   [kernel,
    stdlib,
    anotherapp
   ]},
...
Impulsion answered 27/7, 2017 at 21:17 Comment(1)
$ rebar3 shell doesn't start the apps listed in the applications tuple when I try it--even though the rebar3 docs seem to say that that is the way to start dependent apps. :(Spense

© 2022 - 2024 — McMap. All rights reserved.