couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r655817 - in /incubator/couchdb/branches/runtimeconfig: bin/ etc/couchdb/ share/www/script/ src/couchdb/
Date Tue, 13 May 2008 11:18:08 GMT
Author: jan
Date: Tue May 13 04:18:08 2008
New Revision: 655817

URL: http://svn.apache.org/viewvc?rev=655817&view=rev
Log:
- use new branch for runtime config work
- add ability to initialise from a list of ini files
- remove initialisation code from couch_config.erl
- modules can now optionally request a default value to be returned in case no config value
is set
- use null atom instead of no_value to indicate no config value to have our JSON generator
make that into the null value
- general cleanup

Added:
    incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config.erl
Modified:
    incubator/couchdb/branches/runtimeconfig/bin/couchdb.tpl.in
    incubator/couchdb/branches/runtimeconfig/etc/couchdb/couch.ini.tpl.in
    incubator/couchdb/branches/runtimeconfig/etc/couchdb/couch_httpd.conf.tpl.in
    incubator/couchdb/branches/runtimeconfig/share/www/script/couch_tests.js
    incubator/couchdb/branches/runtimeconfig/src/couchdb/Makefile.am
    incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_httpd.erl
    incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_log.erl
    incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_query_servers.erl
    incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server.erl
    incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server_sup.erl
    incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_util.erl
    incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_view.erl

Modified: incubator/couchdb/branches/runtimeconfig/bin/couchdb.tpl.in
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/bin/couchdb.tpl.in?rev=655817&r1=655816&r2=655817&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/bin/couchdb.tpl.in (original)
+++ incubator/couchdb/branches/runtimeconfig/bin/couchdb.tpl.in Tue May 13 04:18:08 2008
@@ -220,6 +220,9 @@
         touch $PID_FILE
         interactive_option="+Bd -noinput"
     fi
+    
+    ini_file_list="[\\\"$INI_FILE\\\"]"
+    
     command="`%ICU_CONFIG% --invoke` \
         %ERL% $interactive_option -sasl errlog_type error \
         -pa %erlanglibdir%/couch-%version%/ebin \
@@ -229,8 +232,8 @@
         -eval \"application:load(couch)\" \
         -eval \"crypto:start()\" \
         -eval \"inets:start()\" \
-        -eval \"couch_server:start(), receive done -> done end.\" \
-        -couchini $INI_FILE"
+        -eval \"couch_server:start($ini_file_list), receive done -> done end.\" "
+
     if test "$BACKGROUND_BOOLEAN" = "true" \
         -a "$RECURSED_BOOLEAN" = "false"; then
         # Recursively call and detach a duplicate couchdb command.

Modified: incubator/couchdb/branches/runtimeconfig/etc/couchdb/couch.ini.tpl.in
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/etc/couchdb/couch.ini.tpl.in?rev=655817&r1=655816&r2=655817&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/etc/couchdb/couch.ini.tpl.in (original)
+++ incubator/couchdb/branches/runtimeconfig/etc/couchdb/couch.ini.tpl.in Tue May 13 04:18:08
2008
@@ -1,23 +1,21 @@
 ; @configure_input@
 
-[Couch]
-
+[CouchDB]
 ConsoleStartupMsg=Apache CouchDB is starting.
+RootDirectory=%pkgstatelibdir%
+UtilDriverDir=%couchprivlibdir%
 
-DbRootDir=%pkgstatelibdir%
 
+[HTTPd]
 Port=5984
-
 BindAddress=127.0.0.1
-
 DocumentRoot=%pkgdatadir%/www
 
-LogFile=%pkgstatelogdir%/couch.log
-
-UtilDriverDir=%couchprivlibdir%
-
-LogLevel=info
 
-[Couch Query Servers]
+[Log]
+File=%pkgstatelogdir%/couch.log
+Level=info
 
+[CouchDB Query Servers]
 text/javascript=%bindir%/%couchjs_command_name% %pkgdatadir%/server/main.js
+  
\ No newline at end of file

Modified: incubator/couchdb/branches/runtimeconfig/etc/couchdb/couch_httpd.conf.tpl.in
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/etc/couchdb/couch_httpd.conf.tpl.in?rev=655817&r1=655816&r2=655817&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/etc/couchdb/couch_httpd.conf.tpl.in (original)
+++ incubator/couchdb/branches/runtimeconfig/etc/couchdb/couch_httpd.conf.tpl.in Tue May 13
04:18:08 2008
@@ -1,11 +0,0 @@
-# @configure_input@
-
-Port 5984
-#BindAddress 127.0.0.1
-ServerName localhost
-SocketType ip_comm
-Modules mod_couch mod_get mod_log
-ServerRoot %pkgconfdir%
-DocumentRoot %pkgdatadir%/www
-ErrorLog %pkgstatelogdir%/http_error.log
-TransferLog %pkgstatelogdir%/http_access.log

