1.2 KiB · text History 4b6fe3b
defmodule OhMyExOhIrcd.IRC.Services do
  @moduledoc """
  Boot-time starter that ensures the cluster-wide pseudo-services
  (ChanServ, ScrobbleServ, ImgServ) are running. Sits in the supervision
  tree *after* Horde so it can talk to the cluster registry.
  """

  use GenServer
  require Logger

  alias OhMyExOhIrcd.IRC.{ChanServ, ImgServ, ScrobbleServ}

  def start_link(_), do: GenServer.start_link(__MODULE__, [], name: __MODULE__)

  @impl true
  def init(_) do
    {:ok, %{}, {:continue, :boot_services}}
  end

  @impl true
  def handle_continue(:boot_services, state) do
    case ChanServ.ensure_started() do
      {:ok, _pid} -> Logger.debug("Services: ChanServ ready")
      other -> Logger.warning("Services: ChanServ failed to start: #{inspect(other)}")
    end

    case ScrobbleServ.ensure_started() do
      {:ok, _pid} -> Logger.debug("Services: ScrobbleServ ready")
      other -> Logger.warning("Services: ScrobbleServ failed to start: #{inspect(other)}")
    end

    case ImgServ.ensure_started() do
      {:ok, _pid} -> Logger.debug("Services: ImgServ ready")
      other -> Logger.warning("Services: ImgServ failed to start: #{inspect(other)}")
    end

    {:noreply, state}
  end
end