logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

pleroma.ex (3414B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Mix.Pleroma do
  5. @apps [
  6. :restarter,
  7. :ecto,
  8. :ecto_sql,
  9. :postgrex,
  10. :db_connection,
  11. :cachex,
  12. :flake_id,
  13. :swoosh,
  14. :timex,
  15. :fast_html,
  16. :oban,
  17. :logger_backends
  18. ]
  19. @cachex_children ["object", "user", "scrubber", "web_resp"]
  20. @doc "Common functions to be reused in mix tasks"
  21. def start_pleroma do
  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. unless System.get_env("DEBUG") do
  27. try do
  28. Logger.remove_backend(:console)
  29. catch
  30. :exit, _ -> :ok
  31. end
  32. end
  33. adapter = Application.get_env(:tesla, :adapter)
  34. apps =
  35. if adapter == Tesla.Adapter.Gun do
  36. [:gun | @apps]
  37. else
  38. [:hackney | @apps]
  39. end
  40. Enum.each(apps, &Application.ensure_all_started/1)
  41. oban_config = [
  42. crontab: [],
  43. repo: Pleroma.Repo,
  44. log: false,
  45. queues: [],
  46. plugins: []
  47. ]
  48. children =
  49. [
  50. Pleroma.Repo,
  51. Pleroma.Emoji,
  52. {Pleroma.Config.TransferTask, false},
  53. Pleroma.Web.Endpoint,
  54. {Oban, oban_config},
  55. {Majic.Pool,
  56. [name: Pleroma.MajicPool, pool_size: Pleroma.Config.get([:majic_pool, :size], 2)]}
  57. ] ++
  58. http_children(adapter)
  59. cachex_children = Enum.map(@cachex_children, &Pleroma.Application.build_cachex(&1, []))
  60. Supervisor.start_link(children ++ cachex_children,
  61. strategy: :one_for_one,
  62. name: Pleroma.Supervisor
  63. )
  64. if Pleroma.Config.get(:env) not in [:test, :benchmark] do
  65. pleroma_rebooted?()
  66. end
  67. end
  68. defp pleroma_rebooted? do
  69. if Restarter.Pleroma.rebooted?() do
  70. :ok
  71. else
  72. Process.sleep(10)
  73. pleroma_rebooted?()
  74. end
  75. end
  76. def load_pleroma do
  77. Application.load(:pleroma)
  78. end
  79. def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do
  80. Keyword.get(options, opt) || shell_prompt(prompt, defval, defname)
  81. end
  82. def shell_prompt(prompt, defval \\ nil, defname \\ nil) do
  83. prompt_message = "#{prompt} [#{defname || defval}] "
  84. input =
  85. if mix_shell?(),
  86. do: Mix.shell().prompt(prompt_message),
  87. else: :io.get_line(prompt_message)
  88. case input do
  89. "\n" ->
  90. case defval do
  91. nil ->
  92. shell_prompt(prompt, defval, defname)
  93. defval ->
  94. defval
  95. end
  96. input ->
  97. String.trim(input)
  98. end
  99. end
  100. def shell_info(message) do
  101. if mix_shell?(),
  102. do: Mix.shell().info(message),
  103. else: IO.puts(message)
  104. end
  105. def shell_error(message) do
  106. if mix_shell?(),
  107. do: Mix.shell().error(message),
  108. else: IO.puts(:stderr, message)
  109. end
  110. @doc "Performs a safe check whether `Mix.shell/0` is available (does not raise if Mix is not loaded)"
  111. def mix_shell?, do: :erlang.function_exported(Mix, :shell, 0)
  112. def escape_sh_path(path) do
  113. ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')
  114. end
  115. defp http_children(Tesla.Adapter.Gun) do
  116. Pleroma.Gun.ConnectionPool.children() ++
  117. [{Task, &Pleroma.HTTP.AdapterHelper.Gun.limiter_setup/0}]
  118. end
  119. defp http_children(_), do: []
  120. end