summaryrefslogtreecommitdiff
path: root/restarter/lib/pleroma.ex
blob: da714654c20864c69581f296fc5dc9d2452ae0bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
defmodule Restarter.Pleroma do
  use GenServer

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

  def init(_), do: {:ok, %{}}

  def handle_info(:after_boot, %{after_boot: true} = state), do: {:noreply, state}

  def handle_info(:after_boot, state) do
    restart(:pleroma)
    {:noreply, Map.put(state, :after_boot, true)}
  end

  def handle_info({:restart, delay}, state) do
    Process.sleep(delay)
    restart(:pleroma)
    {:noreply, state}
  end

  defp restart(app) do
    :ok = Application.ensure_started(app)
    :ok = Application.stop(app)
    :ok = Application.start(app)
  end
end