What is the appropriate place for performing inets:start()
?
- in `applicationname_app' module?
- in
applicationname_sup
supervisor module? - in a child process hanging from the supervisor?\
- someplace else?
(I am still struggling with inets:httpd
)
Note: the answer cannot be to the tune " use a boot file " , please.
In 2019, we use
rebar3
to create an application and manage its dependencies. For dependencies that need to be downloaded, you add them torebar.config
, andrebar3
will download the dependencies. For example, if you addhackney
(an http client) to rebar.config:Then do:
rebar3
will downloadhackney
and compile all the files in theapplication
.To make sure that all your dependencies get started before your app, you add the names of the dependencies to:
For instance,
The actual .app file gets created here:
To start your app in the shell along with all its dependencies, you do:
The
inets
application comes with erlang, so it doesn't need to be downloaded, so you don't specify inets as a dependency in rebar.config (you'll get an error when you$ rebar3 compile
). You still need to specify inets as a dependency in yourapplication
in the file:But
rebar3
itself usesinets
(to download your dependencies), so even if you didn't specifyinets
as a dependency in your application,inets
would still get started before your app. You can test that by not specifyinginets
as a dependency in yourapplication
, then doing:But, don't rely on that and DO specify
inets
as a dependency in your application.inets is a "stand-alone" Erlang application;
inets:start()
is just an alias toapplication:start(inets)
. I guess the answer pretty much depends on how you maintain your code.If your code is packaged as an application, your .app file should list
inets
as required to be started before yours (see the applications tag). Starting your applicaion withapplication:start(my_app).
will now ensure that inets is also started. Consequence: if you make a boot file, it will also start inets for you :-PIf you are keen on not using applications, I guess the choice depends on how your code works. If you will always need inets to be started, it is better started by any of your supervisors. If it is rarely needed, you can always make sure it is started with something like:
If your code is packaged as an application, list
inets
in the application resource file:Then you can start the application using
application:ensure_all_started(flamingo)
. This ensures that inets is started automatically for you (i.e. there is no need to explicitly callinets:start()
).For example (assuming the *.app file and *.beam files and are in
ebin/
):