summaryrefslogtreecommitdiff
path: root/restarter
diff options
context:
space:
mode:
authorAlexander Strizhakov <alex.strizhakov@gmail.com>2020-01-28 15:19:05 +0300
committerAlexander Strizhakov <alex.strizhakov@gmail.com>2020-01-28 15:19:05 +0300
commit91ea3ed82cc29f02ae8eec94e4e4ced325a7e008 (patch)
treec97c4f953b4f7dc790452024de7f2468c6e101fb /restarter
parent7c6e5c541de808957be8a1948fa7a20eba8734df (diff)
moving restarter application into pleroma repo
Diffstat (limited to 'restarter')
-rw-r--r--restarter/lib/pleroma.ex28
-rw-r--r--restarter/lib/restarter.ex8
-rw-r--r--restarter/mix .exs21
3 files changed, 57 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
diff --git a/restarter/mix .exs b/restarter/mix .exs
new file mode 100644
index 000000000..b0908aece
--- /dev/null
+++ b/restarter/mix .exs
@@ -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