2.0 KiB · text History 442a476
defmodule OhMyExOhIrcd.Application do
  # See https://hexdocs.pm/elixir/Application.html
  # for more information on OTP Applications
  @moduledoc false

  use Application

  @impl true
  def start(_type, _args) do
    topologies = Application.get_env(:libcluster, :topologies, [])

    children = [
      OhMyExOhIrcdWeb.Telemetry,
      OhMyExOhIrcd.Repo,
      {DNSCluster, query: Application.get_env(:oh_my_ex_oh_ircd, :dns_cluster_query) || :ignore},
      {Phoenix.PubSub, name: OhMyExOhIrcd.PubSub},
      {Cluster.Supervisor, [topologies, [name: OhMyExOhIrcd.ClusterSupervisor]]},
      OhMyExOhIrcd.IRC.HLC,
      OhMyExOhIrcd.IRC.MessageLog,
      OhMyExOhIrcd.Cluster.HordeRegistry,
      OhMyExOhIrcd.Cluster.HordeSupervisor,
      OhMyExOhIrcd.Cluster.NodeListener,
      OhMyExOhIrcd.IRC.Services,
      OhMyExOhIrcd.IRC.Listener,
      endpoint_child(),
      OhMyExOhIrcd.IRC.TLSListener
    ]

    # See https://hexdocs.pm/elixir/Supervisor.html
    # for other strategies and supported options
    opts = [strategy: :one_for_one, name: OhMyExOhIrcd.Supervisor]
    Supervisor.start_link(children, opts)
  end

  # Tell Phoenix to update the endpoint configuration
  # whenever the application is updated.
  @impl true
  def config_change(changed, _new, removed) do
    OhMyExOhIrcdWeb.Endpoint.config_change(changed, removed)
    :ok
  end

  # In :standalone mode wrap the endpoint in `SiteEncrypt.Phoenix.Endpoint`
  # so site_encrypt manages ACME cert lifecycle (provision/renew). In
  # :kubernetes mode start the endpoint directly — certs come from a
  # mounted Secret, no in-process ACME client needed. The branch is
  # compile-time so the alternate path's references aren't even
  # compiled into the release.
  @tls_mode Application.compile_env(:oh_my_ex_oh_ircd, :tls_mode, :standalone)

  if @tls_mode == :standalone do
    defp endpoint_child,
      do: {SiteEncrypt.Phoenix.Endpoint, endpoint: OhMyExOhIrcdWeb.Endpoint}
  else
    defp endpoint_child, do: OhMyExOhIrcdWeb.Endpoint
  end
end