couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject [17/42] git commit: updated refs/heads/master to a4d6cd4
Date Thu, 03 Oct 2013 14:13:30 GMT
load plugin config from priv/default.d/*.ini


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

Branch: refs/heads/master
Commit: c3efead76f0b7977ee86c7258aad8121ea065911
Parents: 963aee4
Author: Bob Ippolito <bob@redivi.com>
Authored: Thu Aug 1 01:47:50 2013 -0700
Committer: Jan Lehnardt <jan@apache.org>
Committed: Thu Oct 3 16:08:35 2013 +0200

----------------------------------------------------------------------
 Makefile.am                             |  1 +
 bin/Makefile.am                         |  1 +
 bin/couchdb.tpl.in                      | 39 +++++++++++---------
 src/couch_plugins/Makefile.am           |  1 +
 src/couch_plugins/README.md             |  8 ++---
 src/couch_plugins/src/couch_plugins.erl | 53 ++++++++++------------------
 src/couchdb/couch_config.erl            |  2 +-
 utils/Makefile.am                       |  1 +
 8 files changed, 51 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/c3efead7/Makefile.am
----------------------------------------------------------------------
diff --git a/Makefile.am b/Makefile.am
index debfdf4..527cf18 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -113,6 +113,7 @@ if TESTS
 	mkdir -p $(top_builddir)/tmp/lib
 	mkdir -p $(top_builddir)/tmp/log
 	mkdir -p $(top_builddir)/tmp/run/couchdb
+	mkdir -p $(top_builddir)/tmp/plugins
 endif
 
 install-data-hook:

http://git-wip-us.apache.org/repos/asf/couchdb/blob/c3efead7/bin/Makefile.am
----------------------------------------------------------------------
diff --git a/bin/Makefile.am b/bin/Makefile.am
index 3d7a075..c1913d0 100644
--- a/bin/Makefile.am
+++ b/bin/Makefile.am
@@ -51,6 +51,7 @@ couchdb: couchdb.tpl
 	    -e "s|%localstatelogdir%|@localstatelogdir@|g" \
 	    -e "s|%localstatelibdir%|@localstatelibdir@|g" \
 	    -e "s|%localstatedir%|@localstatedir@|g" \
+	    -e "s|%locallibdir%|@locallibdir@|g" \
 	    -e "s|%bug_uri%|@bug_uri@|g" \
 	    -e "s|%package_author_address%|@package_author_address@|g" \
 	    -e "s|%package_author_name%|@package_author_name@|g" \

http://git-wip-us.apache.org/repos/asf/couchdb/blob/c3efead7/bin/couchdb.tpl.in
----------------------------------------------------------------------
diff --git a/bin/couchdb.tpl.in b/bin/couchdb.tpl.in
index ff06007..36d4dfb 100644
--- a/bin/couchdb.tpl.in
+++ b/bin/couchdb.tpl.in
@@ -25,6 +25,7 @@ HEART_BEAT_TIMEOUT=11
 HEART_COMMAND="%bindir%/%couchdb_command_name% -k"
 INTERACTIVE=false
 KILL=false
+PLUGINS_DIR=%locallibdir%/plugins
 LOCAL_CONFIG_DIR=%localconfdir%/local.d
 LOCAL_CONFIG_FILE=%localconfdir%/%localini%
 PID_FILE=%localstatedir%/run/couchdb/couchdb.pid
@@ -144,6 +145,8 @@ _add_config_dir () {
 _load_config () {
     _add_config_file "$DEFAULT_CONFIG_FILE"
     _add_config_dir "$DEFAULT_CONFIG_DIR"
+    # We initialize plugins here to get the desired default config load order
+    _find_plugins
     _add_config_file "$LOCAL_CONFIG_FILE"
     _add_config_dir "$LOCAL_CONFIG_DIR"
     if [ "$COUCHDB_ADDITIONAL_CONFIG_FILE" != '' ]
@@ -216,6 +219,26 @@ check_environment () {
     fi
 }
 
+_find_plugins () {
+    # Find plugins and add them to the Erlang path and load their default
+    # configurations. This should be called from _load_config.
+    if test -d "$PLUGINS_DIR"; then
+        for plugin in "$PLUGINS_DIR"/*; do
+            if echo "$COUCH_PLUGIN_BLACKLIST" | grep "$plugin" > /dev/null 2> /dev/null;
then
+                : # Do not use this plugin.
+            else
+                if echo "$ERL_ZFLAGS" | grep "$plugin/ebin" > /dev/null 2> /dev/null;
then
+                    : # It's already loaded.
+                else
+                    ERL_ZFLAGS="$ERL_ZFLAGS -pz '$plugin/ebin'"
+                fi
+                _add_config_dir "$plugin/priv/default.d"
+            fi
+        done
+        export ERL_ZFLAGS
+    fi
+}
+
 start_couchdb () {
     if test ! "$RECURSED" = "true"; then
         if check_status 2> /dev/null; then
@@ -232,22 +255,6 @@ start_couchdb () {
         interactive_option="+Bd -noinput"
     fi
 
-    # Find plugins and add them to the Erlang path.
-    if test -d "%localerlanglibdir%/../../plugins"; then
-        for plugin in "%localerlanglibdir%/../../plugins"/*; do
-            if echo "$ERL_ZFLAGS" | grep "$plugin/ebin" > /dev/null 2> /dev/null; then
-                : # It's already loaded.
-            else
-                if echo "$COUCH_PLUGIN_BLACKLIST" | grep "$plugin" > /dev/null 2> /dev/null;
then
-                    : # Do not use this plugin.
-                else
-                    ERL_ZFLAGS="$ERL_ZFLAGS -pz '$plugin/ebin'"
-                fi
-            fi
-        done
-        export ERL_ZFLAGS
-    fi
-
     command="%ERL% $interactive_option $ERL_START_OPTIONS \
         -env ERL_LIBS $ERL_LIBS:%localerlanglibdir% -couch_ini $start_arguments -s couch"
     if test "$BACKGROUND" = "true" -a "$RECURSED" = "false"; then

http://git-wip-us.apache.org/repos/asf/couchdb/blob/c3efead7/src/couch_plugins/Makefile.am
----------------------------------------------------------------------
diff --git a/src/couch_plugins/Makefile.am b/src/couch_plugins/Makefile.am
index 300f19c..91adfae 100644
--- a/src/couch_plugins/Makefile.am
+++ b/src/couch_plugins/Makefile.am
@@ -10,6 +10,7 @@
 ## License for the specific language governing permissions and limitations under
 ## the License.
 
+couch_pluginslibdir = $(localerlanglibdir)/couch_plugins-0.1
 couch_pluginsebindir = $(couch_pluginslibdir)/ebin
 
 couch_pluginsebin_DATA = $(compiled_files)

http://git-wip-us.apache.org/repos/asf/couchdb/blob/c3efead7/src/couch_plugins/README.md
----------------------------------------------------------------------
diff --git a/src/couch_plugins/README.md b/src/couch_plugins/README.md
index 09a0a71..8851794 100644
--- a/src/couch_plugins/README.md
+++ b/src/couch_plugins/README.md
@@ -131,10 +131,10 @@ to the Erlang code path
 (`code:add_path("/tmp/couchdb_plugins/geocouch-couchdb1.2.x_v0.3.0-12-g4ea0bea-R15B03/ebin")`)
 and loads the included application (`application:load(geocouch)`).
 
-Then it looks into the `./config` directory that lives next to `ebin/`
-in the plugin directory for a file `config.erlt` (“erl-terms”). with a
-list of configuration parameters to load. We parse the file and set
-the config directives one by one.
+Then it looks into the `./priv/default.d` directory that lives next to
+`ebin/` in the plugin directory for configuration `.ini` files and loads them.
+On next startup these configuration files are loaded after global defaults,
+and before any local configuration.
 
 If that all goes to plan, we report success back to the HTTP caller.
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/c3efead7/src/couch_plugins/src/couch_plugins.erl
----------------------------------------------------------------------
diff --git a/src/couch_plugins/src/couch_plugins.erl b/src/couch_plugins/src/couch_plugins.erl
index daac885..a7680c3 100644
--- a/src/couch_plugins/src/couch_plugins.erl
+++ b/src/couch_plugins/src/couch_plugins.erl
@@ -18,7 +18,7 @@
 
 -define(PLUGIN_DIR, "/tmp/couchdb_plugins").
 
-log(T) -> 
+log(T) ->
   ?LOG_DEBUG("[couch_plugins] ~p ~n", [T]).
 
 %% "geocouch", "http://localhost:8000/dist", "1.0.0"
@@ -45,44 +45,30 @@ install({Name, _BaseUrl, Version, Checksums}=Plugin) ->
   log("loaded plugin"),
   ok.
 
--spec load_config(string(), string()) -> ok | {error, string()}.
+-spec load_config(string(), string()) -> ok.
 load_config(Name, Version) ->
-  ConfigFile = ?PLUGIN_DIR ++ "/" ++ get_file_slug(Name, Version) ++ "/priv/config.erlt",
-  load_config_file(file_exists(ConfigFile), ConfigFile).
-
--spec load_config_file(boolean(), string()) -> ok | {error, string()}.
-load_config_file(false, _) -> ok;
-load_config_file(true, ConfigFile) ->
-  % read file
-  {ok, ConfigFileData} = file:read_file(ConfigFile),
-  % split by \n
-  Lines = binary:split(ConfigFileData, <<"\n">>, [global]),
-  % feed each line...
-  lists:foreach(
-    fun(<<>>) ->
-      ok; % skip empty lines
-    (<<";", _Rest/binary>>) ->
-      ok; % ignore comments
-    (Line) ->
-    % ...to couch_util:parse_term()...
-    case couch_util:parse_term(Line) of
-      {ok, {{Section, Key}, Value}} ->
-        % ...and set the configs
-        ?LOG_DEBUG("parsed Line correctly: ~p", [Line]),
-        couch_config:set(Section, Key, Value);
-      Else ->
-        ?LOG_ERROR("Error parsing plugin config from line ~s", [Line]),
-        Else
-      end
-  end, Lines),
-  ok.
+    lists:foreach(
+      fun load_config_file/1,
+      filelib:wildcard(
+        filename:join(
+          [?PLUGIN_DIR, get_file_slug(Name, Version),
+           "priv", "default.d", "*.ini"]))).
+
+-spec load_config_file(string()) -> ok.
+load_config_file(File) ->
+    {ok, Config} = couch_config:parse_ini_file(File),
+    lists:foreach(fun set_config/1, Config).
+
+-spec set_config({{string(), string()}, string()}) -> ok.
+set_config({{Section, Key}, Value}) ->
+    ok = couch_config:set(Section, Key, Value, false).
 
 -spec add_code_path(string(), string()) -> ok | {error, bad_directory}.
 add_code_path(Name, Version) ->
   PluginPath = ?PLUGIN_DIR ++ "/" ++ get_file_slug(Name, Version) ++ "/ebin",
   case code:add_path(PluginPath) of
     true -> ok;
-    Else -> 
+    Else ->
       ?LOG_ERROR("Failed to add PluginPath: '~s'", [PluginPath]),
       Else
   end.
@@ -103,7 +89,7 @@ untargz(Filename) ->
   ok = filelib:ensure_dir(?PLUGIN_DIR),
   % untar
   erl_tar:extract({binary, TarData}, [{cwd, ?PLUGIN_DIR}, keep_old_files]).
-  
+
 
 % downloads a pluygin .tar.gz into a local plugins directory
 -spec download(string()) -> ok | {error, string()}.
@@ -256,4 +242,3 @@ does_file_exist(_Else) -> true.
 %  - in couch 1.x.x context
 %  - in bigcouch context
 %  - what is a server-user owned data/ dir we can use for this, that isn’t db_dir or index_dir
or log or var/run or /tmp
-

http://git-wip-us.apache.org/repos/asf/couchdb/blob/c3efead7/src/couchdb/couch_config.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_config.erl b/src/couchdb/couch_config.erl
index 96fabba..22d7cdc 100644
--- a/src/couchdb/couch_config.erl
+++ b/src/couchdb/couch_config.erl
@@ -94,7 +94,7 @@ register(Fun, Pid) ->
 init(IniFiles) ->
     ets:new(?MODULE, [named_table, set, protected]),
     try
-        lists:map(fun(IniFile) ->
+        lists:foreach(fun(IniFile) ->
             {ok, ParsedIniValues} = parse_ini_file(IniFile),
             ets:insert(?MODULE, ParsedIniValues)
         end, IniFiles),

http://git-wip-us.apache.org/repos/asf/couchdb/blob/c3efead7/utils/Makefile.am
----------------------------------------------------------------------
diff --git a/utils/Makefile.am b/utils/Makefile.am
index e5bbdb8..5afe707 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -34,6 +34,7 @@ run: ../bin/couchdb.tpl
 	    -e "s|%localstatelogdir%|$(abs_top_builddir)/tmp/log|g" \
 	    -e "s|%localstatelibdir%|$(abs_top_builddir)/tmp/lib|g" \
 	    -e "s|%localstatedir%|$(abs_top_builddir)/tmp|g" \
+	    -e "s|%locallibdir%|$(abs_top_builddir)/tmp|g" \
 	    -e "s|%bug_uri%|@bug_uri@|g" \
 	    -e "s|%package_author_address%|@package_author_address@|g" \
 	    -e "s|%package_author_name%|@package_author_name@|g" \


Mime
View raw message