logo

pleroma

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

pleroma.ex (3353B)


  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. Logger.remove_backend(:console)
  28. end
  29. adapter = Application.get_env(:tesla, :adapter)
  30. apps =
  31. if adapter == Tesla.Adapter.Gun do
  32. [:gun | @apps]
  33. else
  34. [:hackney | @apps]
  35. end
  36. Enum.each(apps, &Application.ensure_all_started/1)
  37. oban_config = [
  38. crontab: [],
  39. repo: Pleroma.Repo,
  40. log: false,
  41. queues: [],
  42. plugins: []
  43. ]
  44. children =
  45. [
  46. Pleroma.Repo,
  47. Pleroma.Emoji,
  48. {Pleroma.Config.TransferTask, false},
  49. Pleroma.Web.Endpoint,
  50. {Oban, oban_config},
  51. {Majic.Pool,
  52. [name: Pleroma.MajicPool, pool_size: Pleroma.Config.get([:majic_pool, :size], 2)]}
  53. ] ++
  54. http_children(adapter)
  55. cachex_children = Enum.map(@cachex_children, &Pleroma.Application.build_cachex(&1, []))
  56. Supervisor.start_link(children ++ cachex_children,
  57. strategy: :one_for_one,
  58. name: Pleroma.Supervisor
  59. )
  60. if Pleroma.Config.get(:env) not in [:test, :benchmark] do
  61. pleroma_rebooted?()
  62. end
  63. end
  64. defp pleroma_rebooted? do
  65. if Restarter.Pleroma.rebooted?() do
  66. :ok
  67. else
  68. Process.sleep(10)
  69. pleroma_rebooted?()
  70. end
  71. end
  72. def load_pleroma do
  73. Application.load(:pleroma)
  74. end
  75. def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do
  76. Keyword.get(options, opt) || shell_prompt(prompt, defval, defname)
  77. end
  78. def shell_prompt(prompt, defval \\ nil, defname \\ nil) do
  79. prompt_message = "#{prompt} [#{defname || defval}] "
  80. input =
  81. if mix_shell?(),
  82. do: Mix.shell().prompt(prompt_message),
  83. else: :io.get_line(prompt_message)
  84. case input do
  85. "\n" ->
  86. case defval do
  87. nil ->
  88. shell_prompt(prompt, defval, defname)
  89. defval ->
  90. defval
  91. end
  92. input ->
  93. String.trim(input)
  94. end
  95. end
  96. def shell_info(message) do
  97. if mix_shell?(),
  98. do: Mix.shell().info(message),
  99. else: IO.puts(message)
  100. end
  101. def shell_error(message) do
  102. if mix_shell?(),
  103. do: Mix.shell().error(message),
  104. else: IO.puts(:stderr, message)
  105. end
  106. @doc "Performs a safe check whether `Mix.shell/0` is available (does not raise if Mix is not loaded)"
  107. def mix_shell?, do: :erlang.function_exported(Mix, :shell, 0)
  108. def escape_sh_path(path) do
  109. ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')
  110. end
  111. defp http_children(Tesla.Adapter.Gun) do
  112. Pleroma.Gun.ConnectionPool.children() ++
  113. [{Task, &Pleroma.HTTP.AdapterHelper.Gun.limiter_setup/0}]
  114. end
  115. defp http_children(_), do: []
  116. end