couch_server_sup -> couch_sup
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/fab1bad0 Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/fab1bad0 Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/fab1bad0 Branch: refs/heads/1994-merge-rcouch Commit: fab1bad0913bc42ee8dcb4fb3cec2892eb26f4d4 Parents: b32a9ba Author: Benoit Chesneau <beno...@apache.org> Authored: Mon Jan 13 23:06:26 2014 +0100 Committer: Benoit Chesneau <beno...@apache.org> Committed: Mon Jan 13 23:06:26 2014 +0100 ---------------------------------------------------------------------- apps/couch/src/couch.app.src.script | 2 +- apps/couch/src/couch.erl | 4 +- apps/couch/src/couch_app.erl | 2 +- apps/couch/src/couch_log.erl | 2 +- apps/couch/src/couch_server.erl | 2 +- apps/couch/src/couch_server_sup.erl | 117 ------------------- apps/couch/src/couch_sup.erl | 117 +++++++++++++++++++ apps/couch_httpd/src/couch_httpd.erl | 2 +- .../src/couch_httpd_misc_handlers.erl | 2 +- rel/vars.config | 2 +- test/etap/001-load.t | 2 +- 11 files changed, 127 insertions(+), 127 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/fab1bad0/apps/couch/src/couch.app.src.script ---------------------------------------------------------------------- diff --git a/apps/couch/src/couch.app.src.script b/apps/couch/src/couch.app.src.script index 1e14e3d..ac8156d 100644 --- a/apps/couch/src/couch.app.src.script +++ b/apps/couch/src/couch.app.src.script @@ -54,7 +54,7 @@ end, couch_query_servers, couch_secondary_services, couch_server, - couch_server_sup, + couch_sup, couch_stats_aggregator, couch_stats_collector, couch_task_status http://git-wip-us.apache.org/repos/asf/couchdb/blob/fab1bad0/apps/couch/src/couch.erl ---------------------------------------------------------------------- diff --git a/apps/couch/src/couch.erl b/apps/couch/src/couch.erl index 4b2032a..fe4f1a8 100644 --- a/apps/couch/src/couch.erl +++ b/apps/couch/src/couch.erl @@ -60,9 +60,9 @@ restart() -> end. reload() -> - case supervisor:terminate_child(couch_server_sup, couch_config) of + case supervisor:terminate_child(couch_sup, couch_config) of ok -> - supervisor:restart_child(couch_server_sup, couch_config); + supervisor:restart_child(couch_sup, couch_config); {error, Reason} -> {error, Reason} end. http://git-wip-us.apache.org/repos/asf/couchdb/blob/fab1bad0/apps/couch/src/couch_app.erl ---------------------------------------------------------------------- diff --git a/apps/couch/src/couch_app.erl b/apps/couch/src/couch_app.erl index 414a5c9..1d537e6 100644 --- a/apps/couch/src/couch_app.erl +++ b/apps/couch/src/couch_app.erl @@ -23,7 +23,7 @@ start(_Type, _Args) -> couch_util:start_app_deps(couch), IniFiles = get_ini_files(), - couch_server_sup:start_link(IniFiles). + couch_sup:start_link(IniFiles). stop(_) -> ok. http://git-wip-us.apache.org/repos/asf/couchdb/blob/fab1bad0/apps/couch/src/couch_log.erl ---------------------------------------------------------------------- diff --git a/apps/couch/src/couch_log.erl b/apps/couch/src/couch_log.erl index cd4bbbb..7cfd47b 100644 --- a/apps/couch/src/couch_log.erl +++ b/apps/couch/src/couch_log.erl @@ -73,7 +73,7 @@ stop() -> init([]) -> % read config and register for configuration changes - % just stop if one of the config settings change. couch_server_sup + % just stop if one of the config settings change. couch_sup % will restart us and then we will pick up the new settings. ok = couch_config:register( fun("log", "file") -> http://git-wip-us.apache.org/repos/asf/couchdb/blob/fab1bad0/apps/couch/src/couch_server.erl ---------------------------------------------------------------------- diff --git a/apps/couch/src/couch_server.erl b/apps/couch/src/couch_server.erl index 4b80dfb..91b4bc7 100644 --- a/apps/couch/src/couch_server.erl +++ b/apps/couch/src/couch_server.erl @@ -146,7 +146,7 @@ hash_admin_passwords(Persist) -> init([]) -> % read config and register for configuration changes - % just stop if one of the config settings change. couch_server_sup + % just stop if one of the config settings change. couch_sup % will restart us and then we will pick up the new settings. RootDir = couch_config:get("couchdb", "database_dir", "."), http://git-wip-us.apache.org/repos/asf/couchdb/blob/fab1bad0/apps/couch/src/couch_server_sup.erl ---------------------------------------------------------------------- diff --git a/apps/couch/src/couch_server_sup.erl b/apps/couch/src/couch_server_sup.erl deleted file mode 100644 index 7f37677..0000000 --- a/apps/couch/src/couch_server_sup.erl +++ /dev/null @@ -1,117 +0,0 @@ -% 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_server_sup). --behaviour(supervisor). - - --export([start_link/1,stop/0, couch_config_start_link_wrapper/2, - restart_core_server/0, config_change/2]). - --include("couch_db.hrl"). - -%% supervisor callbacks --export([init/1]). - -start_link(IniFiles) -> - case whereis(couch_server_sup) of - undefined -> - start_server(IniFiles); - _Else -> - {error, already_started} - end. - -restart_core_server() -> - init:restart(). - -couch_config_start_link_wrapper(IniFiles, FirstConfigPid) -> - case is_process_alive(FirstConfigPid) of - true -> - link(FirstConfigPid), - {ok, FirstConfigPid}; - false -> couch_config:start_link(IniFiles) - end. - -start_server(IniFiles) -> - case init:get_argument(pidfile) of - {ok, [PidFile]} -> - case file:write_file(PidFile, os:getpid()) of - ok -> ok; - {error, Reason} -> - io:format("Failed to write PID file ~s: ~s", - [PidFile, file:format_error(Reason)]) - end; - _ -> ok - end, - - {ok, ConfigPid} = couch_config:start_link(IniFiles), - - LogLevel = couch_config:get("log", "level", "info"), - % announce startup - io:format("Apache CouchDB ~s (LogLevel=~s) is starting.~n", [ - couch_server:get_version(), - LogLevel - ]), - case LogLevel of - "debug" -> - io:format("Configuration Settings ~p:~n", [IniFiles]), - [io:format(" [~s] ~s=~p~n", [Module, Variable, Value]) - || {{Module, Variable}, Value} <- couch_config:all()]; - _ -> ok - end, - - BaseChildSpecs = - {{one_for_all, 10, 3600}, - [{couch_config, - {couch_server_sup, couch_config_start_link_wrapper, [IniFiles, ConfigPid]}, - permanent, - brutal_kill, - worker, - [couch_config]}, - {couch_primary_services, - {couch_primary_sup, start_link, []}, - permanent, - infinity, - supervisor, - [couch_primary_sup]}, - {couch_secondary_services, - {couch_secondary_sup, start_link, []}, - permanent, - infinity, - supervisor, - [couch_secondary_sup]} - ]}, - - % ensure these applications are running - application:start(ibrowse), - application:start(crypto), - - {ok, Pid} = supervisor:start_link( - {local, couch_server_sup}, couch_server_sup, BaseChildSpecs), - - % launch the icu bridge - % just restart if one of the config settings change. - couch_config:register(fun ?MODULE:config_change/2, Pid), - - unlink(ConfigPid), - - {ok, Pid}. - -stop() -> - catch exit(whereis(couch_server_sup), normal). - -config_change("daemons", _) -> - supervisor:terminate_child(couch_server_sup, couch_secondary_services), - supervisor:restart_child(couch_server_sup, couch_secondary_services). - -init(ChildSpecs) -> - {ok, ChildSpecs}. http://git-wip-us.apache.org/repos/asf/couchdb/blob/fab1bad0/apps/couch/src/couch_sup.erl ---------------------------------------------------------------------- diff --git a/apps/couch/src/couch_sup.erl b/apps/couch/src/couch_sup.erl new file mode 100644 index 0000000..1f04aea --- /dev/null +++ b/apps/couch/src/couch_sup.erl @@ -0,0 +1,117 @@ +% 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_sup). +-behaviour(supervisor). + + +-export([start_link/1,stop/0, couch_config_start_link_wrapper/2, + restart_core_server/0, config_change/2]). + +-include("couch_db.hrl"). + +%% supervisor callbacks +-export([init/1]). + +start_link(IniFiles) -> + case whereis(couch_sup) of + undefined -> + start_server(IniFiles); + _Else -> + {error, already_started} + end. + +restart_core_server() -> + init:restart(). + +couch_config_start_link_wrapper(IniFiles, FirstConfigPid) -> + case is_process_alive(FirstConfigPid) of + true -> + link(FirstConfigPid), + {ok, FirstConfigPid}; + false -> couch_config:start_link(IniFiles) + end. + +start_server(IniFiles) -> + case init:get_argument(pidfile) of + {ok, [PidFile]} -> + case file:write_file(PidFile, os:getpid()) of + ok -> ok; + {error, Reason} -> + io:format("Failed to write PID file ~s: ~s", + [PidFile, file:format_error(Reason)]) + end; + _ -> ok + end, + + {ok, ConfigPid} = couch_config:start_link(IniFiles), + + LogLevel = couch_config:get("log", "level", "info"), + % announce startup + io:format("Apache CouchDB ~s (LogLevel=~s) is starting.~n", [ + couch_server:get_version(), + LogLevel + ]), + case LogLevel of + "debug" -> + io:format("Configuration Settings ~p:~n", [IniFiles]), + [io:format(" [~s] ~s=~p~n", [Module, Variable, Value]) + || {{Module, Variable}, Value} <- couch_config:all()]; + _ -> ok + end, + + BaseChildSpecs = + {{one_for_all, 10, 3600}, + [{couch_config, + {couch_sup, couch_config_start_link_wrapper, [IniFiles, ConfigPid]}, + permanent, + brutal_kill, + worker, + [couch_config]}, + {couch_primary_services, + {couch_primary_sup, start_link, []}, + permanent, + infinity, + supervisor, + [couch_primary_sup]}, + {couch_secondary_services, + {couch_secondary_sup, start_link, []}, + permanent, + infinity, + supervisor, + [couch_secondary_sup]} + ]}, + + % ensure these applications are running + application:start(ibrowse), + application:start(crypto), + + {ok, Pid} = supervisor:start_link( + {local, couch_sup}, couch_sup, BaseChildSpecs), + + % launch the icu bridge + % just restart if one of the config settings change. + couch_config:register(fun ?MODULE:config_change/2, Pid), + + unlink(ConfigPid), + + {ok, Pid}. + +stop() -> + catch exit(whereis(couch_sup), normal). + +config_change("daemons", _) -> + supervisor:terminate_child(couch_sup, couch_secondary_services), + supervisor:restart_child(couch_sup, couch_secondary_services). + +init(ChildSpecs) -> + {ok, ChildSpecs}. http://git-wip-us.apache.org/repos/asf/couchdb/blob/fab1bad0/apps/couch_httpd/src/couch_httpd.erl ---------------------------------------------------------------------- diff --git a/apps/couch_httpd/src/couch_httpd.erl b/apps/couch_httpd/src/couch_httpd.erl index 8cef53f..7be8a2a 100644 --- a/apps/couch_httpd/src/couch_httpd.erl +++ b/apps/couch_httpd/src/couch_httpd.erl @@ -92,7 +92,7 @@ start_link(couch_https) -> start_link(Name, Options) -> % read config and register for configuration changes - % just stop if one of the config settings change. couch_server_sup + % just stop if one of the config settings change. couch_sup % will restart us and then we will pick up the new settings. BindAddress = couch_config:get("httpd", "bind_address", any), http://git-wip-us.apache.org/repos/asf/couchdb/blob/fab1bad0/apps/couch_httpd/src/couch_httpd_misc_handlers.erl ---------------------------------------------------------------------- diff --git a/apps/couch_httpd/src/couch_httpd_misc_handlers.erl b/apps/couch_httpd/src/couch_httpd_misc_handlers.erl index 1999e5e..293ef00 100644 --- a/apps/couch_httpd/src/couch_httpd_misc_handlers.erl +++ b/apps/couch_httpd/src/couch_httpd_misc_handlers.erl @@ -98,7 +98,7 @@ handle_restart_req(#httpd{method='POST'}=Req) -> couch_httpd:validate_ctype(Req, "application/json"), ok = couch_httpd:verify_is_server_admin(Req), Result = send_json(Req, 202, {[{ok, true}]}), - couch_server_sup:restart_core_server(), + couch_sup:restart_core_server(), Result; handle_restart_req(Req) -> send_method_not_allowed(Req, "POST"). http://git-wip-us.apache.org/repos/asf/couchdb/blob/fab1bad0/rel/vars.config ---------------------------------------------------------------------- diff --git a/rel/vars.config b/rel/vars.config index c30c13c..da671df 100644 --- a/rel/vars.config +++ b/rel/vars.config @@ -50,4 +50,4 @@ {runner_patch_dir, "$RUNNER_BASE_DIR/lib/couchdb-patches"}. {pipe_dir, "/tmp/$RUNNER_BASE_DIR/"}. {runner_user, ""}. -{runner_wait_process, "couch_server_sup"}. +{runner_wait_process, "couch_sup"}. http://git-wip-us.apache.org/repos/asf/couchdb/blob/fab1bad0/test/etap/001-load.t ---------------------------------------------------------------------- diff --git a/test/etap/001-load.t b/test/etap/001-load.t index b719e82..9159fde 100755 --- a/test/etap/001-load.t +++ b/test/etap/001-load.t @@ -48,7 +48,7 @@ main(_) -> couch_query_servers, couch_ref_counter, couch_server, - couch_server_sup, + couch_sup, couch_stats_aggregator, couch_stats_collector, couch_stream,