mochiweb_sup.erl -- broken?

1 view
Skip to first unread message

JP

unread,
Nov 15, 2007, 5:58:31 PM11/15/07
to MochiWeb
Sorry if this is a stupid question -- but it appears that mochiweb_sup
doesn't do anything. the init callback looks like this:

init([]) ->
Processes = [],
{ok, {{one_for_one, 10, 10}, Processes}}.

I read that as "start no child processes", and when I start mochiweb
via application:start(mochiweb), I see only the supervisor proc in
appmon. Am I missing something? Using mochiweb_http:start/1 works
fine, I'm just wondering whether the app packaging is broken or my
poor understanding of OTP is misleading me.

JP

Roberto Saccon

unread,
Nov 15, 2007, 6:54:47 PM11/15/07
to MochiWeb
I don't now either the purpose of that supervisor, if you just need an
example of how to build an OTP app on top of MochiWeb, you can take a
look at ErlyComet and how we have tried to approach that.

regards
Roberto

Bob Ippolito

unread,
Nov 16, 2007, 1:48:18 AM11/16/07
to moch...@googlegroups.com

It's not supposed to be started as an OTP application, you're supposed
to use mochiweb_http in your own supervisor(s). It doesn't really make
sense to do that since it's not a general web server, and it's much
easier to configure it in your own supervisor than with the
application configuration junk in OTP.

The fact that it has mochiweb_sup, mochiweb_app, etc. is pretty much
just because of the template I was starting from. Maybe someday we'll
find something intelligent to do with that (like start up a demo that
serves up documentation).

-bob

Bob Ippolito

unread,
Nov 16, 2007, 1:56:46 AM11/16/07
to moch...@googlegroups.com

To expand on that, this is the basic pattern that we use:

%% Application's web code
-module(webapp_web).
-export([start/1, http/1]).

start(Options) ->
mochiweb_http:start([{name, ?MODULE}, {loop, {?MODULE, loop}} | Options]).

loop(Req) ->
Req:ok({"text/plain", "It worked!"}).

%% Application's supervisor
-module(webapp_sup).
-export([init/1, start_link/0]).
-behaviour(supervisor).

start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []).

init([]) ->
WebConfig = [{port, 8080}],
Web = {webapp_web,
{webapp_web, start, [WebConfig]},
permanent, 5000, worker, dynamic},
Processes = [Web],

JP

unread,
Nov 16, 2007, 10:04:27 AM11/16/07
to MochiWeb

> To expand on that, this is the basic pattern that we use:
>
> %% Application's web code
> -module(webapp_web).
> -export([start/1, http/1]).
>
> start(Options) ->
> mochiweb_http:start([{name, ?MODULE}, {loop, {?MODULE, loop}} | Options]).
>
> loop(Req) ->
> Req:ok({"text/plain", "It worked!"}).
>
> %% Application's supervisor
> -module(webapp_sup).
> -export([init/1, start_link/0]).
> -behaviour(supervisor).
>
> start_link() ->
> supervisor:start_link({local, ?MODULE}, ?MODULE, []).
>
> init([]) ->
> WebConfig = [{port, 8080}],
> Web = {webapp_web,
> {webapp_web, start, [WebConfig]},
> permanent, 5000, worker, dynamic},
> Processes = [Web],
> {ok, {{one_for_one, 10, 10}, Processes}}.

Thanks! The example is very helpful.

JP
Reply all
Reply to author
Forward
0 new messages