1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Mix.Pleroma do
17 @cachex_children ["object", "user", "scrubber", "web_resp"]
18 @doc "Common functions to be reused in mix tasks"
20 Pleroma.Config.Holder.save_default()
21 Pleroma.Config.Oban.warn()
22 Pleroma.Application.limiters_setup()
23 Application.put_env(:phoenix, :serve_endpoints, false, persistent: true)
25 unless System.get_env("DEBUG") do
26 Logger.remove_backend(:console)
29 adapter = Application.get_env(:tesla, :adapter)
32 if adapter == Tesla.Adapter.Gun do
38 Enum.each(apps, &Application.ensure_all_started/1)
43 {Pleroma.Config.TransferTask, false},
45 {Oban, Pleroma.Config.get(Oban)}
47 http_children(adapter)
49 cachex_children = Enum.map(@cachex_children, &Pleroma.Application.build_cachex(&1, []))
51 Supervisor.start_link(children ++ cachex_children,
52 strategy: :one_for_one,
53 name: Pleroma.Supervisor
56 if Pleroma.Config.get(:env) not in [:test, :benchmark] do
61 defp pleroma_rebooted? do
62 if Restarter.Pleroma.rebooted?() do
71 Application.load(:pleroma)
74 def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do
75 Keyword.get(options, opt) || shell_prompt(prompt, defval, defname)
78 def shell_prompt(prompt, defval \\ nil, defname \\ nil) do
79 prompt_message = "#{prompt} [#{defname || defval}] "
83 do: Mix.shell().prompt(prompt_message),
84 else: :io.get_line(prompt_message)
90 shell_prompt(prompt, defval, defname)
101 def shell_info(message) do
103 do: Mix.shell().info(message),
104 else: IO.puts(message)
107 def shell_error(message) do
109 do: Mix.shell().error(message),
110 else: IO.puts(:stderr, message)
113 @doc "Performs a safe check whether `Mix.shell/0` is available (does not raise if Mix is not loaded)"
114 def mix_shell?, do: :erlang.function_exported(Mix, :shell, 0)
116 def escape_sh_path(path) do
117 ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')
120 defp http_children(Tesla.Adapter.Gun) do
121 Pleroma.Gun.ConnectionPool.children() ++
122 [{Task, &Pleroma.HTTP.AdapterHelper.Gun.limiter_setup/0}]
125 defp http_children(_), do: []