Add children to the supervision tree

Project: http://git-wip-us.apache.org/repos/asf/couchdb-config/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-config/commit/21a966ae
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-config/tree/21a966ae
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-config/diff/21a966ae

Branch: refs/heads/import
Commit: 21a966ae4216a79e5bfc633757493ed2fa83a0fb
Parents: 203b49a
Author: Adam Kocoloski <a...@cloudant.com>
Authored: Tue Oct 23 19:10:57 2012 -0400
Committer: Adam Kocoloski <a...@cloudant.com>
Committed: Wed Oct 24 21:38:19 2012 +0900

----------------------------------------------------------------------
 src/couch_config_app.erl | 14 +++++++++++++-
 src/couch_config_sup.erl | 29 +++++++++++++++++++++--------
 2 files changed, 34 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-config/blob/21a966ae/src/couch_config_app.erl
----------------------------------------------------------------------
diff --git a/src/couch_config_app.erl b/src/couch_config_app.erl
index b7672f5..4178d1d 100644
--- a/src/couch_config_app.erl
+++ b/src/couch_config_app.erl
@@ -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.

http://git-wip-us.apache.org/repos/asf/couchdb-config/blob/21a966ae/src/couch_config_sup.erl
----------------------------------------------------------------------
diff --git a/src/couch_config_sup.erl b/src/couch_config_sup.erl
index 638ec79..af2aa30 100644
--- a/src/couch_config_sup.erl
+++ b/src/couch_config_sup.erl
@@ -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}}.

Reply via email to