Generated on 2009-08-09 21:22:54 with etap 0.3.4.
| Name | Total lines | Lines of code | Total coverage | Code coverage | ||||
| couch_server_sup | ?? | ?? | ?? |
|
....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_server_sup). ...14 -behaviour(supervisor). ...15 ...16 ...17 -export([start_link/1,stop/0, couch_config_start_link_wrapper/2, ...18 start_primary_services/0,start_secondary_services/0, ...19 restart_core_server/0]). ...20 ...21 -include("couch_db.hrl"). ...22 ...23 %% supervisor callbacks ...24 -export([init/1]). ...25 ...26 start_link(IniFiles) -> ...27 case whereis(couch_server_sup) of ...28 undefined -> ...29 start_server(IniFiles); ...30 _Else -> ...31 {error, already_started} ...32 end. ...33 ...34 restart_core_server() -> ...35 supervisor:terminate_child(couch_primary_services, couch_server), ...36 supervisor:terminate_child(couch_secondary_services, stats_aggregator), ...37 supervisor:terminate_child(couch_secondary_services, stats_collector), ...38 supervisor:restart_child(couch_primary_services, couch_server), ...39 supervisor:restart_child(couch_secondary_services, stats_collector), ...40 supervisor:restart_child(couch_secondary_services, stats_aggregator). ...41 ...42 couch_config_start_link_wrapper(IniFiles, FirstConfigPid) -> ...43 case is_process_alive(FirstConfigPid) of ...44 true -> ...45 link(FirstConfigPid), ...46 {ok, FirstConfigPid}; ...47 false -> couch_config:start_link(IniFiles) ...48 end. ...49 ...50 start_server(IniFiles) -> ...51 case init:get_argument(pidfile) of ...52 {ok, [PidFile]} -> ...53 case file:write_file(PidFile, os:getpid()) of ...54 ok -> ok; ...55 Error -> io:format("Failed to write PID file ~s, error: ~p", [PidFile, Error]) ...56 end; ...57 _ -> ok ...58 end, ...59 ...60 {ok, ConfigPid} = couch_config:start_link(IniFiles), ...61 ...62 LogLevel = couch_config:get("log", "level", "info"), ...63 % announce startup ...64 io:format("Apache CouchDB ~s (LogLevel=~s) is starting.~n", [ ...65 couch_server:get_version(), ...66 LogLevel ...67 ]), ...68 case LogLevel of ...69 "debug" -> ...70 io:format("Configuration Settings ~p:~n", [IniFiles]), ...71 [io:format(" [~s] ~s=~p~n", [Module, Variable, Value]) ...72 || {{Module, Variable}, Value} <- couch_config:all()]; ...73 _ -> ok ...74 end, ...75 ...76 LibDir = ...77 case couch_config:get("couchdb", "util_driver_dir", null) of ...78 null -> ...79 filename:join(code:priv_dir(couch), "lib"); ...80 LibDir0 -> LibDir0 ...81 end, ...82 ...83 ok = couch_util:start_driver(LibDir), ...84 ...85 BaseChildSpecs = ...86 {{one_for_all, 10, 3600}, ...87 [{couch_config, ...88 {couch_server_sup, couch_config_start_link_wrapper, [IniFiles, ConfigPid]}, ...89 permanent, ...90 brutal_kill, ...91 worker, ...92 dynamic}, ...93 {couch_primary_services, ...94 {couch_server_sup, start_primary_services, []}, ...95 permanent, ...96 infinity, ...97 supervisor, ...98 [couch_server_sup]}, ...99 {couch_secondary_services, ..100 {couch_server_sup, start_secondary_services, []}, ..101 permanent, ..102 infinity, ..103 supervisor, ..104 [couch_server_sup]} ..105 ]}, ..106 ..107 % ensure these applications are running ..108 application:start(ibrowse), ..109 application:start(crypto), ..110 ..111 {ok, Pid} = supervisor:start_link( ..112 {local, couch_server_sup}, couch_server_sup, BaseChildSpecs), ..113 ..114 % launch the icu bridge ..115 % just restart if one of the config settings change. ..116 ..117 couch_config:register( ..118 fun("couchdb", "util_driver_dir") -> ..119 ?MODULE:stop(); ..120 ("daemons", _) -> ..121 ?MODULE:stop() ..122 end, Pid), ..123 ..124 unlink(ConfigPid), ..125 ..126 Ip = couch_config:get("httpd", "bind_address"), ..127 Port = mochiweb_socket_server:get(couch_httpd, port), ..128 io:format("Apache CouchDB has started. Time to relax.~n"), ..129 ?LOG_INFO("Apache CouchDB has started on http://~s:~w/", [Ip, Port]), ..130 ..131 {ok, Pid}. ..132 ..133 start_primary_services() -> ..134 supervisor:start_link({local, couch_primary_services}, couch_server_sup, ..135 {{one_for_one, 10, 3600}, ..136 [{couch_log, ..137 {couch_log, start_link, []}, ..138 permanent, ..139 brutal_kill, ..140 worker, ..141 [couch_log]}, ..142 {couch_replication_supervisor, ..143 {couch_rep_sup, start_link, []}, ..144 permanent, ..145 infinity, ..146 supervisor, ..147 [couch_rep_sup]}, ..148 {couch_task_status, ..149 {couch_task_status, start_link, []}, ..150 permanent, ..151 brutal_kill, ..152 worker, ..153 [couch_task_status]}, ..154 {couch_server, ..155 {couch_server, sup_start_link, []}, ..156 permanent, ..157 brutal_kill, ..158 supervisor, ..159 [couch_server]}, ..160 {couch_db_update_event, ..161 {gen_event, start_link, [{local, couch_db_update}]}, ..162 permanent, ..163 brutal_kill, ..164 supervisor, ..165 dynamic} ..166 ] ..167 }). ..168 ..169 start_secondary_services() -> ..170 DaemonChildSpecs = [ ..171 begin ..172 {ok, {Module, Fun, Args}} = couch_util:parse_term(SpecStr), ..173 ..174 {list_to_atom(Name), ..175 {Module, Fun, Args}, ..176 permanent, ..177 brutal_kill, ..178 worker, ..179 [Module]} ..180 end ..181 || {Name, SpecStr} ..182 <- couch_config:get("daemons"), SpecStr /= ""], ..183 ..184 supervisor:start_link({local, couch_secondary_services}, couch_server_sup, ..185 {{one_for_one, 10, 3600}, DaemonChildSpecs}). ..186 ..187 stop() -> ..188 catch exit(whereis(couch_server_sup), normal). ..189 ..190 init(ChildSpecs) -> ..191 {ok, ChildSpecs}.
Generated using etap 0.3.4.