diff options
author | Maksim Pechnikov <parallel588@gmail.com> | 2020-02-10 20:49:20 +0300 |
---|---|---|
committer | Maksim Pechnikov <parallel588@gmail.com> | 2020-02-10 20:49:20 +0300 |
commit | 6813c0302c2b665d337d5f5831d2df6312b6b277 (patch) | |
tree | 8c9333eeff70c799ecd30e6589f3cbebd8adbf5c /restarter/lib | |
parent | 2c40c8b4a2890e60abe8d67a3c8af4a88d225b60 (diff) | |
parent | 544bdbfb90d764a5aba8ed07c13b842838d76d73 (diff) | |
download | pleroma-6813c0302c2b665d337d5f5831d2df6312b6b277.tar.gz pleroma-6813c0302c2b665d337d5f5831d2df6312b6b277.zip |
Merge branch 'develop' into issue/1383
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 |