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.''
18
%%----------------------------------------------------------------------
19
%% Purpose: The supervisor for auth and sec processes in the http server,
20
%% hangs under the httpd_instance_sup_<Addr>_<Port> supervisor.
21
%%----------------------------------------------------------------------
23
-module(httpd_misc_sup).
25
-behaviour(supervisor).
28
-export([start_link/2, start_auth_server/2, stop_auth_server/2,
29
start_sec_server/2, stop_sec_server/2]).
31
%% Supervisor callback
34
%%%=========================================================================
36
%%%=========================================================================
38
start_link(Addr, Port) ->
39
SupName = make_name(Addr, Port),
40
supervisor:start_link({local, SupName}, ?MODULE, []).
42
%%----------------------------------------------------------------------
43
%% Function: [start|stop]_[auth|sec]_server/3
44
%% Description: Starts a [auth | security] worker (child) process
45
%%----------------------------------------------------------------------
46
start_auth_server(Addr, Port) ->
47
start_permanent_worker(mod_auth_server, Addr, Port, [gen_server]).
49
stop_auth_server(Addr, Port) ->
50
stop_permanent_worker(mod_auth_server, Addr, Port).
53
start_sec_server(Addr, Port) ->
54
start_permanent_worker(mod_security_server, Addr, Port, [gen_server]).
56
stop_sec_server(Addr, Port) ->
57
stop_permanent_worker(mod_security_server, Addr, Port).
60
%%%=========================================================================
61
%%% Supervisor callback
62
%%%=========================================================================
64
Flags = {one_for_one, 0, 1},
66
{ok, {Flags, Workers}}.
68
%%%=========================================================================
69
%%% Internal functions
70
%%%=========================================================================
71
start_permanent_worker(Mod, Addr, Port, Modules) ->
72
SupName = make_name(Addr, Port),
73
Spec = {{Mod, Addr, Port},
74
{Mod, start_link, [Addr, Port]},
75
permanent, timer:seconds(1), worker, [Mod] ++ Modules},
76
supervisor:start_child(SupName, Spec).
78
stop_permanent_worker(Mod, Addr, Port) ->
79
SupName = make_name(Addr, Port),
80
Name = {Mod, Addr, Port},
81
case supervisor:terminate_child(SupName, Name) of
83
supervisor:delete_child(SupName, Name);
88
make_name(Addr,Port) ->
89
httpd_util:make_name("httpd_misc_sup",Addr,Port).