diff options
author | Ivan Tashkinov <ivantashkinov@gmail.com> | 2020-02-08 19:59:37 +0300 |
---|---|---|
committer | Ivan Tashkinov <ivantashkinov@gmail.com> | 2020-02-08 19:59:37 +0300 |
commit | 4e6bbdc7b549e630141cb10d383a42055f06dc16 (patch) | |
tree | d0675328c7fc75f612eab779289afabee27a40a8 /restarter/lib | |
parent | d458f4fdcafe847a7db8b1c663cfd945019816b7 (diff) | |
parent | 964b4d82a0cde5b552b6210400c5e2c747a2f0e0 (diff) | |
download | pleroma-4e6bbdc7b549e630141cb10d383a42055f06dc16.tar.gz pleroma-4e6bbdc7b549e630141cb10d383a42055f06dc16.zip |
Merge remote-tracking branch 'remotes/origin/develop' into 1505-threads-federation
Diffstat (limited to 'restarter/lib')
-rw-r--r-- | restarter/lib/pleroma.ex | 28 | ||||
-rw-r--r-- | restarter/lib/restarter.ex | 8 |
2 files changed, 36 insertions, 0 deletions
diff --git a/restarter/lib/pleroma.ex b/restarter/lib/pleroma.ex new file mode 100644 index 000000000..da714654c --- /dev/null +++ b/restarter/lib/pleroma.ex @@ -0,0 +1,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 diff --git a/restarter/lib/restarter.ex b/restarter/lib/restarter.ex new file mode 100644 index 000000000..eadd86f89 --- /dev/null +++ b/restarter/lib/restarter.ex @@ -0,0 +1,8 @@ +defmodule Restarter do + use Application + + def start(_, _) do + opts = [strategy: :one_for_one, name: Restarter.Supervisor] + Supervisor.start_link([Restarter.Pleroma], opts) + end +end |