diff options
author | Adam Kocoloski <kocolosk@apache.org> | 2009-08-30 17:56:56 +0000 |
---|---|---|
committer | Adam Kocoloski <kocolosk@apache.org> | 2009-08-30 17:56:56 +0000 |
commit | 6c5a22e7afd7530148f3eef6d4722cd725f28851 (patch) | |
tree | 80862f0920c1f7cb55e7279fd5acfbc27286194a /src/couchdb | |
parent | 422d815b3baf1a0152429d02257aeaeaf6fa471c (diff) |
refactor CouchDB startup procedure, see COUCHDB-216 for details
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@809392 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb')
-rw-r--r-- | src/couchdb/Makefile.am | 11 | ||||
-rw-r--r-- | src/couchdb/couch.app.tpl.in | 58 | ||||
-rw-r--r-- | src/couchdb/couch.erl | 39 | ||||
-rw-r--r-- | src/couchdb/couch_app.erl | 53 | ||||
-rw-r--r-- | src/couchdb/couch_server.erl | 25 |
5 files changed, 135 insertions, 51 deletions
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(), |