1
%% ``The contents of this file are subject to the Erlang Public License,
2
%% Version 1.1, (the "License"); you may not use this file except in
3
%% compliance with the License. You should have received a copy of the
4
%% Erlang Public License along with this software. If not, it can be
5
%% retrieved via the world wide web at http://www.erlang.org/.
7
%% Software distributed under the License is distributed on an "AS IS"
8
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9
%% the License for the specific language governing rights and limitations
12
%% The Initial Developer of the Original Code is Ericsson Utvecklings AB.
13
%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
14
%% AB. All Rights Reserved.''
16
%% $Id: inets_sup.erl,v 1.1 2008/12/17 09:53:34 mikpe Exp $
21
-export([start/2, stop/1, init/1]).
22
-export([start_child/2, stop_child/2, which_children/0]).
25
%% crock (Used for debugging!)
28
application:start(sasl),
29
application:start(inets).
35
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
46
start_child(ConfigFile, Verbosity) ->
47
{ok, Spec} = httpd_child_spec(ConfigFile, Verbosity),
48
supervisor:start_child(?MODULE, Spec).
53
stop_child(Addr, Port) ->
54
Name = {httpd_sup, Addr, Port},
55
case supervisor:terminate_child(?MODULE, Name) of
57
supervisor:delete_child(?MODULE, Name);
66
supervisor:which_children(?MODULE).
72
case get_services() of
76
SupFlags = {one_for_one, 10, 3600},
77
{ok, {SupFlags, child_spec(Services, [])}}
81
case (catch application:get_env(inets, services)) of
89
child_spec([], Acc) ->
91
child_spec([{httpd, ConfigFile, Verbosity}|Rest], Acc) ->
92
case httpd_child_spec(ConfigFile, Verbosity) of
94
child_spec(Rest, [Spec | Acc]);
96
error_msg("Failed creating child spec "
97
"using ~p for reason: ~p", [ConfigFile, Reason]),
100
child_spec([{httpd, ConfigFile}|Rest], Acc) ->
101
case httpd_child_spec(ConfigFile, []) of
103
child_spec(Rest, [Spec | Acc]);
105
error_msg("Failed creating child spec "
106
"using ~p for reason: ~p", [ConfigFile, Reason]),
107
child_spec(Rest, Acc)
111
httpd_child_spec(ConfigFile, Verbosity) ->
112
case httpd_conf:load(ConfigFile) of
114
Port = httpd_util:key1search(ConfigList, port, 80),
115
Addr = httpd_util:key1search(ConfigList, bind_address),
116
{ok, httpd_child_spec(ConfigFile, Addr, Port, Verbosity)};
122
httpd_child_spec(ConfigFile, Addr, Port, Verbosity) ->
123
{{httpd_sup, Addr, Port},{httpd_sup, start_link,[ConfigFile, Verbosity]},
124
permanent, 20000, supervisor,
158
error_logger:error_msg(F ++ "~n", A).