Skip to content

Commit

Permalink
[RTC-515] Fix ensure_epmd_started! (#190)
Browse files Browse the repository at this point in the history
* [RTC-515] Fix `ensure_epmd_started!`
* Fix typo
  • Loading branch information
sgfn authored May 14, 2024
1 parent 5a96434 commit ee3f387
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions lib/jellyfish/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ defmodule Jellyfish.Application do

require Logger

# seconds
# in seconds
@resource_manager_opts %{interval: 600, recording_timeout: 3_600}

# in milliseconds
@epmd_timeout 5_000
@epmd_pgrep_interval 500

@impl true
def start(_type, _args) do
scrape_interval = Application.fetch_env!(:jellyfish, :webrtc_metrics_scrape_interval)
Expand Down Expand Up @@ -104,20 +108,38 @@ defmodule Jellyfish.Application do
end

defp ensure_epmd_started!() do
case System.cmd("epmd", ["-daemon"]) do
{_output, 0} ->
:ok
try do
{_output, 0} = System.cmd("epmd", ["-daemon"])
:ok = Task.async(&ensure_epmd_running/0) |> Task.await(@epmd_timeout)

_other ->
:ok
catch
_exit_or_error, _e ->
raise """
Couldn't start epmd daemon.
Epmd is required to run Jellyfish in a distributed mode.
Epmd is required to run Jellyfish in distributed mode.
You can try to start it manually with:
epmd -daemon
and run Jellyfish again.
"""
end

:ok
end

defp ensure_epmd_running() do
with {:pgrep, {_output, 0}} <- {:pgrep, System.cmd("pgrep", ["epmd"])},
{:epmd, {_output, 0}} <- {:epmd, System.cmd("epmd", ["-names"])} do
:ok
else
{:pgrep, _other} ->
Process.sleep(@epmd_pgrep_interval)
ensure_epmd_running()

{:epmd, _other} ->
:error
end
end
end

0 comments on commit ee3f387

Please sign in to comment.