Modified: incubator/couchdb/branches/runtimeconfig/share/www/script/couch_tests.js
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/share/www/script/couch_tests.js?rev=655817&r1=655816&r2=655817&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/share/www/script/couch_tests.js [utf-8] (original)
+++ incubator/couchdb/branches/runtimeconfig/share/www/script/couch_tests.js [utf-8] Tue May
13 04:18:08 2008
@@ -885,8 +885,41 @@
     var compactedsize = db.info().disk_size;
     
     T(deletesize > originalsize);
+    },
+    
+  runtime_config: function(debug) {
+    if(debug) debugger;
+    var xhr;
+
+    xhr = CouchDB.request("GET", "/_config/HTTPd/Port");
+    T(xhr.status == 200);
+    T(JSON.parse(xhr.responseText).ok);
+
+    xhr = CouchDB.request("POST", "/_config/HTTPd/Port", {"body":"5985"});
+    T(xhr.status == 200);
+    var res = JSON.parse(xhr.responseText);
+    T(res.ok);
+    T(res.value == "5985");
+
+    xhr = CouchDB.request("GET", "/_config/HTTPd/Port");
+    T(xhr.status == 200);
+    var res = JSON.parse(xhr.responseText);
+    T(res.ok);
+    T(res.value == "5985");
+
+    xhr = CouchDB.request("DELETE", "/_config/HTTPd/Port");
+    T(xhr.status == 200);
+    var res = JSON.parse(xhr.responseText);
+    T(res.ok);
+    T(res.old_value == "5985");
+
+    xhr = CouchDB.request("PUT", "/_config/HTTPd/Port", {"body":"5984"});
+    T(xhr.status == 200);
+    var res = JSON.parse(xhr.responseText);
+    T(res.ok);
+    T(res.value == "5984");
     }
