1 %% @author author <author@example.com>
2 %% @copyright YYYY author.
4 %% @doc Supervisor for the webmachine_demo application.
6 -module(webmachine_demo_sup).
8 -behaviour(supervisor).
11 -export([start_link/0, upgrade/0]).
13 %% supervisor callbacks
16 %% @spec start_link() -> ServerRet
17 %% @doc API for starting the supervisor.
19 supervisor:start_link({local, ?MODULE}, ?MODULE, []).
21 %% @spec upgrade() -> ok
22 %% @doc Add processes if necessary.
24 {ok, {_, Specs}} = init([]),
27 [Name || {Name, _, _, _} <- supervisor:which_children(?MODULE)]),
28 New = sets:from_list([Name || {Name, _, _, _, _, _} <- Specs]),
29 Kill = sets:subtract(Old, New),
31 sets:fold(fun (Id, ok) ->
32 supervisor:terminate_child(?MODULE, Id),
33 supervisor:delete_child(?MODULE, Id),
37 [supervisor:start_child(?MODULE, Spec) || Spec <- Specs],
40 %% @spec init([]) -> SupervisorTree
41 %% @doc supervisor callback.
43 Ip = case os:getenv("WEBMACHINE_IP") of false -> "0.0.0.0"; Any -> Any end,
44 {ok, Dispatch} = file:consult(filename:join(
45 [filename:dirname(code:which(?MODULE)),
46 "..", "priv", "dispatch.conf"])),
50 {log_dir, "priv/log"},
51 {dispatch, Dispatch}],
52 Web = {webmachine_mochiweb,
53 {webmachine_mochiweb, start, [WebConfig]},
54 permanent, 5000, worker, dynamic},
56 {ok, { {one_for_one, 10, 10}, Processes} }.