1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.ApplicationRequirements do
7 The module represents the collection of validations to runs before start server.
10 defmodule VerifyError do
11 defexception([:message])
12 @type t :: %__MODULE__{}
16 alias Pleroma.Helpers.MediaHelper
22 @spec verify!() :: :ok | VerifyError.t()
25 |> check_system_commands!()
26 |> check_confirmation_accounts!()
27 |> check_migrations_applied!()
28 |> check_welcome_message_config!()
30 |> check_repo_pool_size!()
34 defp handle_result(:ok), do: :ok
35 defp handle_result({:error, message}), do: raise(VerifyError, message: message)
37 defp check_welcome_message_config!(:ok) do
38 if Pleroma.Config.get([:welcome, :email, :enabled], false) and
39 not Pleroma.Emails.Mailer.enabled?() do
41 To send welcome emails, you need to enable the mailer.
42 Welcome emails will NOT be sent with the current config.
45 config :pleroma, Pleroma.Emails.Mailer, enabled: true
52 defp check_welcome_message_config!(result), do: result
54 # Checks account confirmation email
56 def check_confirmation_accounts!(:ok) do
57 if Pleroma.Config.get([:instance, :account_activation_required]) &&
58 not Pleroma.Emails.Mailer.enabled?() do
60 Account activation is required, but the mailer is disabled.
61 Users will NOT be able to confirm their accounts with this config.
62 Either disable account activation or enable the mailer.
64 Disable account activation:
65 config :pleroma, :instance, account_activation_required: false
68 config :pleroma, Pleroma.Emails.Mailer, enabled: true
75 def check_confirmation_accounts!(result), do: result
77 # Checks for pending migrations.
79 def check_migrations_applied!(:ok) do
80 unless Pleroma.Config.get(
81 [:i_am_aware_this_may_cause_data_loss, :disable_migration_check],
85 Ecto.Migrator.with_repo(Pleroma.Repo, fn repo ->
87 Ecto.Migrator.migrations(repo)
90 {:down, _, _} -> false
93 if length(down_migrations) > 0 do
94 down_migrations_text =
95 Enum.map(down_migrations, fn {:down, id, name} -> "- #{name} (#{id})\n" end)
98 "The following migrations were not applied:\n#{down_migrations_text}" <>
99 "If you want to start Pleroma anyway, set\n" <>
100 "config :pleroma, :i_am_aware_this_may_cause_data_loss, disable_migration_check: true"
103 {:error, "Unapplied Migrations detected"}
115 def check_migrations_applied!(result), do: result
117 # Checks for settings of RUM indexes.
119 defp check_rum!(:ok) do
121 Ecto.Migrator.with_repo(Pleroma.Repo, fn repo ->
124 where: o.table_name == "objects",
125 where: o.column_name == "fts_content"
127 |> repo.exists?(prefix: "information_schema")
129 setting = Pleroma.Config.get([:database, :rum_enabled], false)
131 do_check_rum!(setting, migrate)
137 defp check_rum!(result), do: result
139 defp do_check_rum!(setting, migrate) do
140 case {setting, migrate} do
143 "Use `RUM` index is enabled, but were not applied migrations for it.\n" <>
144 "If you want to start Pleroma anyway, set\n" <>
145 "config :pleroma, :database, rum_enabled: false\n" <>
146 "Otherwise apply the following migrations:\n" <>
147 "`mix ecto.migrate --migrations-path priv/repo/optional_migrations/rum_indexing/`"
150 {:error, "Unapplied RUM Migrations detected"}
154 "Detected applied migrations to use `RUM` index, but `RUM` isn't enable in settings.\n" <>
155 "If you want to use `RUM`, set\n" <>
156 "config :pleroma, :database, rum_enabled: true\n" <>
157 "Otherwise roll `RUM` migrations back.\n" <>
158 "`mix ecto.rollback --migrations-path priv/repo/optional_migrations/rum_indexing/`"
161 {:error, "RUM Migrations detected"}
168 defp check_system_commands!(:ok) do
169 filter_commands_statuses = [
170 check_filter(Pleroma.Upload.Filter.Exiftool.StripLocation, "exiftool"),
171 check_filter(Pleroma.Upload.Filter.Exiftool.ReadDescription, "exiftool"),
172 check_filter(Pleroma.Upload.Filter.Mogrify, "mogrify"),
173 check_filter(Pleroma.Upload.Filter.Mogrifun, "mogrify"),
174 check_filter(Pleroma.Upload.Filter.AnalyzeMetadata, "ffprobe")
177 preview_proxy_commands_status =
178 if !Config.get([:media_preview_proxy, :enabled]) or
179 MediaHelper.missing_dependencies() == [] do
183 "The following dependencies required by Media preview proxy " <>
184 "(which is currently enabled) are not installed: " <>
185 inspect(MediaHelper.missing_dependencies())
191 if Enum.all?([preview_proxy_commands_status | filter_commands_statuses], & &1) do
195 "System commands missing. Check logs and see `docs/installation` for more details."}
199 defp check_repo_pool_size!(:ok) do
200 if Pleroma.Config.get([Pleroma.Repo, :pool_size], 10) != 10 and
201 not Pleroma.Config.get([:dangerzone, :override_repo_pool_size], false) do
205 The database pool size has been altered from the recommended value of 10.
207 Please revert or ensure your database is tuned appropriately and then set
208 `config :pleroma, :dangerzone, override_repo_pool_size: true`.
210 If you are experiencing database timeouts, please check the "Optimizing
211 your PostgreSQL performance" section in the documentation. If you still
212 encounter issues after that, please open an issue on the tracker.
215 {:error, "Repo.pool_size different than recommended value."}
221 defp check_repo_pool_size!(result), do: result
223 defp check_filter(filter, command_required) do
224 filters = Config.get([Pleroma.Upload, :filters])
226 if filter in filters and not Pleroma.Utils.command_available?(command_required) do
228 "#{filter} is specified in list of Pleroma.Upload filters, but the " <>
229 "#{command_required} command is not found"