2
%% <year>2008-2008</year>
3
%% <holder>Ericsson AB, All Rights Reserved</holder>
6
%% The contents of this file are subject to the Erlang Public License,
7
%% Version 1.1, (the "License"); you may not use this file except in
8
%% compliance with the License. You should have received a copy of the
9
%% Erlang Public License along with this software. If not, it can be
10
%% retrieved online at http://www.erlang.org/.
12
%% Software distributed under the License is distributed on an "AS IS"
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
%% the License for the specific language governing rights and limitations
17
%% The Initial Developer of the Original Code is Ericsson AB.
20
%%----------------------------------------------------------------------
21
%% Purpose: The top supervisor for ssh servers hangs under
23
%%----------------------------------------------------------------------
27
-behaviour(supervisor).
29
-export([start_link/1, start_child/1, stop_child/1,
30
stop_child/2, system_name/1]).
32
%% Supervisor callback
35
%%%=========================================================================
37
%%%=========================================================================
38
start_link(Servers) ->
39
supervisor:start_link({local, ?MODULE}, ?MODULE, [Servers]).
41
start_child(ServerOpts) ->
42
Address = proplists:get_value(address, ServerOpts),
43
Port = proplists:get_value(port, ServerOpts),
44
case ssh_system_sup:system_supervisor(Address, Port) of
46
Spec = child_spec(Address, Port, ServerOpts),
47
supervisor:start_child(?MODULE, Spec);
49
AccPid = ssh_system_sup:acceptor_supervisor(Pid),
50
ssh_acceptor_sup:start_child(AccPid, ServerOpts)
54
case supervisor:terminate_child(?MODULE, Name) of
56
supervisor:delete_child(?MODULE, Name);
61
stop_child(Address, Port) ->
62
Name = id(Address, Port),
65
system_name(SysSup) ->
66
Children = supervisor:which_children(sshd_sup),
67
system_name(SysSup, Children).
69
%%%=========================================================================
70
%%% Supervisor callback
71
%%%=========================================================================
73
RestartStrategy = one_for_one,
76
Fun = fun(ServerOpts) ->
77
Address = proplists:get_value(address, ServerOpts),
78
Port = proplists:get_value(port, ServerOpts),
79
child_spec(Address, Port, ServerOpts)
81
Children = lists:map(Fun, Servers),
82
{ok, {{RestartStrategy, MaxR, MaxT}, Children}}.
84
%%%=========================================================================
85
%%% Internal functions
86
%%%=========================================================================
87
child_spec(Address, Port, ServerOpts) ->
88
Name = id(Address, Port),
89
StartFunc = {ssh_system_sup, start_link, [ServerOpts]},
92
Modules = [ssh_system_sup],
94
{Name, StartFunc, Restart, Shutdown, Type, Modules}.
97
{server, ssh_system_sup, Address, Port}.
99
system_name([], _ ) ->
101
system_name(SysSup, [{Name, SysSup, _, _} | _]) ->
103
system_name(SysSup, [_ | Rest]) ->
104
system_name(SysSup, Rest).