2 %% @copyright {{year}} {{author}}
4 %% @doc Supervisor for the {{appid}} application.
6 -module({{appid}}_sup).
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 Web = web_specs({{appid}}_web, {{port}}),
46 Strategy = {one_for_one, 10, 10},
48 {Strategy, lists:flatten(Processes)}}.
50 web_specs(Mod, Port) ->
51 WebConfig = [{ip, {0,0,0,0}},
53 {docroot, {{appid}}_deps:local_path(["priv", "www"])}],
55 {Mod, start, [WebConfig]},
56 permanent, 5000, worker, dynamic}.