Skip to content

Commit 79c599f

Browse files
committed
Improve supervision tree
1 parent 641710f commit 79c599f

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

lib/ex_turn/supervisor.ex

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
defmodule ExTURN.Supervisor do
2+
@moduledoc false
3+
use Supervisor
4+
5+
require Logger
6+
7+
@version Mix.Project.config()[:version]
8+
9+
@spec start_link(any()) :: Supervisor.on_start()
10+
def start_link(_arg) do
11+
Supervisor.start_link(__MODULE__, nil, name: __MODULE__)
12+
end
13+
14+
@impl true
15+
def init(_arg) do
16+
Logger.info("Starting ExTURN v#{@version}")
17+
18+
listen_ip = Application.fetch_env!(:ex_turn, :listen_ip)
19+
listen_port = Application.fetch_env!(:ex_turn, :listen_port)
20+
21+
children = [
22+
{DynamicSupervisor, strategy: :one_for_one, name: ExTURN.AllocationSupervisor},
23+
{Registry, keys: :unique, name: Registry.Allocations},
24+
{ExTURN.Listener, [listen_ip, listen_port]},
25+
]
26+
27+
Supervisor.init(children, strategy: :one_for_all)
28+
end
29+
end

lib/ex_turn_app.ex

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,8 @@ defmodule ExTURN.App do
22
@moduledoc false
33
use Application
44

5-
require Logger
6-
7-
@version Mix.Project.config()[:version]
8-
95
@impl true
106
def start(_, _) do
11-
Logger.info("Starting ExTURN v#{@version}...")
12-
13-
listen_ip = Application.fetch_env!(:ex_turn, :listen_ip)
14-
listen_port = Application.fetch_env!(:ex_turn, :listen_port)
15-
167
auth_provider_ip = Application.fetch_env!(:ex_turn, :auth_provider_ip)
178
auth_provider_port = Application.fetch_env!(:ex_turn, :auth_provider_port)
189
use_tls? = Application.fetch_env!(:ex_turn, :auth_provider_use_tls?)
@@ -34,11 +25,9 @@ defmodule ExTURN.App do
3425
end
3526

3627
children = [
28+
ExTURN.Supervisor,
3729
{TelemetryMetricsPrometheus,
3830
metrics: metrics(), plug_cowboy_opts: [ip: metrics_ip, port: metrics_port]},
39-
{DynamicSupervisor, strategy: :one_for_one, name: ExTURN.AllocationSupervisor},
40-
{Registry, keys: :unique, name: Registry.Allocations},
41-
{ExTURN.Listener, [listen_ip, listen_port]},
4231
{Bandit,
4332
[plug: ExTURN.AuthProvider, ip: auth_provider_ip, port: auth_provider_port] ++ scheme_opts}
4433
]

0 commit comments

Comments
 (0)