-};
+  };
 
 function makeDocs(start, end, templateDoc) {
   var templateDocSrc = templateDoc ? templateDoc.toSource() : "{}"

Modified: incubator/couchdb/branches/runtimeconfig/src/couchdb/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/Makefile.am?rev=655817&r1=655816&r2=655817&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/Makefile.am (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/Makefile.am Tue May 13 04:18:08 2008
@@ -31,6 +31,7 @@
 couch_file_collection = \
     cjson.erl \
     couch_btree.erl \
+	couch_config.erl \
     couch_db.erl \
     couch_db_update_notifier.erl \
     couch_doc.erl \
@@ -52,6 +53,7 @@
     cjson.beam \
     couch.app \
     couch_btree.beam \
+	couch_config.beam \
     couch_db.beam \
     couch_db_update_notifier.beam \
     couch_doc.beam \

Added: incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config.erl?rev=655817&view=auto
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config.erl (added)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config.erl Tue May 13 04:18:08
2008
@@ -0,0 +1,145 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License.  You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_config).
+-include("couch_db.hrl").
+
+-define(DEFAULT_INI, "couch.ini").
+
+-behaviour(gen_server).
+-export([start_link/0, init/1   , 
+    handle_call/3, handle_cast/2, handle_info/2, 
+    terminate/2, code_change/3]).
+-export([store/2, 
+    lookup/1, lookup/2, lookup_match/1, lookup_match/2, dump/0,
+    init_value/2, unset/1, load_ini_file/1, 
+    load_ini_files/1]).
+
+start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).    
+
+init_value(Key, Value) -> gen_server:call(?MODULE, {init_value, Key, Value}).
+store(Key, Value) -> gen_server:call(?MODULE, {store, [{Key, Value}]}).
+lookup(Key) -> gen_server:call(?MODULE, {lookup, Key}).
+lookup(Key, Default) -> gen_server:call(?MODULE, {lookup, Key, Default}).
+lookup_match(Key) -> gen_server:call(?MODULE, {lookup_match, Key}).
+lookup_match(Key, Default) -> gen_server:call(?MODULE, {lookup_match, Key, Default}).
+dump() -> gen_server:call(?MODULE, {dump, []}).
+
+
+unset(Key) -> gen_server:call(?MODULE, {unset, Key}).
+
+
+init([]) ->     
+    Tap = ets:new(?MODULE, []),
+    {ok, Tap}.
+
+
+handle_call({store, Config}, _From, Tab) ->
+    [ets:insert(Tab, {Key, Value}) || {Key, Value} <- Config],
+    commit(),
+    {reply, ok, Tab};
+
+handle_call({init_value, Key, Value}, _From, Tab) ->
+    Reply = ets:insert(Tab, {Key, Value}),
+    {reply, Reply, Tab};
+
+handle_call({unset, Key}, _From, Tab) ->
+    ets:delete(Tab, Key),
+    {reply, ok, Tab};
+
+handle_call({lookup, Key}, _From, Tab) ->
+    lookup(Key, fun(Tab_, Key_) -> ets:lookup(Tab_, Key_) end, null, Tab);
+
+handle_call({lookup, Key, Default}, _From, Tab) ->
+    lookup(Key, fun(Tab_, Key_) -> ets:lookup(Tab_, Key_) end, Default, Tab);
+
+handle_call({lookup_match, Key}, _From, Tab) ->
+    lookup(Key, fun(Tab_, Key_) -> ets:match(Tab_, Key_) end, null, Tab);
+
+handle_call({lookup_match, Key, Default}, _From, Tab) ->
+       lookup(Key, fun(Tab_, Key_) -> ets:match(Tab_, Key_) end, Default, Tab);
+
+handle_call({dump, []}, _From, Tab) ->
+    io:format("~p~n", [ets:match(Tab, '$1')]),
+    {reply, ok, Tab}.
+
+
+
+lookup(Key, Fun, Default, Tab) ->
+    Reply = case Fun(Tab, Key) of
+        [{Key, Value}] ->
+            Value;
+        [List] ->
+            lists:map(fun([Key2, Value2]) -> {Key2, Value2} end, [List]);
+        [] ->
+            Default
+    end,
+    {reply, Reply, Tab}.
+
+commit() ->
+    ok.
+
+handle_cast(_Msg, State) -> {noreply, State}.
+handle_info(_Msg, State) -> {noreply, State}.
+terminate(_Reason, _State) -> ok.
+code_change(_OldVersion, State, _Extra) -> {ok, State}.
+
+load_ini_files(IniFiles) ->
+    % load all ini files in the order they come in.
+    lists:foreach(fun(IniFile) -> load_ini_file(IniFile) end, IniFiles).
+
+load_ini_file(IniFile) ->
+    IniFilename = couch_util:abs_pathname(IniFile),
+    IniBin =
+    case file:read_file(IniFilename) of
+        {ok, IniBin0} ->
+           IniBin0;
+        {error, enoent} ->
+           Msg = io_lib:format("Couldn't find server configuration file ~s.", [IniFilename]),
+           io:format("~s~n", [Msg]),
+           throw({startup_error, Msg})
+    end,
+    
+    {ok, Lines} = regexp:split(binary_to_list(IniBin), "\r\n|\n|\r|\032"),
+    {_, ParsedIniValues} =
+    lists:foldl(fun(Line, {AccSectionName, AccValues}) ->
+            case string:strip(Line) of
+            "[" ++ Rest ->
+                case regexp:split(Rest, "\\]") of
+                {ok, [NewSectionName, ""]} ->
+                    {NewSectionName, AccValues};
+                _Else -> % end bracket not at end, ignore this line
+                    {AccSectionName, AccValues}
+                end;
+            ";" ++ _Comment ->
+                {AccSectionName, AccValues};
+            Line2 ->
+                case regexp:split(Line2, "=") of
+                {ok, [_SingleElement]} -> % no "=" found, ignore this line
+                    {AccSectionName, AccValues};
+                {ok, [""|_LineValues]} -> % line begins with "=", ignore
+                    {AccSectionName, AccValues};
+                {ok, [ValueName|LineValues]} -> % yeehaw, got a line!
+                    RemainingLine = couch_util:implode(LineValues, "="),
+                    {ok, [LineValue | _Rest]} = regexp:split(RemainingLine, " ;|\t;"), %
removes comments
+                    {AccSectionName, [{{AccSectionName, ValueName}, LineValue} | AccValues]}
+                end
+            end
+        end, {"", []}, Lines),
+        
+        lists:foreach(
+            fun({Key, Value}) ->
+                couch_config:init_value(Key, Value)
+            end,
+            lists:reverse(ParsedIniValues)
+        ),
+    ok.

Modified: incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_httpd.erl?rev=655817&r1=655816&r2=655817&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_httpd.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_httpd.erl Tue May 13 04:18:08
2008
@@ -13,7 +13,7 @@
 -module(couch_httpd).
 -include("couch_db.hrl").
 
