couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kocol...@apache.org
Subject svn commit: r809392 - in /couchdb/trunk: bin/couchdb.bat.tpl.in bin/couchdb.tpl.in src/couchdb/Makefile.am src/couchdb/couch.app.tpl.in src/couchdb/couch.erl src/couchdb/couch_app.erl src/couchdb/couch_server.erl
Date Sun, 30 Aug 2009 17:56:57 GMT
Author: kocolosk
Date: Sun Aug 30 17:56:56 2009
New Revision: 809392

URL: http://svn.apache.org/viewvc?rev=809392&view=rev
Log:
refactor CouchDB startup procedure, see COUCHDB-216 for details

Added:
    couchdb/trunk/src/couchdb/couch.erl
    couchdb/trunk/src/couchdb/couch_app.erl
Modified:
    couchdb/trunk/bin/couchdb.bat.tpl.in
    couchdb/trunk/bin/couchdb.tpl.in
    couchdb/trunk/src/couchdb/Makefile.am
    couchdb/trunk/src/couchdb/couch.app.tpl.in
    couchdb/trunk/src/couchdb/couch_server.erl

Modified: couchdb/trunk/bin/couchdb.bat.tpl.in
URL: http://svn.apache.org/viewvc/couchdb/trunk/bin/couchdb.bat.tpl.in?rev=809392&r1=809391&r2=809392&view=diff
==============================================================================
--- couchdb/trunk/bin/couchdb.bat.tpl.in (original)
+++ couchdb/trunk/bin/couchdb.bat.tpl.in Sun Aug 30 17:56:56 2009
@@ -19,8 +19,4 @@
 if "%ERL%x" == "x" set ERL=erl.exe
 
 echo CouchDB %version% - prepare to relax...
-%ERL% -smp auto -sasl errlog_type error ^
-      -eval "application:load(crypto)" ^
-      -eval "application:load(couch)" ^
-      -eval "crypto:start()" ^
-      -eval "couch_server:start([""../etc/couchdb/default.ini"", ""../etc/couchdb/local.ini""]),
receive done -> done end."
+%ERL% -sasl errlog_type error -s couch

