Permalink
Browse files

Start cowboy outside of supervisor

  • Loading branch information...
1 parent ad9a5e7 commit e33b405ff84faa4583dc818cc75294ed0db21e9a @yrashk committed Apr 30, 2011
Showing with 10 additions and 9 deletions.
  1. +9 −2 src/stayunlost_app.erl
  2. +1 −7 src/stayunlost_sup.erl
@@ -10,7 +10,14 @@
%% ===================================================================
start(_StartType, _StartArgs) ->
- stayunlost_sup:start_link().
+ {ok, Port} = application:get_env(stayunlost, port),
+ Dispatch = [{'_', [{'_', stayunlost_http_handler, []}]}],
+ {ok, Listener} = cowboy:start_listener(http, 100,
+ cowboy_tcp_transport, [{port, Port}],
+ cowboy_http_protocol, [{dispatch, Dispatch}]),
+ {ok, Pid} = stayunlost_sup:start_link(),
+ {ok, Pid, Listener}.
-stop(_State) ->
+stop(Listener) ->
+ cowboy:stop_listener(Listener),
ok.
@@ -23,12 +23,6 @@ start_link() ->
%% ===================================================================
init([]) ->
- {ok, Port} = application:get_env(stayunlost, port),
- Dispatch = [{'_', [{'_', stayunlost_http_handler, []}]}],
{ok, { {one_for_one, 5, 10}, [
- {stayunlost_http_server, {cowboy, start_listener, [http, 100,
- cowboy_tcp_transport, [{port, Port}],
- cowboy_http_protocol, [{dispatch, Dispatch}]]},
- permanent, infinity, supervisor, [stayunlost_http_handler, cowboy, cowboy_http_protocol, cowboy_tcp_transport]}
- ]} }.
+ ]}}.

0 comments on commit e33b405

Please sign in to comment.