--export([start_link/3, stop/0]).
+-export([start_link/0, stop/0]).
 
 -record(doc_query_args, {
     options = [],
@@ -34,7 +34,12 @@
     skip = 0
 }).
 
-start_link(BindAddress, Port, DocumentRoot) ->
+start_link() ->
+    % read config
+    BindAddress = couch_config:lookup({"HTTPd", "BindAddress"}),
+    Port = couch_config:lookup({"HTTPd", "Port"}),
+    DocumentRoot = couch_config:lookup({"HTTPd", "DocumentRoot"}),
+    
     Loop = fun (Req) -> handle_request(Req, DocumentRoot) end,
     mochiweb_http:start([
         {loop, Loop},
@@ -74,14 +79,8 @@
         atom_to_list(Req:get(method)) ++ " " ++ Path,
         Resp:get(code)
     ]).
-
-handle_request(Req, DocumentRoot, Method, Path) ->
-    % Start = erlang:now(),
-    X = handle_request0(Req, DocumentRoot, Method, Path),
-    % io:format("now_diff:~p~n", [timer:now_diff(erlang:now(), Start)]),
-    X.
     
-handle_request0(Req, DocumentRoot, Method, Path) ->
+handle_request(Req, DocumentRoot, Method, Path) ->
     case Path of
         "/" ->
             handle_welcome_request(Req, Method);
@@ -95,6 +94,8 @@
             {ok, Req:respond({301, [{"Location", "/_utils/"}], <<>>})};
         "/_utils/" ++ PathInfo ->
             {ok, Req:serve_file(PathInfo, DocumentRoot)};
+        "/_config/" ++ Config ->
+            handle_config_request(Req, Method, {config, Config});
         _Else ->
             handle_db_request(Req, Method, {Path})
     end.
@@ -543,6 +544,58 @@
 handle_attachment_request(_Req, _Method, _DbName, _Db, _DocId, _FileName) ->
     throw({method_not_allowed, "GET,HEAD"}).
 
+% Config request handlers
+
+handle_config_request(_Req, Method, {config, Config}) ->
+    [Module, Key] = string:tokens(Config, "/"),
+    handle_config_request(_Req, Method, {[list_to_atom(Module), list_to_atom(Key)]});
+
+
+% PUT /_config/Module/Key
+% "value"
+handle_config_request(_Req, 'PUT', {[Module, Key]}) ->
+     handle_config_request(_Req, 'POST', {[Module, Key]});
+
+% POST,PUT /_config/Module/Key
+% "value"
+ 
+handle_config_request(Req, 'POST', {[Module, Key]}) ->
+    Value = binary_to_list(Req:recv_body()),
+    ok = couch_config:store({Module, Key}, Value),
+    send_json(Req, 200, {obj, [
+        {ok, true},
+        {module, Module},
+        {key, Key},
+        {value, Value}
+    ]});
+    
+% GET /_config/Module/Key
+handle_config_request(Req, 'GET', {[Module, Key]}) ->
+    send_json(Req, 200, {obj, [
+        {ok, true},
+        {module, Module},
+        {key, Key},
+        {value, couch_config:lookup({Module, Key})}
+     ]});
+    
+% DELETE /_config/Key
+handle_config_request(Req, 'DELETE', {[Module, Key]}) ->
+    OldValue = couch_config:lookup({Module, Key}),
+    couch_config:unset({Module, Key}),
+    send_json(Req, 200, {obj, [
+        {ok, true},
+        {module, Module},
+        {key, Key},
+        {old_value, OldValue}
+     ]}).
+
+% TODO:
+% POST,PUT /_config/
+% [{Key, Value}, {K2, V2}, {K3, V3}]
+% 
+% POST,PUT/_config/Key?value=Value
+
+
 % View request handling internals
 
 reverse_key_default(nil) -> <<>>;

Modified: incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_log.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_log.erl?rev=655817&r1=655816&r2=655817&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_log.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_log.erl Tue May 13 04:18:08
2008
@@ -13,7 +13,7 @@
 -module(couch_log).
 -behaviour(gen_event).
 
--export([start_link/2,stop/0]).
+-export([start_link/0,stop/0]).
 -export([debug_on/0,info_on/0,get_level/0,get_level_integer/0, set_level/1]).
 -export([init/1, handle_event/2, terminate/2, code_change/3, handle_info/2, handle_call/2]).
 
@@ -34,7 +34,9 @@
 level_atom(?LEVEL_TMI) -> tmi.
 
 
