1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Mix.Pleroma do
19 @cachex_children ["object", "user", "scrubber", "web_resp"]
20 @doc "Common functions to be reused in mix tasks"
22 Pleroma.Config.Holder.save_default()
23 Pleroma.Config.Oban.warn()
24 Pleroma.Application.limiters_setup()
25 Application.put_env(:phoenix, :serve_endpoints, false, persistent: true)
27 unless System.get_env("DEBUG") do
28 Logger.remove_backend(:console)
31 adapter = Application.get_env(:tesla, :adapter)
34 if adapter == Tesla.Adapter.Gun do
40 Enum.each(apps, &Application.ensure_all_started/1)
54 {Pleroma.Config.TransferTask, false},
58 [name: Pleroma.MajicPool, pool_size: Pleroma.Config.get([:majic_pool, :size], 2)]}
60 http_children(adapter)
62 cachex_children = Enum.map(@cachex_children, &Pleroma.Application.build_cachex(&1, []))
64 Supervisor.start_link(children ++ cachex_children,
65 strategy: :one_for_one,
66 name: Pleroma.Supervisor
69 if Pleroma.Config.get(:env) not in [:test, :benchmark] do
74 defp pleroma_rebooted? do
75 if Restarter.Pleroma.rebooted?() do
84 Application.load(:pleroma)
87 def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do
88 Keyword.get(options, opt) || shell_prompt(prompt, defval, defname)
91 def shell_prompt(prompt, defval \\ nil, defname \\ nil) do
92 prompt_message = "#{prompt} [#{defname || defval}] "
96 do: Mix.shell().prompt(prompt_message),
97 else: :io.get_line(prompt_message)
103 shell_prompt(prompt, defval, defname)
114 def shell_info(message) do
116 do: Mix.shell().info(message),
117 else: IO.puts(message)
120 def shell_error(message) do
122 do: Mix.shell().error(message),
123 else: IO.puts(:stderr, message)
126 @doc "Performs a safe check whether `Mix.shell/0` is available (does not raise if Mix is not loaded)"
127 def mix_shell?, do: :erlang.function_exported(Mix, :shell, 0)
129 def escape_sh_path(path) do
130 ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')
133 defp http_children(Tesla.Adapter.Gun) do
134 Pleroma.Gun.ConnectionPool.children() ++
135 [{Task, &Pleroma.HTTP.AdapterHelper.Gun.limiter_setup/0}]
138 defp http_children(_), do: []