Skip to content
Permalink
Browse files
Add children to the supervision tree
  • Loading branch information
kocolosk committed Oct 24, 2012
1 parent 203b49a commit 21a966ae4216a79e5bfc633757493ed2fa83a0fb
Showing 2 changed files with 34 additions and 9 deletions.
@@ -10,7 +10,19 @@
%% ===================================================================

start(_StartType, _StartArgs) ->
couch_config_sup:start_link().
couch_config_sup:start_link(get_ini_files()).

stop(_State) ->
ok.

get_ini_files() ->
Etc = filename:join(code:root_dir(), "etc"),
Default = [filename:join(Etc,"default.ini"), filename:join(Etc,"local.ini")],
case init:get_argument(couch_ini) of
error ->
Default;
{ok, [[]]} ->
Default;
{ok, [Values]} ->
Values
end.
@@ -14,24 +14,37 @@
-behaviour(supervisor).

%% API
-export([start_link/0]).
-export([start_link/1]).

%% Supervisor callbacks
-export([init/1]).

%% Helper macro for declaring children of supervisor
-define(CHILD(I, Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}).

%% ===================================================================
%% API functions
%% ===================================================================

start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
start_link(IniFiles) ->
supervisor:start_link({local, ?MODULE}, ?MODULE, IniFiles).

%% ===================================================================
%% Supervisor callbacks
%% ===================================================================

init([]) ->
{ok, { {one_for_one, 5, 10}, []} }.
init(IniFiles) ->
Children = [
{couch_config,
{couch_config, start_link, [IniFiles]},
permanent,
5000,
worker,
[couch_config]
},
{couch_config_event,
{couch_config_event, start_link, []},
permanent,
5000,
worker,
dynamic
}
],
{ok, {{one_for_one, 5, 10}, Children}}.

0 comments on commit 21a966a

Please sign in to comment.