Local copy of Pleroma, an ActivityPub server software. Contains modifications running live on fedi.underscore.world
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

application.ex 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Application do
  5. use Application
  6. @name Mix.Project.config()[:name]
  7. @version Mix.Project.config()[:version]
  8. @repository Mix.Project.config()[:source_url]
  9. def name, do: @name
  10. def version, do: @version
  11. def named_version, do: @name <> " " <> @version
  12. def repository, do: @repository
  13. def user_agent do
  14. info = "#{Pleroma.Web.base_url()} <#{Pleroma.Config.get([:instance, :email], "")}>"
  15. named_version() <> "; " <> info
  16. end
  17. # See http://elixir-lang.org/docs/stable/elixir/Application.html
  18. # for more information on OTP Applications
  19. def start(_type, _args) do
  20. import Cachex.Spec
  21. Pleroma.Config.DeprecationWarnings.warn()
  22. setup_instrumenters()
  23. # Define workers and child supervisors to be supervised
  24. children =
  25. [
  26. # Start the Ecto repository
  27. %{id: Pleroma.Repo, start: {Pleroma.Repo, :start_link, []}, type: :supervisor},
  28. %{id: Pleroma.Config.TransferTask, start: {Pleroma.Config.TransferTask, :start_link, []}},
  29. %{id: Pleroma.Emoji, start: {Pleroma.Emoji, :start_link, []}},
  30. %{id: Pleroma.Captcha, start: {Pleroma.Captcha, :start_link, []}},
  31. %{
  32. id: :cachex_used_captcha_cache,
  33. start:
  34. {Cachex, :start_link,
  35. [
  36. :used_captcha_cache,
  37. [
  38. ttl_interval:
  39. :timer.seconds(Pleroma.Config.get!([Pleroma.Captcha, :seconds_valid]))
  40. ]
  41. ]}
  42. },
  43. %{
  44. id: :cachex_user,
  45. start:
  46. {Cachex, :start_link,
  47. [
  48. :user_cache,
  49. [
  50. default_ttl: 25_000,
  51. ttl_interval: 1000,
  52. limit: 2500
  53. ]
  54. ]}
  55. },
  56. %{
  57. id: :cachex_object,
  58. start:
  59. {Cachex, :start_link,
  60. [
  61. :object_cache,
  62. [
  63. default_ttl: 25_000,
  64. ttl_interval: 1000,
  65. limit: 2500
  66. ]
  67. ]}
  68. },
  69. %{
  70. id: :cachex_rich_media,
  71. start:
  72. {Cachex, :start_link,
  73. [
  74. :rich_media_cache,
  75. [
  76. default_ttl: :timer.minutes(120),
  77. limit: 5000
  78. ]
  79. ]}
  80. },
  81. %{
  82. id: :cachex_scrubber,
  83. start:
  84. {Cachex, :start_link,
  85. [
  86. :scrubber_cache,
  87. [
  88. limit: 2500
  89. ]
  90. ]}
  91. },
  92. %{
  93. id: :cachex_idem,
  94. start:
  95. {Cachex, :start_link,
  96. [
  97. :idempotency_cache,
  98. [
  99. expiration:
  100. expiration(
  101. default: :timer.seconds(6 * 60 * 60),
  102. interval: :timer.seconds(60)
  103. ),
  104. limit: 2500
  105. ]
  106. ]}
  107. },
  108. %{id: Pleroma.FlakeId, start: {Pleroma.FlakeId, :start_link, []}},
  109. %{
  110. id: Pleroma.ScheduledActivityWorker,
  111. start: {Pleroma.ScheduledActivityWorker, :start_link, []}
  112. }
  113. ] ++
  114. hackney_pool_children() ++
  115. [
  116. %{
  117. id: Pleroma.Web.Federator.RetryQueue,
  118. start: {Pleroma.Web.Federator.RetryQueue, :start_link, []}
  119. },
  120. %{
  121. id: Pleroma.Web.OAuth.Token.CleanWorker,
  122. start: {Pleroma.Web.OAuth.Token.CleanWorker, :start_link, []}
  123. },
  124. %{
  125. id: Pleroma.Stats,
  126. start: {Pleroma.Stats, :start_link, []}
  127. },
  128. %{
  129. id: :web_push_init,
  130. start: {Task, :start_link, [&Pleroma.Web.Push.init/0]},
  131. restart: :temporary
  132. },
  133. %{
  134. id: :federator_init,
  135. start: {Task, :start_link, [&Pleroma.Web.Federator.init/0]},
  136. restart: :temporary
  137. },
  138. %{
  139. id: :internal_fetch_init,
  140. start: {Task, :start_link, [&Pleroma.Web.ActivityPub.InternalFetchActor.init/0]},
  141. restart: :temporary
  142. }
  143. ] ++
  144. streamer_child() ++
  145. chat_child() ++
  146. [
  147. # Start the endpoint when the application starts
  148. %{
  149. id: Pleroma.Web.Endpoint,
  150. start: {Pleroma.Web.Endpoint, :start_link, []},
  151. type: :supervisor
  152. },
  153. %{id: Pleroma.Gopher.Server, start: {Pleroma.Gopher.Server, :start_link, []}}
  154. ]
  155. # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
  156. # for other strategies and supported options
  157. opts = [strategy: :one_for_one, name: Pleroma.Supervisor]
  158. result = Supervisor.start_link(children, opts)
  159. :ok = after_supervisor_start()
  160. result
  161. end
  162. defp setup_instrumenters do
  163. require Prometheus.Registry
  164. if Application.get_env(:prometheus, Pleroma.Repo.Instrumenter) do
  165. :ok =
  166. :telemetry.attach(
  167. "prometheus-ecto",
  168. [:pleroma, :repo, :query],
  169. &Pleroma.Repo.Instrumenter.handle_event/4,
  170. %{}
  171. )
  172. Pleroma.Repo.Instrumenter.setup()
  173. end
  174. Pleroma.Web.Endpoint.MetricsExporter.setup()
  175. Pleroma.Web.Endpoint.PipelineInstrumenter.setup()
  176. Pleroma.Web.Endpoint.Instrumenter.setup()
  177. end
  178. def enabled_hackney_pools do
  179. [:media] ++
  180. if Application.get_env(:tesla, :adapter) == Tesla.Adapter.Hackney do
  181. [:federation]
  182. else
  183. []
  184. end ++
  185. if Pleroma.Config.get([Pleroma.Upload, :proxy_remote]) do
  186. [:upload]
  187. else
  188. []
  189. end
  190. end
  191. if Pleroma.Config.get(:env) == :test do
  192. defp streamer_child, do: []
  193. defp chat_child, do: []
  194. else
  195. defp streamer_child do
  196. [%{id: Pleroma.Web.Streamer, start: {Pleroma.Web.Streamer, :start_link, []}}]
  197. end
  198. defp chat_child do
  199. if Pleroma.Config.get([:chat, :enabled]) do
  200. [
  201. %{
  202. id: Pleroma.Web.ChatChannel.ChatChannelState,
  203. start: {Pleroma.Web.ChatChannel.ChatChannelState, :start_link, []}
  204. }
  205. ]
  206. else
  207. []
  208. end
  209. end
  210. end
  211. defp hackney_pool_children do
  212. for pool <- enabled_hackney_pools() do
  213. options = Pleroma.Config.get([:hackney_pools, pool])
  214. :hackney_pool.child_spec(pool, options)
  215. end
  216. end
  217. defp after_supervisor_start do
  218. with digest_config <- Application.get_env(:pleroma, :email_notifications)[:digest],
  219. true <- digest_config[:active] do
  220. PleromaJobQueue.schedule(
  221. digest_config[:schedule],
  222. :digest_emails,
  223. Pleroma.DigestEmailWorker
  224. )
  225. end
  226. :ok
  227. end
  228. end