-start_link(Filename, Level) ->
+start_link() ->
+    Filename = couch_config:lookup({"Log", "File"}),
+    Level = couch_config:lookup({"Log", "Level"}),
     couch_event_sup:start_link({local, couch_log}, error_logger, couch_log, {Filename, Level}).
 
 stop() ->
@@ -42,7 +44,7 @@
 
 init({Filename, Level}) ->
     {ok, Fd} = file:open(Filename, [append]),
-    {ok, {Fd, level_integer(Level)}}.
+    {ok, {Fd, level_integer(list_to_atom(Level))}}.
 
 debug_on() ->
     get_level_integer() =< ?LEVEL_DEBUG.

Modified: incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_query_servers.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_query_servers.erl?rev=655817&r1=655816&r2=655817&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_query_servers.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_query_servers.erl Tue May 13
04:18:08 2008
@@ -13,12 +13,12 @@
 -module(couch_query_servers).
 -behaviour(gen_server).
 
--export([start_link/1]).
+-export([start_link/0]).
 
 -export([init/1, terminate/2, handle_call/3, handle_cast/2, handle_info/2,code_change/3,stop/0]).
 -export([start_doc_map/2, map_docs/2, stop_doc_map/1]).
 
--export([test/0, test/1]).
+-export([test/0]).
 
 -include("couch_db.hrl").
 
@@ -26,7 +26,8 @@
     % hardcoded 5 sec timeout per document
     5000.
 
-start_link(QueryServerList) ->
+start_link() ->
+    QueryServerList = couch_config:lookup_match({{"CouchDB Query Servers", '$1'}, '$2'},
[]),
     gen_server:start_link({local, couch_query_servers}, couch_query_servers, QueryServerList,
[]).
 
 stop() ->
@@ -182,11 +183,11 @@
 code_change(_OldVsn, State, _Extra) ->
     {ok, State}.
 
-test() ->
-    test("../js/js -f main.js").
+% test() ->
+%     test("../js/js -f main.js").
 
-test(Cmd) ->
-    start_link(Cmd),
+test() ->
+    start_link(),
     {ok, DocMap} = start_doc_map("javascript", ["function(doc) {if (doc[0] == 'a') return
doc[1];}"]),
     {ok, Results} = map_docs(DocMap, [#doc{body={"a", "b"}}, #doc{body={"c", "d"}},#doc{body={"a",
"c"}}]),
     io:format("Results: ~w~n", [Results]),

Modified: incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server.erl?rev=655817&r1=655816&r2=655817&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server.erl Tue May 13 04:18:08
2008
@@ -16,7 +16,7 @@
 
 -export([start/0,start/1,start/2,stop/0,stop/1]).
 -export([open/1,create/2,delete/1,all_databases/0,get_version/0]).
--export([init/1, handle_call/3,sup_start_link/2]).
+-export([init/1, handle_call/3,sup_start_link/0]).
 -export([handle_cast/2,code_change/3,handle_info/2,terminate/2]).
 -export([dev_start/0,remote_restart/0]).
 
@@ -29,14 +29,10 @@
     }).
 
 start() ->
-    start("").
+    start([]).
 
-start(IniFile) when is_atom(IniFile) ->
-    couch_server_sup:start_link(atom_to_list(IniFile) ++ ".ini");
-start(IniNum) when is_integer(IniNum) ->
-    couch_server_sup:start_link("couch" ++ integer_to_list(IniNum) ++ ".ini");
-start(IniFile) ->
-    couch_server_sup:start_link(IniFile).
+start(IniFiles) ->
+    couch_server_sup:start_link(IniFiles).
 
 start(_Type, _Args) ->
     start().
@@ -61,7 +57,9 @@
         "0.0.0"
     end.
 
-sup_start_link(RootDir, Options) ->
+sup_start_link() ->
+    RootDir = couch_config:lookup({"CouchDB", "RootDirectory"}), 
+    Options = couch_config:lookup({"CouchDB", "ServerOptions"}), 
     gen_server:start_link({local, couch_server}, couch_server, {RootDir, Options}, []).
 
 open(Filename) ->

Modified: incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server_sup.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server_sup.erl?rev=655817&r1=655816&r2=655817&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server_sup.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server_sup.erl Tue May 13 04:18:08
2008
@@ -13,7 +13,6 @@
 -module(couch_server_sup).
 -behaviour(supervisor).
 
--define(DEFAULT_INI, "couch.ini").
 
 -export([start_link/1,stop/0]).
 
@@ -22,26 +21,17 @@
 %% supervisor callbacks
 -export([init/1]).
 
