PageRenderTime 35ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/priv/skel/src/skel_sup.erl

http://github.com/basho/mochiweb
Erlang | 62 lines | 34 code | 14 blank | 14 comment | 3 complexity | 25caa315c3635cdc015cb0dbe3be986a MD5 | raw file
Possible License(s): MIT
  1. %% @author author <author@example.com>
  2. %% @copyright YYYY author.
  3. %% @doc Supervisor for the skel application.
  4. -module(skel_sup).
  5. -author('author <author@example.com>').
  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. Ip = case os:getenv("MOCHIWEB_IP") of false -> "0.0.0.0"; Any -> Any end,
  34. WebConfig = [
  35. {ip, Ip},
  36. {port, 8000},
  37. {docroot, skel_deps:local_path(["priv", "www"])}],
  38. Web = {skel_web,
  39. {skel_web, start, [WebConfig]},
  40. permanent, 5000, worker, dynamic},
  41. Processes = [Web],
  42. {ok, {{one_for_one, 10, 10}, Processes}}.
  43. %%
  44. %% Tests
  45. %%
  46. -include_lib("eunit/include/eunit.hrl").
  47. -ifdef(TEST).
  48. -endif.