1 %% @author author <author@example.com>
2 %% @copyright YYYY author.
4 %% @doc Supervisor for the {{appid}} application.
6 -module({{appid}}_sup).
7 -author('author <author@example.com>').
9 -behaviour(supervisor).
12 -export([start_link/0, upgrade/0]).
14 %% supervisor callbacks
17 %% @spec start_link() -> ServerRet
18 %% @doc API for starting the supervisor.
20 supervisor:start_link({local, ?MODULE}, ?MODULE, []).
22 %% @spec upgrade() -> ok
23 %% @doc Add processes if necessary.
25 {ok, {_, Specs}} = init([]),
28 [Name || {Name, _, _, _} <- supervisor:which_children(?MODULE)]),
29 New = sets:from_list([Name || {Name, _, _, _, _, _} <- Specs]),
30 Kill = sets:subtract(Old, New),
32 sets:fold(fun (Id, ok) ->
33 supervisor:terminate_child(?MODULE, Id),
34 supervisor:delete_child(?MODULE, Id),
38 [supervisor:start_child(?MODULE, Spec) || Spec <- Specs],
41 %% @spec init([]) -> SupervisorTree
42 %% @doc supervisor callback.
44 Ip = case os:getenv("WEBMACHINE_IP") of false -> "0.0.0.0"; Any -> Any end,
45 {ok, App} = application:get_application(?MODULE),
46 {ok, Dispatch} = file:consult(filename:join([priv_dir(App),
48 Port = case os:getenv("WEBMACHINE_PORT") of
55 {log_dir, "priv/log"},
56 {dispatch, Dispatch}],
57 Web = {webmachine_mochiweb,
58 {webmachine_mochiweb, start, [WebConfig]},
59 permanent, 5000, worker, [mochiweb_socket_server]},
61 {ok, { {one_for_one, 10, 10}, Processes} }.
64 %% @doc return the priv dir
66 case code:priv_dir(Mod) of
68 Ebin = filename:dirname(code:which(Mod)),
69 filename:join(filename:dirname(Ebin), "priv");