moving restarter application into pleroma repo
authorAlexander Strizhakov <alex.strizhakov@gmail.com>
Tue, 28 Jan 2020 12:19:05 +0000 (15:19 +0300)
committerAlexander Strizhakov <alex.strizhakov@gmail.com>
Tue, 28 Jan 2020 12:19:05 +0000 (15:19 +0300)
mix.exs
restarter/lib/pleroma.ex [new file with mode: 0644]
restarter/lib/restarter.ex [new file with mode: 0644]
restarter/mix .exs [new file with mode: 0644]

diff --git a/mix.exs b/mix.exs
index 1d0b59e566b6d1699246b3b68d97bfaecec0e452..2608f986e102c688e8efe07176500c57413150bc 100644 (file)
--- a/mix.exs
+++ b/mix.exs
@@ -172,7 +172,7 @@ defmodule Pleroma.Mixfile do
        git: "https://git.pleroma.social/pleroma/elixir-libraries/elixir-captcha.git",
        ref: "e0f16822d578866e186a0974d65ad58cddc1e2ab"},
       {:mox, "~> 0.5", only: :test},
-      {:restarter, git: "https://git.pleroma.social/alex.s/restarter"}
+      {:restarter, path: "../restarter"}
     ] ++ oauth_deps()
   end
 
diff --git a/restarter/lib/pleroma.ex b/restarter/lib/pleroma.ex
new file mode 100644 (file)
index 0000000..da71465
--- /dev/null
@@ -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 (file)
index 0000000..eadd86f
--- /dev/null
@@ -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
diff --git a/restarter/mix .exs b/restarter/mix .exs
new file mode 100644 (file)
index 0000000..b0908ae
--- /dev/null
@@ -0,0 +1,21 @@
+defmodule Restarter.MixProject do
+  use Mix.Project
+
+  def project do
+    [
+      app: :restarter,
+      version: "0.1.0",
+      elixir: "~> 1.8",
+      start_permanent: Mix.env() == :prod,
+      deps: deps()
+    ]
+  end
+
+  def application do
+    [
+      mod: {Restarter, []}
+    ]
+  end
+
+  defp deps, do: []
+end