-start_link(IniFilename) ->
+start_link(IniFiles) ->
     case whereis(couch_server_sup) of
     undefined ->
-        start_server(IniFilename);
+        couch_config:start_link(),
+        couch_config:load_ini_files(IniFiles),
+        start_server();
     _Else ->
         {error, already_started}
     end.
 
-start_server("") ->
-        % no ini file specified, check the command line args
-    IniFile =
-    case init:get_argument(couchini) of
-    {ok, [CmdLineIniFilename]} ->
-        CmdLineIniFilename;
-    _Else ->
-        ?DEFAULT_INI
-    end,
-    start_server(IniFile);
-start_server(InputIniFilename) ->
-
+start_server() ->
     case init:get_argument(pidfile) of
     {ok, [PidFile]} ->
         case file:write_file(PidFile, os:getpid()) of
@@ -51,36 +41,12 @@
     _ -> ok
     end,
 
-    {ok, Cwd} = file:get_cwd(),
-    IniFilename = couch_util:abs_pathname(InputIniFilename),
-    IniBin =
-    case file:read_file(IniFilename) of
-    {ok, IniBin0} ->
-        IniBin0;
-    {error, enoent} ->
-        Msg = io_lib:format("Couldn't find server configuration file ~s.", [InputIniFilename]),
-        io:format("~s~n", [Msg]),
-        throw({startup_error, Msg})
-    end,
-    {ok, Ini} = couch_util:parse_ini(binary_to_list(IniBin)),
-
-    ConsoleStartupMsg = proplists:get_value({"Couch", "ConsoleStartupMsg"}, Ini, "Apache
CouchDB is starting."),
-    LogLevel = list_to_atom(proplists:get_value({"Couch", "LogLevel"}, Ini, "error")),
-    DbRootDir = proplists:get_value({"Couch", "DbRootDir"}, Ini, "."),
-    BindAddress = proplists:get_value({"Couch", "BindAddress"}, Ini, any),
-    Port = proplists:get_value({"Couch", "Port"}, Ini, 5984),
-    DocumentRoot = proplists:get_value({"Couch", "DocumentRoot"}, Ini, "share/www"),
-    LogFile = proplists:get_value({"Couch", "LogFile"}, Ini, "couchdb.log"),
-    UtilDriverDir = proplists:get_value({"Couch", "UtilDriverDir"}, Ini, ""),
-    UpdateNotifierExes = proplists:get_all_values({"Couch", "DbUpdateNotificationProcess"},
Ini),
-    FtSearchQueryServer = proplists:get_value({"Couch", "FullTextSearchQueryServer"}, Ini,
""),
-    RemoteRestart = list_to_atom(proplists:get_value({"Couch", "AllowRemoteRestart"}, Ini,
"undefined")),
-    ServerOptions = [{remote_restart, RemoteRestart}],
-    QueryServers = [{Lang, QueryExe} || {{"Couch Query Servers", Lang}, QueryExe} <- Ini],
-    
+    ConsoleStartupMsg = couch_config:lookup({"CouchDB", "ConsoleStartupMsg"}),
+    UpdateNotificationProcesses = couch_config:lookup({"CouchDB", "UpdateNotificationProcesses"},
[]),
+    FtSearchQueryServer = couch_config:lookup({"Fulltext", "QueryServer"}, []),
     ChildProcesses =
         [{couch_log,
-            {couch_log, start_link, [LogFile, LogLevel]},
+            {couch_log, start_link, []},
             permanent,
             brutal_kill,
             worker,
@@ -92,38 +58,44 @@
             supervisor,
             dynamic},
         {couch_server,
-            {couch_server, sup_start_link, [DbRootDir, ServerOptions]},
+            {couch_server, sup_start_link, []},
             permanent,
             brutal_kill,
             worker,
             [couch_server]},
+        % {couch_util,
+        %     {couch_util, start_link, []},
+        %     permanent,
+        %     brutal_kill,
+        %     worker,
+        %     [couch_util]},
         {couch_query_servers,
-            {couch_query_servers, start_link, [QueryServers]},
+            {couch_query_servers, start_link, []},
             permanent,
             brutal_kill,
             worker,
             [couch_query_servers]},
         {couch_view,
-            {couch_view, start_link, [DbRootDir]},
+            {couch_view, start_link, []},
             permanent,
             brutal_kill,
             worker,
             [couch_view]},
         {couch_httpd,
-            {couch_httpd, start_link, [BindAddress, Port, DocumentRoot]},
+            {couch_httpd, start_link, []},
             permanent,
             1000,
             supervisor,
             [couch_httpd]}
         ] ++
-        lists:map(fun(UpdateNotifierExe) ->
-            {UpdateNotifierExe,
-                {couch_db_update_notifier, start_link, [UpdateNotifierExe]},
+        lists:map(fun(UpdateNotificationProcess) when is_list(UpdateNotificationProcesses)
->
+            {UpdateNotificationProcess,
+                {couch_db_update_notifier, start_link, [UpdateNotificationProcess]},
                 permanent,
                 1000,
                 supervisor,
                 [couch_db_update_notifier]}
-            end, UpdateNotifierExes)
+            end, UpdateNotificationProcesses)
         ++
         case FtSearchQueryServer of
         "" ->
@@ -137,10 +109,10 @@
                 [couch_ft_query]}]
         end,
 
