moving restarter application into pleroma repo
[akkoma] / restarter / lib / pleroma.ex
1 defmodule Restarter.Pleroma do
2 use GenServer
3
4 def start_link(_) do
5 GenServer.start_link(__MODULE__, [], name: __MODULE__)
6 end
7
8 def init(_), do: {:ok, %{}}
9
10 def handle_info(:after_boot, %{after_boot: true} = state), do: {:noreply, state}
11
12 def handle_info(:after_boot, state) do
13 restart(:pleroma)
14 {:noreply, Map.put(state, :after_boot, true)}
15 end
16
17 def handle_info({:restart, delay}, state) do
18 Process.sleep(delay)
19 restart(:pleroma)
20 {:noreply, state}
21 end
22
23 defp restart(app) do
24 :ok = Application.ensure_started(app)
25 :ok = Application.stop(app)
26 :ok = Application.start(app)
27 end
28 end