[erlang-questions] supervised inets httpd process

Michael McDaniel erlangy@REDACTED
Mon Jun 28 01:33:36 CEST 2010


On Sun, Jun 27, 2010 at 02:37:48PM -0400, Ryan Zezeski wrote:
> Hi everyone.  I'm a newcomer to Erlang and have been reading through
> Programming Erlang for the past week.  There is an application I want to
> build to replace a legacy webapp in my workplace.  I will be replacing the
> bulk of this application with CouchDB/Erlang but I need a light web
> interface that wraps it to provide service to the legacy endpoints (URLs).
> 
> As a first cut, I plan on using the inets application with a custom httpd
> callback module to service the API.  I was curious, what is the best way to
> "embed" the httpd server in my application?  That is, I'm building an OTP
> compliant application, and I want the httpd server to sit under my
> supervisor.
> 
> My first attempt was to create a gen_server callback that called
> inets:start/1 and httpd:start/2 in the init/1 function, but I'm not sure
> this was the appropriate approach.  My second approach was to start inets in
> the supervisor callback init/1, and then pass the httpd startup to the
> supervisor config like so: {inets, start, [httpd,[{port,7777}, ...}.
> 
> I'm not sure either approach is the correct one.  What I *think* I want is a
> supervised process that contains the httpd server. I want this to be a
> "permanent" process that is restarted when an error occurs.  I peeked at the
> OTP source code a bit on github and noticed there is an httpd_manager which
> implements gen_server.  Would this be more appropriate?
> 
> Before anyone mentions them, I am aware of Yaws and Mochiweb, but for my
> proof of concept I want to stick with inets.
> 
> I appreciate any help and I just want to say that Erlang has been an
> absolute joy so far!
> 
> -Ryan
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

 I start inets and httpd from my supervisor (in init/1).  Not
 claiming this is the *best* way to do it, but seems to work fine.
 It might make more sense to start it from within one of the other
 processes that is started from the supervisor but, as mentioned,
 this seems to work fine (though I only use inets in my application
 to provide RSS feeds).

 See also Erlang documentation for inets and application regarding
 'permanent'.

    inets:start(permanent) ,
    inets:start(httpd, [{proplist_file, "priv/conf/httpd.conf"}]) ,

 The above two lines are in src/edids_sup.erl at http://edids.org
 (you will have to login as 'anonymous' to see the 'Files' link).

~M

-- 
Michael McDaniel
Portland, Oregon, USA
http://trip.autosys.us
http://edids.org


More information about the erlang-questions mailing list