-    io:format("couch ~s (LogLevel=~s)~n", [couch_server:get_version(), LogLevel]),
     io:format("~s~n", [ConsoleStartupMsg]),
     
-    couch_util:start_driver(UtilDriverDir),
+    
+    couch_util:start_driver(),
     
     % ensure these applications are running
     application:start(inets),
@@ -150,44 +122,49 @@
     StartResult = (catch supervisor:start_link(
         {local, couch_server_sup}, couch_server_sup, ChildProcesses)),
 
-    ConfigInfo = io_lib:format("Config Info ~s:~n\tCurrentWorkingDir=~s~n" ++
-        "\tDbRootDir=~s~n" ++
-        "\tBindAddress=~p~n" ++
-        "\tPort=~p~n" ++
-        "\tDocumentRoot=~s~n" ++
-        "\tLogFile=~s~n" ++
-        "\tUtilDriverDir=~s~n" ++
-        "\tDbUpdateNotificationProcesses=~s~n" ++
-        "\tFullTextSearchQueryServer=~s~n" ++
-        "~s",
-            [IniFilename,
-            Cwd,
-            DbRootDir,
-            BindAddress,
-            Port,
-            DocumentRoot,
-            LogFile,
-            UtilDriverDir,
-            UpdateNotifierExes,
-            FtSearchQueryServer,
-            [lists:flatten(io_lib:format("\t~s=~s~n", [Lang, QueryExe])) || {Lang, QueryExe}
<- QueryServers]]),
-    ?LOG_DEBUG("~s", [ConfigInfo]),
-
     case StartResult of
     {ok,_} ->
         % only output when startup was successful
         io:format("Apache CouchDB has started. Time to relax.~n");
     _ ->
         % Since we failed startup, unconditionally dump configuration data to console
-        io:format("~s", [ConfigInfo]),
-        ok
+        ok = couch_config:dump()
     end,
     process_flag(trap_exit, false),
     StartResult.
 
 stop() ->
     catch exit(whereis(couch_server_sup), normal),
+    couch_config:stop(),
     couch_log:stop().
 
 init(ChildProcesses) ->
     {ok, {{one_for_one, 10, 3600}, ChildProcesses}}.
+
+% dump_config() ->
+%     io:format("Debug: ~p~n", [dying]),
+%     ?LOG_DEBUG("~s", [okay]).
+%     % {ok, Cwd} = file:get_cwd(),
+%     % ConfigInfo = io_lib:format("Config Info:~n\tCurrentWorkingDir=~s~n" ++
+%     %        "\tDbRootDir=~s~n" ++
+%     %        "\tBindAddress=~p~n" ++
+%     %        "\tPort=~p~n" ++
+%     %        "\tDocumentRoot=~s~n" ++
+%     %        "\tLogFile=~s~n" ++
+%     %        "\tLogLevel=~s~n" ++
+%     %        "\tUtilDriverDir=~s~n" ++
+%     %        "\tDbUpdateNotificationProcesses=~s~n" ++
+%     %        "\tFullTextSearchQueryServer=~s~n" ++
+%     %        "~s",
+%     %            [Cwd,
+%     %            couch_config:lookup({couchdb, root_directory}),
+%     %            couch_config:lookup({couchdb, util_driver_dir}),
+%     %            couch_config:lookup({couchdb, update_notification_processes}),
+%     %            couch_config:lookup({httpd, bind_address}),
+%     %            couch_config:lookup({httpd, port}),
+%     %            couch_config:lookup({httpd, document_root}),
+%     %            couch_config:lookup({log, file}),
+%     %            couch_config:lookup({log, level}),
+%     %            couch_config:lookup({fulltext, query_server}),
+%     %            [lists:flatten(io_lib:format("\t~s=~s~n", [Lang, QueryExe])) || {Lang,
QueryExe} <- couch_config:lookup({couchdb, view_query_servers})]]),
+%     %            ?LOG_INFO("~s", [ConfigInfo]).
\ No newline at end of file

