Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make couch_httpd more resistant to failures.
If vhosts or the authentication cache module crash we need to make sure that HTTPd bindings are restarted as well.
- Loading branch information
Showing
9 changed files
with
139 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- | ||
%% ex: ft=erlang ts=4 sw=4 et | ||
|
||
{cover_enabled, true}. | ||
{eunit_opts, [{report,{eunit_surefire,[{dir,"."}]}}]}. | ||
{edoc_opts, [{preprocess, true}]}. | ||
{erl_opts, [warnings_as_errors, {parse_transform, lager_transform}]}. | ||
|
||
{deps, [ | ||
%% mochiweb module, http framework | ||
{mochiweb, ".*", {git,"git://github.com/refuge/mochiweb.git", | ||
{branch, "master"}}}, | ||
|
||
%% cowboy adapter to mochiweb | ||
{mochicow, ".*", {git,"git://github.com/benoitc/mochicow.git", | ||
{branch, "refuge"}}}, | ||
|
||
%% logging | ||
{lager, ".*", {git, "git://github.com/basho/lager.git", | ||
{branch, "master"}}} | ||
]}. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
% 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_httpd_binding_sup). | ||
-behaviour(supervisor). | ||
|
||
-export([start_link/0]). | ||
-export([init/1]). | ||
|
||
-define(CHILD(I), {I, {I, start_link, []}, permanent, brutal_kill, worker, [I]}). | ||
start_link() -> | ||
supervisor:start_link({local, ?MODULE}, ?MODULE, []). | ||
|
||
|
||
init([]) -> | ||
Bindings = lists:map(fun(Binding) -> | ||
couch_httpd:child_spec(Binding) | ||
end, couch_httpd:get_bindings()), | ||
{ok, {{one_for_one, 10, 3600}, Bindings}}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
% 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_httpd_vhosts_sup). | ||
-behaviour(supervisor). | ||
|
||
-export([start_link/0, write_uri_file/0]). | ||
-export([init/1]). | ||
|
||
-define(SUP(I), {I, {I, start_link, []}, permanent, 5000, | ||
supervisor, [I]}). | ||
-define(CHILD(I), {I, {I, start_link, []}, permanent, brutal_kill, | ||
worker, [I]}). | ||
|
||
|
||
start_link() -> | ||
{ok, Pid} = supervisor:start_link({local, ?MODULE}, ?MODULE, []), | ||
%% announce HTTP uri | ||
couch_httpd:display_uris(), | ||
%% write uri file | ||
write_uri_file(), | ||
{ok, Pid}. | ||
|
||
write_uri_file() -> | ||
Ip = couch_config:get("httpd", "bind_address"), | ||
Listeners = couch_httpd:get_bindings(), | ||
Uris = [couch_httpd_util:get_uri(Name, Ip) || Name <- Listeners], | ||
case couch_config:get("couchdb", "uri_file", null) of | ||
null -> ok; | ||
UriFile -> | ||
Lines = [begin case Uri of | ||
undefined -> []; | ||
Uri -> io_lib:format("~s~n", [Uri]) | ||
end end || Uri <- Uris], | ||
case file:write_file(UriFile, Lines) of | ||
ok -> ok; | ||
{error, eacces} -> | ||
lager:info("Permission error when writing to URI file ~s", [UriFile]), | ||
throw({file_permission_error, UriFile}); | ||
Error2 -> | ||
lager:info("Failed to write to URI file ~s: ~p~n", [UriFile, Error2]), | ||
throw(Error2) | ||
end | ||
end. | ||
|
||
init([]) -> | ||
AuthCache = ?CHILD(couch_auth_cache), | ||
Vhost = ?CHILD(couch_httpd_vhost), | ||
Binding = ?SUP(couch_httpd_binding_sup), | ||
{ok, {{one_for_all, 10, 10}, [AuthCache, Vhost, Binding]}}. |