tags:

views:

130

answers:

1

What is the appropriate place for performing inets:start() ?

  1. in `applicationname_app' module?
  2. in applicationname_sup supervisor module?
  3. in a child process hanging from the supervisor?\
  4. someplace else?

(I am still struggling with inets:httpd)

Note: the answer cannot be to the tune " use a boot file " , please.

+3  A: 

inets is a "stand-alone" Erlang application; inets:start() is just an alias to application: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 with application: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 :-P

If 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:

ensure_app_started(App) ->
  case application:started(App) of
    ok -> ok;
    {error, already_started} -> ok;
    Error -> Error
  end.
Zed
@zed: thanks again. Let's say I were to package my app as an `application`, how would I start it from the command line? (I am mostly doing daemons).
jldupont
@zed: i.e. `erl -sname daemon -detached -boot start_sasl -s daemon_app start`? Show me an example, please.
jldupont
Add SASL to the application dependencies as well. Make a release file, and then a boot script. Then -boot my_boot.
Zed
@Zed: I finally decided to restructure and go OTP all the way (almost- no boot files!). I went for a proper `.app` based structure. Thanks for your time.
jldupont
Why no boot files ?
Zed