Modified: incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_util.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_util.erl?rev=655817&r1=655816&r2=655817&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_util.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_util.erl Tue May 13 04:18:08
2008
@@ -12,8 +12,8 @@
 
 -module(couch_util).
 
--export([start_driver/1]).
--export([parse_ini/1,should_flush/0, should_flush/1]).
+-export([start_driver/0]).
+-export([should_flush/0, should_flush/1]).
 -export([new_uuid/0, rand32/0, implode/2, collate/2, collate/3]).
 -export([abs_pathname/1,abs_pathname/2, trim/1, ascii_lower/1]).
 -export([encodeBase64/1, decodeBase64/1]).
@@ -22,16 +22,21 @@
 % arbitrarily chosen amount of memory to use before flushing to disk
 -define(FLUSH_MAX_MEM, 10000000).
 
-start_driver("") ->
-    start_driver(filename:join(code:priv_dir(couch), "lib"));
-start_driver(LibDir) ->
+start_driver() ->
+    LibDir1 = couch_config:lookup({"CouchDB", "UtilDriverDir"}),
+    case LibDir1 of
+        null ->
+            LibDir = filename:join(code:priv_dir(couch), "lib");
+        _ ->
+            LibDir = LibDir1
+    end,
+
     case erl_ddll:load_driver(LibDir, "couch_erl_driver") of
     ok -> ok;
     {error, already_loaded} -> ok;
     Error -> exit(Error)
     end.
 
-
 new_uuid() ->
     to_hex(binary_to_list(crypto:rand_bytes(16))).
 
@@ -157,34 +162,6 @@
 % {{"Another Section", "oops"}, "\"it doesn't qet quoted strings with semis quite right"}]
 %
 
-parse_ini(FileContents) ->
-    {ok, Lines} = regexp:split(FileContents, "\r\n|\n|\r|\032"),
-    {_, ParsedIniValues} =
-    lists:foldl(fun(Line, {AccSectionName, AccValues}) ->
-            case string:strip(Line) of
-            "[" ++ Rest ->
-                case regexp:split(Rest, "\\]") of
-                {ok, [NewSectionName, ""]} ->
-                    {NewSectionName, AccValues};
-                _Else -> % end bracket not at end, ignore this line
-                    {AccSectionName, AccValues}
-                end;
-            ";" ++ _Comment ->
-                {AccSectionName, AccValues};
-            Line2 ->
-                case regexp:split(Line2, "=") of
-                {ok, [_SingleElement]} -> % no "=" found, ignore this line
-                    {AccSectionName, AccValues};
-                {ok, [""|_LineValues]} -> % line begins with "=", ignore
-                    {AccSectionName, AccValues};
-                {ok, [ValueName|LineValues]} -> % yeehaw, got a line!
-                    RemainingLine = implode(LineValues, "="),
-                    {ok, [LineValue | _Rest]} = regexp:split(RemainingLine, " ;|\t;"), %
removes comments
-                    {AccSectionName, [{{AccSectionName, ValueName}, LineValue} | AccValues]}
-                end
-            end
-        end, {"", []}, Lines),
-    {ok, lists:reverse(ParsedIniValues)}.
 
 drv_port() ->
     case get(couch_drv_port) of
@@ -293,5 +270,3 @@
 
 dec(C) ->
     62*?st(C,43) + ?st(C,47) + (C-59)*?st(C,48) - 69*?st(C,65) - 6*?st(C,97).
-
-

Modified: incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_view.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_view.erl?rev=655817&r1=655816&r2=655817&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_view.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_view.erl Tue May 13 04:18:08
2008
@@ -15,7 +15,7 @@
 -module(couch_view).
 -behaviour(gen_server).
 
--export([start_link/1,fold/4,fold/5,less_json/2, start_update_loop/3, start_temp_update_loop/4]).
+-export([start_link/0,fold/4,fold/5,less_json/2, start_update_loop/3, start_temp_update_loop/4]).
 -export([init/1,terminate/2,handle_call/3,handle_cast/2,handle_info/2,code_change/3]).
 
 -include("couch_db.hrl").
@@ -42,7 +42,8 @@
     {root_dir
     }).
 
-start_link(RootDir) ->
+start_link() ->
+    RootDir = couch_config:lookup({"CouchDB", "RootDirectory"}),
     gen_server:start_link({local, couch_view}, couch_view, RootDir, []).
 
 



Mime
View raw message