logo

pleroma

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

pleroma.ex (3331B)


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