Skip to content
This repository
Browse code

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
  • Loading branch information...
commit 6c5a22e7afd7530148f3eef6d4722cd725f28851 1 parent 422d815
Adam Kocoloski kocolosk authored
6 bin/couchdb.bat.tpl.in
@@ -19,8 +19,4 @@ rem Allow a different erlang executable (eg, werl) to be used.
19 19 if "%ERL%x" == "x" set ERL=erl.exe
20 20
21 21 echo CouchDB %version% - prepare to relax...
22   -%ERL% -smp auto -sasl errlog_type error ^
23   - -eval "application:load(crypto)" ^
24   - -eval "application:load(couch)" ^
25   - -eval "crypto:start()" ^
26   - -eval "couch_server:start([""../etc/couchdb/default.ini"", ""../etc/couchdb/local.ini""]), receive done -> done end."
  22 +%ERL% -sasl errlog_type error -s couch
22 bin/couchdb.tpl.in
@@ -106,9 +106,6 @@ _get_pid () {
106 106 }
107 107
108 108 _add_config_file () {
109   - if test -n "$start_arguments"; then
110   - start_arguments="$start_arguments, ";
111   - fi
112 109 if test -z "$print_arguments"; then
113 110 print_arguments="$1"
114 111 else
@@ -118,12 +115,12 @@ $1
118 115 EOF
119 116 `"
120 117 fi
121   - start_arguments="$start_arguments \\\"$1\\\""
  118 + start_arguments="$start_arguments $1"
122 119 background_start_arguments="$background_start_arguments -a \\\"$1\\\""
123 120 }
124 121
125 122 _add_config_dir () {
126   - for file in `find "$1" -mindepth 1 -maxdepth 1 -type f`; do
  123 + for file in `find "$1" -mindepth 1 -maxdepth 1 -type f -name *.ini`; do
127 124 _add_config_file $file
128 125 done
129 126 }
@@ -214,19 +211,8 @@ start_couchdb () {
214 211 touch $PID_FILE
215 212 interactive_option="+Bd -noinput"
216 213 fi
217   - command="`%ICU_CONFIG% --invoke` \
218   - %ERL% $interactive_option -smp auto -sasl errlog_type error +K true \
219   - -pa %localerlanglibdir%/%couchdbebindir% \
220   - %localerlanglibdir%/%mochiwebebindir% \
221   - %localerlanglibdir%/%ibrowseebindir% \
222   - %localerlanglibdir%/%oauthebindir% \
223   - -eval \"application:load(ibrowse)\" \
224   - -eval \"application:load(oauth)\" \
225   - -eval \"application:load(crypto)\" \
226   - -eval \"application:load(couch)\" \
227   - -eval \"crypto:start()\" \
228   - -eval \"ibrowse:start()\" \
229   - -eval \"couch_server:start([$start_arguments]), receive done -> done end.\" "
  214 + command="%ERL% $interactive_option -sasl errlog_type error +K true \
  215 + -env ERL_LIBS %localerlanglibdir% -couch_ini $start_arguments -s couch"
230 216 if test "$BACKGROUND" = "true" -a "$RECURSED" = "false"; then
231 217 $0 $background_start_arguments -b -r $RESPAWN_TIMEOUT -p $PID_FILE \
232 218 -o $STDOUT_FILE -e $STDERR_FILE -R &
11 src/couchdb/Makefile.am
@@ -56,6 +56,8 @@ CLEANFILES = $(compiled_files) $(doc_base)
56 56 # CLEANFILES = $(doc_modules) edoc-info
57 57
58 58 source_files = \
  59 + couch.erl \
  60 + couch_app.erl \
59 61 couch_btree.erl \
60 62 couch_batch_save.erl \
61 63 couch_batch_save_sup.erl \
@@ -109,6 +111,8 @@ EXTRA_DIST = $(source_files) couch_db.hrl couch_stats.hrl
109 111
110 112 compiled_files = \
111 113 couch.app \
  114 + couch.beam \
  115 + couch_app.beam \
112 116 couch_btree.beam \
113 117 couch_batch_save.beam \
114 118 couch_batch_save_sup.beam \
@@ -189,8 +193,13 @@ compiled_files = \
189 193 # couch_view.html
190 194
191 195 couch.app: couch.app.tpl
  196 + modules=`find . -name "*.erl" -exec basename -s .erl {} \; | tr '\n' ',' | sed "s/,$$//"`; \
192 197 sed -e "s|%package_name%|@package_name@|g" \
193   - -e "s|%version%|@version@|g" > \
  198 + -e "s|%version%|@version@|g" \
  199 + -e "s|@modules@|$$modules|g" \
  200 + -e "s|%localconfdir%|@localconfdir@|g" \
  201 + -e "s|@defaultini@|default.ini|g" \
  202 + -e "s|@localini@|local.ini|g" > \
194 203 $@ < $<
195 204 chmod +x $@
196 205
58 src/couchdb/couch.app.tpl.in
... ... @@ -1,27 +1,31 @@
1   -{application,couch,
2   - [{description,"@package_name@"},
3   - {vsn,"@version@"},
4   - {modules,[couch_btree,
5   - couch_db,
6   - couch_db_updater,
7   - couch_doc,
8   - couch_query_servers,
9   - couch_file,
10   - couch_server,
11   - couch_server_sup,
12   - couch_stream,
13   - couch_key_tree,
14   - couch_view,
15   - couch_util,
16   - couch_httpd,
17   - couch_event_sup,
18   - couch_db_update_notifier,
19   - couch_db_update_notifier_sup,
20   - couch_log,
21   - couch_rep]},
22   - {registered,[couch_server,
23   - couch_server_sup,
24   - couch_view,
25   - couch_query_servers,
26   - couch_db_update_notifier_sup]},
27   - {applications,[kernel,stdlib,crypto,ibrowse,mochiweb]}]}.
  1 +{application, couch, [
  2 + {description, "@package_name@"},
  3 + {vsn, "@version@"},
  4 + {modules, [@modules@]},
  5 + {registered, [
  6 + couch_batch_save,
  7 + couch_batch_save_sup,
  8 + couch_config,
  9 + couch_db_update,
  10 + couch_db_update_notifier_sup,
  11 + couch_external_manager,
  12 + couch_httpd,
  13 + couch_log,
  14 + couch_primary_services,
  15 + couch_query_servers,
  16 + couch_rep_sup,
  17 + couch_secondary_services,
  18 + couch_server,
  19 + couch_server_sup,
  20 + couch_stats_aggregator,
  21 + couch_stats_collector,
  22 + couch_task_status,
  23 + couch_view
  24 + ]},
  25 + {mod, {couch_app, [
  26 + "%localconfdir%/@defaultini@",
  27 + "%localconfdir%/@localini@"
  28 + ]}},
  29 + {applications, [kernel, stdlib]},
  30 + {included_applications, [crypto, sasl, inets, oauth, ibrowse, mochiweb]}
  31 +]}.
39 src/couchdb/couch.erl
... ... @@ -0,0 +1,39 @@
  1 +% Licensed under the Apache License, Version 2.0 (the "License"); you may not
  2 +% use this file except in compliance with the License. You may obtain a copy of
  3 +% the License at
  4 +%
  5 +% http://www.apache.org/licenses/LICENSE-2.0
  6 +%
  7 +% Unless required by applicable law or agreed to in writing, software
  8 +% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  9 +% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  10 +% License for the specific language governing permissions and limitations under
  11 +% the License.
  12 +
  13 +-module(couch).
  14 +
  15 +-compile(export_all).
  16 +
  17 +start() ->
  18 + application:start(couch).
  19 +
  20 +stop() ->
  21 + application:stop(couch).
  22 +
  23 +restart() ->
  24 + case stop() of
  25 + ok ->
  26 + start();
  27 + {error, {not_started,couch}} ->
  28 + start();
  29 + {error, Reason} ->
  30 + {error, Reason}
  31 + end.
  32 +
  33 +reload() ->
  34 + case supervisor:terminate_child(couch_server_sup, couch_config) of
  35 + ok ->
  36 + supervisor:restart_child(couch_server_sup, couch_config);
  37 + {error, Reason} ->
  38 + {error, Reason}
  39 + end.
53 src/couchdb/couch_app.erl
... ... @@ -0,0 +1,53 @@
  1 +% Licensed under the Apache License, Version 2.0 (the "License"); you may not
  2 +% use this file except in compliance with the License. You may obtain a copy of
  3 +% the License at
  4 +%
  5 +% http://www.apache.org/licenses/LICENSE-2.0
  6 +%
  7 +% Unless required by applicable law or agreed to in writing, software
  8 +% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  9 +% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  10 +% License for the specific language governing permissions and limitations under
  11 +% the License.
  12 +
  13 +-module(couch_app).
  14 +
  15 +-behaviour(application).
  16 +
  17 +-include("couch_db.hrl").
  18 +
  19 +-export([start/2, stop/1]).
  20 +
  21 +start(_Type, DefaultIniFiles) ->
  22 + IniFiles = get_ini_files(DefaultIniFiles),
  23 + case start_apps([crypto, sasl, inets, oauth, ibrowse, mochiweb]) of
  24 + ok ->
  25 + couch_server_sup:start_link(IniFiles);
  26 + {error, Reason} ->
  27 + {error, Reason}
  28 + end.
  29 +
  30 +stop(_) ->
  31 + ok.
  32 +
  33 +get_ini_files(Default) ->
  34 + case init:get_argument(couch_ini) of
  35 + error ->
  36 + Default;
  37 + {ok, [[]]} ->
  38 + Default;
  39 + {ok, [Values]} ->
  40 + Values
  41 + end.
  42 +
  43 +start_apps([]) ->
  44 + ok;
  45 +start_apps([App|Rest]) ->
  46 + case application:start(App) of
  47 + ok ->
  48 + start_apps(Rest);
  49 + {error, {already_started, App}} ->
  50 + start_apps(Rest);
  51 + {error, _Reason} ->
  52 + {error, {app_would_not_start, App}}
  53 + end.
25 src/couchdb/couch_server.erl
@@ -12,9 +12,7 @@
12 12
13 13 -module(couch_server).
14 14 -behaviour(gen_server).
15   --behaviour(application).
16 15
17   --export([start/0,start/1,start/2,stop/0,stop/1,restart/0]).
18 16 -export([open/2,create/2,delete/2,all_databases/0,get_version/0]).
19 17 -export([init/1, handle_call/3,sup_start_link/0]).
20 18 -export([handle_cast/2,code_change/3,handle_info/2,terminate/2]).
@@ -30,29 +28,10 @@
30 28 start_time=""
31 29 }).
32 30
33   -start() ->
34   - start(["default.ini"]).
35   -
36   -start(IniFiles) ->
37   - couch_server_sup:start_link(IniFiles).
38   -
39   -start(_Type, _Args) ->
40   - start().
41   -
42   -restart() ->
43   - stop(),
44   - start().
45   -
46   -stop() ->
47   - couch_server_sup:stop().
48   -
49   -stop(_Reason) ->
50   - stop().
51   -
52 31 dev_start() ->
53   - stop(),
  32 + couch:stop(),
54 33 up_to_date = make:all([load, debug_info]),
55   - start().
  34 + couch:start().
56 35
57 36 get_version() ->
58 37 Apps = application:loaded_applications(),

0 comments on commit 6c5a22e

Please sign in to comment.
Something went wrong with that request. Please try again.