summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/couchdb.bat.tpl.in6
-rw-r--r--bin/couchdb.tpl.in22
-rw-r--r--src/couchdb/Makefile.am11
-rw-r--r--src/couchdb/couch.app.tpl.in58
-rw-r--r--src/couchdb/couch.erl39
-rw-r--r--src/couchdb/couch_app.erl53
-rw-r--r--src/couchdb/couch_server.erl25
7 files changed, 140 insertions, 74 deletions
diff --git a/bin/couchdb.bat.tpl.in b/bin/couchdb.bat.tpl.in
index 6c1f3aed..9be38137 100644
--- a/bin/couchdb.bat.tpl.in
+++ b/bin/couchdb.bat.tpl.in
@@ -19,8 +19,4 @@ rem Allow a different erlang executable (eg, werl) to be used.
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
diff --git a/bin/couchdb.tpl.in b/bin/couchdb.tpl.in
index 6f22495c..14f989a6 100644
--- a/bin/couchdb.tpl.in
+++ b/bin/couchdb.tpl.in
@@ -106,9 +106,6 @@ _get_pid () {
}
_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 @@ $1
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 @@ start_couchdb () {
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 &
diff --git a/src/couchdb/Makefile.am b/src/couchdb/Makefile.am
index 13b20c10..95c523c4 100644
--- a/src/couchdb/Makefile.am
+++ b/src/couchdb/Makefile.am
@@ -56,6 +56,8 @@ CLEANFILES = $(compiled_files) $(doc_base)
# 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 @@ EXTRA_DIST = $(source_files) couch_db.hrl couch_stats.hrl
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 @@ compiled_files = \
# 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 $@
diff --git a/src/couchdb/couch.app.tpl.in b/src/couchdb/couch.app.tpl.in
index e0100cb4..84ac36ee 100644
--- a/src/couchdb/couch.app.tpl.in
+++ b/src/couchdb/couch.app.tpl.in
@@ -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
diff --git a/src/couchdb/couch.erl b/src/couchdb/couch.erl
new file mode 100644
index 00000000..956e9489
--- /dev/null
+++ b/src/couchdb/couch.erl
@@ -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.
diff --git a/src/couchdb/couch_app.erl b/src/couchdb/couch_app.erl
new file mode 100644
index 00000000..98615e50
--- /dev/null
+++ b/src/couchdb/couch_app.erl
@@ -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.
diff --git a/src/couchdb/couch_server.erl b/src/couchdb/couch_server.erl
index 23de5284..93ba67d0 100644
--- a/src/couchdb/couch_server.erl
+++ b/src/couchdb/couch_server.erl
@@ -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(),