%%%------------------------------------------------------------------- %% @doc sdlan top level supervisor. %% @end %%%------------------------------------------------------------------- -module(sdlan_sup). -behaviour(supervisor). -export([start_link/0]). -export([init/1]). -define(SERVER, ?MODULE). -spec start_link() -> supervisor:startlink_ret(). start_link() -> supervisor:start_link({local, ?SERVER}, ?MODULE, []). %% sup_flags() = #{strategy => strategy(), % optional %% intensity => non_neg_integer(), % optional %% period => pos_integer()} % optional %% child_spec() = #{id => child_id(), % mandatory %% start => mfargs(), % mandatory %% restart => restart(), % optional %% shutdown => shutdown(), % optional %% type => worker(), % optional -spec init(Args :: term()) -> {ok, {SupFlags :: supervisor:sup_flags(), [ChildSpec :: supervisor:child_spec()]}} | ignore. init([]) -> SupFlags = #{strategy => one_for_one, intensity => 1000, period => 3600}, Specs = [ %% 暂时注释掉dns的逻辑 #{ id => dns_server_sup, start => {dns_server_sup, start_link, []}, restart => permanent, shutdown => 2000, type => supervisor, modules => ['dns_server_sup'] }, #{ id => ipv6_assist_server_sup, start => {ipv6_assist_server_sup, start_link, []}, restart => permanent, shutdown => 2000, type => supervisor, modules => ['ipv6_assist_server_sup'] }, #{ id => sdlan_network_coordinator, start => {sdlan_network_coordinator, start_link, []}, restart => permanent, shutdown => 2000, type => worker, modules => ['sdlan_network_coordinator'] }, #{ id => sdlan_network_sup, start => {sdlan_network_sup, start_link, []}, restart => permanent, shutdown => 2000, type => supervisor, modules => ['sdlan_network_sup'] }, #{ id => sdlan_stun_sup, start => {sdlan_stun_sup, start_link, []}, restart => permanent, shutdown => 2000, type => supervisor, modules => ['sdlan_stun_sup'] }, #{ id => sdlan_quic_channel_sup, start => {sdlan_quic_channel_sup, start_link, []}, restart => permanent, shutdown => 2000, type => supervisor, modules => ['sdlan_quic_channel_sup'] }, #{ id => sdlan_quic_server, start => {sdlan_quic_server, start_link, []}, restart => permanent, shutdown => 2000, type => worker, modules => ['sdlan_quic_server'] }, #{ id => sdlan_sync_mysql, start => {sdlan_sync_mysql, start_link, []}, restart => permanent, shutdown => 2000, type => worker, modules => ['sdlan_sync_mysql'] }, #{ id => maxwell_redis_server, start => {maxwell_redis_server, start_link, [16379]}, restart => permanent, shutdown => 2000, type => worker, modules => ['maxwell_redis_server'] } ], {ok, {SupFlags, pools() ++ Specs}}. %% internal functions pools() -> {ok, Pools} = application:get_env(sdlan, pools), lists:map(fun({Name, PoolArgs, WorkerArgs}) -> poolboy:child_spec(Name, [{name, {local, Name}}|PoolArgs], WorkerArgs) end, Pools).