summaryrefslogtreecommitdiff
path: root/restarter/lib
diff options
context:
space:
mode:
authorrinpatch <rinpatch@sdf.org>2020-02-05 16:59:21 +0000
committerrinpatch <rinpatch@sdf.org>2020-02-05 16:59:21 +0000
commit49e80a15377fe460d7ac644601609700fffea632 (patch)
treeaf98f0e28eb063c48152658294a4dce0d05131d4 /restarter/lib
parenta56db789359c7c7d57b45e6c68f791eeadc171e4 (diff)
parent33bd8fbffea79b8ca510a098ad4654b8f01324d6 (diff)
downloadpleroma-49e80a15377fe460d7ac644601609700fffea632.tar.gz
pleroma-49e80a15377fe460d7ac644601609700fffea632.zip
Merge branch 'feature/restart-pleroma-from-outside-application' into 'develop'
Restarting pleroma from outside application See merge request pleroma/pleroma!2144
Diffstat (limited to 'restarter/lib')
-rw-r--r--restarter/lib/pleroma.ex28
-rw-r--r--restarter/lib/restarter.ex8
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