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)
26 Finch.start_link(name: MyFinch)
29 unless System.get_env("DEBUG") do
30 Logger.remove_backend(:console)
33 Enum.each(@apps, &Application.ensure_all_started/1)
47 {Pleroma.Config.TransferTask, false},
51 [name: Pleroma.MajicPool, pool_size: Pleroma.Config.get([:majic_pool, :size], 2)]}
53 elasticsearch_children()
55 cachex_children = Enum.map(@cachex_children, &Pleroma.Application.build_cachex(&1, []))
57 Supervisor.start_link(children ++ cachex_children,
58 strategy: :one_for_one,
59 name: Pleroma.Supervisor
62 if Pleroma.Config.get(:env) not in [:test, :benchmark] do
67 defp pleroma_rebooted? do
68 if Restarter.Pleroma.rebooted?() do
77 Application.load(:pleroma)
80 def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do
81 Keyword.get(options, opt) || shell_prompt(prompt, defval, defname)
84 def shell_prompt(prompt, defval \\ nil, defname \\ nil) do
85 prompt_message = "#{prompt} [#{defname || defval}] "
89 do: Mix.shell().prompt(prompt_message),
90 else: :io.get_line(prompt_message)
96 shell_prompt(prompt, defval, defname)
107 def shell_info(message) do
109 do: Mix.shell().info(message),
110 else: IO.puts(message)
113 def shell_error(message) do
115 do: Mix.shell().error(message),
116 else: IO.puts(:stderr, message)
119 @doc "Performs a safe check whether `Mix.shell/0` is available (does not raise if Mix is not loaded)"
120 def mix_shell?, do: :erlang.function_exported(Mix, :shell, 0)
122 def escape_sh_path(path) do
123 ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')
126 def elasticsearch_children do
127 config = Pleroma.Config.get([Pleroma.Search, :module])
129 if config == Pleroma.Search.Elasticsearch do
130 [Pleroma.Search.Elasticsearch.Cluster]