PageRenderTime 77ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/support/templates/mochiwebapp_skel/src/mochiapp_sup.erl

http://github.com/basho/mochiweb
Erlang | 56 lines | 33 code | 12 blank | 11 comment | 3 complexity | c948ca2b19a7c7cea0e008245adcabd4 MD5 | raw file
Possible License(s): MIT
  1. %% @author {{author}}
  2. %% @copyright {{year}} {{author}}
  3. %% @doc Supervisor for the {{appid}} application.
  4. -module({{appid}}_sup).
  5. -author("{{author}}").
  6. -behaviour(supervisor).
  7. %% External exports
  8. -export([start_link/0, upgrade/0]).
  9. %% supervisor callbacks
  10. -export([init/1]).
  11. %% @spec start_link() -> ServerRet
  12. %% @doc API for starting the supervisor.
  13. start_link() ->
  14. supervisor:start_link({local, ?MODULE}, ?MODULE, []).
  15. %% @spec upgrade() -> ok
  16. %% @doc Add processes if necessary.
  17. upgrade() ->
  18. {ok, {_, Specs}} = init([]),
  19. Old = sets:from_list(
  20. [Name || {Name, _, _, _} <- supervisor:which_children(?MODULE)]),
  21. New = sets:from_list([Name || {Name, _, _, _, _, _} <- Specs]),
  22. Kill = sets:subtract(Old, New),
  23. sets:fold(fun (Id, ok) ->
  24. supervisor:terminate_child(?MODULE, Id),
  25. supervisor:delete_child(?MODULE, Id),
  26. ok
  27. end, ok, Kill),
  28. [supervisor:start_child(?MODULE, Spec) || Spec <- Specs],
  29. ok.
  30. %% @spec init([]) -> SupervisorTree
  31. %% @doc supervisor callback.
  32. init([]) ->
  33. Web = web_specs({{appid}}_web, {{port}}),
  34. Processes = [Web],
  35. Strategy = {one_for_one, 10, 10},
  36. {ok,
  37. {Strategy, lists:flatten(Processes)}}.
  38. web_specs(Mod, Port) ->
  39. WebConfig = [{ip, {0,0,0,0}},
  40. {port, Port},
  41. {docroot, {{appid}}_deps:local_path(["priv", "www"])}],
  42. {Mod,
  43. {Mod, start, [WebConfig]},
  44. permanent, 5000, worker, dynamic}.