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
18 @cachex_children ["object", "user", "scrubber", "web_resp"]
19 @doc "Common functions to be reused in mix tasks"
21 Pleroma.Config.Holder.save_default()
22 Pleroma.Config.Oban.warn()
23 Pleroma.Application.limiters_setup()
24 Application.put_env(:phoenix, :serve_endpoints, false, persistent: true)
26 unless System.get_env("DEBUG") do
27 Logger.remove_backend(:console)
30 adapter = Application.get_env(:tesla, :adapter)
33 if adapter == Tesla.Adapter.Gun do
39 Enum.each(apps, &Application.ensure_all_started/1)
53 {Pleroma.Config.TransferTask, false},
57 [name: Pleroma.MajicPool, pool_size: Pleroma.Config.get([:majic_pool, :size], 2)]}
59 http_children(adapter)
61 cachex_children = Enum.map(@cachex_children, &Pleroma.Application.build_cachex(&1, []))
63 Supervisor.start_link(children ++ cachex_children,
64 strategy: :one_for_one,
65 name: Pleroma.Supervisor
68 if Pleroma.Config.get(:env) not in [:test, :benchmark] do
73 defp pleroma_rebooted? do
74 if Restarter.Pleroma.rebooted?() do
83 Application.load(:pleroma)
86 def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do
87 Keyword.get(options, opt) || shell_prompt(prompt, defval, defname)
90 def shell_prompt(prompt, defval \\ nil, defname \\ nil) do
91 prompt_message = "#{prompt} [#{defname || defval}] "
95 do: Mix.shell().prompt(prompt_message),
96 else: :io.get_line(prompt_message)
102 shell_prompt(prompt, defval, defname)
113 def shell_info(message) do
115 do: Mix.shell().info(message),
116 else: IO.puts(message)
119 def shell_error(message) do
121 do: Mix.shell().error(message),
122 else: IO.puts(:stderr, message)
125 @doc "Performs a safe check whether `Mix.shell/0` is available (does not raise if Mix is not loaded)"
126 def mix_shell?, do: :erlang.function_exported(Mix, :shell, 0)
128 def escape_sh_path(path) do
129 ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')
132 defp http_children(Tesla.Adapter.Gun) do
133 Pleroma.Gun.ConnectionPool.children() ++
134 [{Task, &Pleroma.HTTP.AdapterHelper.Gun.limiter_setup/0}]
137 defp http_children(_), do: []