Modified: couchdb/trunk/bin/couchdb.tpl.in
URL: http://svn.apache.org/viewvc/couchdb/trunk/bin/couchdb.tpl.in?rev=809392&r1=809391&r2=809392&view=diff
==============================================================================
--- couchdb/trunk/bin/couchdb.tpl.in (original)
+++ couchdb/trunk/bin/couchdb.tpl.in Sun Aug 30 17:56:56 2009
@@ -106,9 +106,6 @@
 }
 
 _add_config_file () {
-    if test -n "$start_arguments"; then
-        start_arguments="$start_arguments, ";
-    fi
     if test -z "$print_arguments"; then
         print_arguments="$1"
     else
@@ -118,12 +115,12 @@
 EOF
 `"
     fi
-    start_arguments="$start_arguments \\\"$1\\\""
+    start_arguments="$start_arguments $1"
     background_start_arguments="$background_start_arguments -a \\\"$1\\\""
 }
 
 _add_config_dir () {
-    for file in `find "$1" -mindepth 1 -maxdepth 1 -type f`; do
+    for file in `find "$1" -mindepth 1 -maxdepth 1 -type f -name *.ini`; do
         _add_config_file $file
     done
 }
@@ -214,19 +211,8 @@
         touch $PID_FILE
         interactive_option="+Bd -noinput"
     fi
-    command="`%ICU_CONFIG% --invoke` \
-        %ERL% $interactive_option -smp auto -sasl errlog_type error +K true \
-        -pa %localerlanglibdir%/%couchdbebindir% \
-            %localerlanglibdir%/%mochiwebebindir% \
-            %localerlanglibdir%/%ibrowseebindir% \
-            %localerlanglibdir%/%oauthebindir% \
-        -eval \"application:load(ibrowse)\" \
-        -eval \"application:load(oauth)\" \
-        -eval \"application:load(crypto)\" \
-        -eval \"application:load(couch)\" \
-        -eval \"crypto:start()\" \
-        -eval \"ibrowse:start()\" \
-        -eval \"couch_server:start([$start_arguments]), receive done -> done end.\" "
+    command="%ERL% $interactive_option -sasl errlog_type error +K true \
+        -env ERL_LIBS %localerlanglibdir% -couch_ini $start_arguments -s couch"
     if test "$BACKGROUND" = "true" -a "$RECURSED" = "false"; then
         $0 $background_start_arguments -b -r $RESPAWN_TIMEOUT -p $PID_FILE \
             -o $STDOUT_FILE -e $STDERR_FILE -R &

Modified: couchdb/trunk/src/couchdb/Makefile.am
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/Makefile.am?rev=809392&r1=809391&r2=809392&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/Makefile.am (original)
+++ couchdb/trunk/src/couchdb/Makefile.am Sun Aug 30 17:56:56 2009
@@ -56,6 +56,8 @@
 # CLEANFILES = $(doc_modules) edoc-info
 
 source_files = \
+    couch.erl \
+    couch_app.erl \
     couch_btree.erl \
     couch_batch_save.erl \
     couch_batch_save_sup.erl \
@@ -109,6 +111,8 @@
 
 compiled_files = \
     couch.app \
+    couch.beam \
+    couch_app.beam \
     couch_btree.beam \
     couch_batch_save.beam \
     couch_batch_save_sup.beam \
@@ -189,8 +193,13 @@
 #     couch_view.html
 
 couch.app: couch.app.tpl
+	modules=`find . -name "*.erl" -exec basename -s .erl {} \; | tr '\n' ',' | sed "s/,$$//"`;
\
 	sed -e "s|%package_name%|@package_name@|g" \
-	    -e "s|%version%|@version@|g" > \
+	    -e "s|%version%|@version@|g" \
+	    -e "s|@modules@|$$modules|g" \
+	    -e "s|%localconfdir%|@localconfdir@|g" \
+	    -e "s|@defaultini@|default.ini|g" \
+	    -e "s|@localini@|local.ini|g" > \
 	$@ < $<
 	chmod +x $@
 

Modified: couchdb/trunk/src/couchdb/couch.app.tpl.in
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch.app.tpl.in?rev=809392&r1=809391&r2=809392&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch.app.tpl.in (original)
+++ couchdb/trunk/src/couchdb/couch.app.tpl.in Sun Aug 30 17:56:56 2009
@@ -1,27 +1,31 @@
-{application,couch,
-             [{description,"@package_name@"},
-              {vsn,"@version@"},
-              {modules,[couch_btree,
-                        couch_db,
-                        couch_db_updater,
-                        couch_doc,
-                        couch_query_servers,
-                        couch_file,
-                        couch_server,
-                        couch_server_sup,
-                        couch_stream,
-                        couch_key_tree,
-                        couch_view,
-                        couch_util,
-                        couch_httpd,
-                        couch_event_sup,
-                        couch_db_update_notifier,
-                        couch_db_update_notifier_sup,
-                        couch_log,
-                        couch_rep]},
-              {registered,[couch_server,
-                           couch_server_sup,
-                           couch_view,
-                           couch_query_servers,
-                           couch_db_update_notifier_sup]},
-              {applications,[kernel,stdlib,crypto,ibrowse,mochiweb]}]}.
+{application, couch, [
+    {description, "@package_name@"},
+    {vsn, "@version@"},
+    {modules, [@modules@]},
+    {registered, [
+        couch_batch_save,
+        couch_batch_save_sup,
+        couch_config,
+        couch_db_update,
+        couch_db_update_notifier_sup,
+        couch_external_manager,
+        couch_httpd,
+        couch_log,
+        couch_primary_services,
+        couch_query_servers,
+        couch_rep_sup,
+        couch_secondary_services,
+        couch_server,
+        couch_server_sup,
+        couch_stats_aggregator,
+        couch_stats_collector,
+        couch_task_status,
+        couch_view
+    ]},
+    {mod, {couch_app, [
+        "%localconfdir%/@defaultini@",
+        "%localconfdir%/@localini@"
+    ]}},
+    {applications, [kernel, stdlib]},
+    {included_applications, [crypto, sasl, inets, oauth, ibrowse, mochiweb]}
+]}.
\ No newline at end of file

Added: couchdb/trunk/src/couchdb/couch.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch.erl?rev=809392&view=auto
==============================================================================
--- couchdb/trunk/src/couchdb/couch.erl (added)
+++ couchdb/trunk/src/couchdb/couch.erl Sun Aug 30 17:56:56 2009
@@ -0,0 +1,39 @@
+% 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).
+
+-compile(export_all).
+
+start() ->
+    application:start(couch).
+
+stop() ->
+    application:stop(couch).
+
+restart() ->
+    case stop() of
+    ok ->
+        start();
+    {error, {not_started,couch}} ->
+        start();
+    {error, Reason} ->
+        {error, Reason}
+    end.
+
+reload() ->
+    case supervisor:terminate_child(couch_server_sup, couch_config) of
+    ok ->
+        supervisor:restart_child(couch_server_sup, couch_config);
+    {error, Reason} ->
+        {error, Reason}
+    end.

Added: couchdb/trunk/src/couchdb/couch_app.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_app.erl?rev=809392&view=auto
==============================================================================
--- couchdb/trunk/src/couchdb/couch_app.erl (added)
+++ couchdb/trunk/src/couchdb/couch_app.erl Sun Aug 30 17:56:56 2009
@@ -0,0 +1,53 @@
+% 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_app).
+
+-behaviour(application).
+
+-include("couch_db.hrl").
+
+-export([start/2, stop/1]).
+
+start(_Type, DefaultIniFiles) ->
+    IniFiles = get_ini_files(DefaultIniFiles),
+    case start_apps([crypto, sasl, inets, oauth, ibrowse, mochiweb]) of
+    ok ->
+        couch_server_sup:start_link(IniFiles);
+    {error, Reason} ->
+        {error, Reason}
+    end.
+
+stop(_) ->
+    ok.
+
+get_ini_files(Default) ->
+    case init:get_argument(couch_ini) of
+    error ->
+        Default;
+    {ok, [[]]} ->
+        Default;
+    {ok, [Values]} ->
+        Values
+    end.
+
+start_apps([]) ->
+    ok;
+start_apps([App|Rest]) ->
+    case application:start(App) of
+    ok ->
+       start_apps(Rest);
+    {error, {already_started, App}} ->
+       start_apps(Rest);
+    {error, _Reason} ->
+       {error, {app_would_not_start, App}}
+    end.

Modified: couchdb/trunk/src/couchdb/couch_server.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_server.erl?rev=809392&r1=809391&r2=809392&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_server.erl (original)
+++ couchdb/trunk/src/couchdb/couch_server.erl Sun Aug 30 17:56:56 2009
@@ -12,9 +12,7 @@
 
 -module(couch_server).
 -behaviour(gen_server).
--behaviour(application).
 
--export([start/0,start/1,start/2,stop/0,stop/1,restart/0]).
 -export([open/2,create/2,delete/2,all_databases/0,get_version/0]).
 -export([init/1, handle_call/3,sup_start_link/0]).
 -export([handle_cast/2,code_change/3,handle_info/2,terminate/2]).
@@ -30,29 +28,10 @@
     start_time=""
     }).
 
-start() ->
-    start(["default.ini"]).
-
-start(IniFiles) ->
-    couch_server_sup:start_link(IniFiles).
-
-start(_Type, _Args) ->
-    start().
-
-restart() ->
-    stop(),
-    start().
-
-stop() ->
-    couch_server_sup:stop().
-
-stop(_Reason) ->
-    stop().
-
 dev_start() ->
-    stop(),
+    couch:stop(),
     up_to_date = make:all([load, debug_info]),
-    start().
+    couch:start().
 
 get_version() ->
     Apps = application:loaded_applications(),



Mime
View raw message