1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 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: defexception([:message])
13 alias Pleroma.Helpers.MediaHelper
19 @spec verify!() :: :ok | VerifyError.t()
22 |> check_system_commands!()
23 |> check_confirmation_accounts!()
24 |> check_migrations_applied!()
25 |> check_welcome_message_config!()
27 |> check_repo_pool_size!()
31 defp handle_result(:ok), do: :ok
32 defp handle_result({:error, message}), do: raise(VerifyError, message: message)
34 defp check_welcome_message_config!(:ok) do
35 if Pleroma.Config.get([:welcome, :email, :enabled], false) and
36 not Pleroma.Emails.Mailer.enabled?() do
38 To send welcome emails, you need to enable the mailer.
39 Welcome emails will NOT be sent with the current config.
42 config :pleroma, Pleroma.Emails.Mailer, enabled: true
49 defp check_welcome_message_config!(result), do: result
51 # Checks account confirmation email
53 def check_confirmation_accounts!(:ok) do
54 if Pleroma.Config.get([:instance, :account_activation_required]) &&
55 not Pleroma.Emails.Mailer.enabled?() do
57 Account activation is required, but the mailer is disabled.
58 Users will NOT be able to confirm their accounts with this config.
59 Either disable account activation or enable the mailer.
61 Disable account activation:
62 config :pleroma, :instance, account_activation_required: false
65 config :pleroma, Pleroma.Emails.Mailer, enabled: true
72 def check_confirmation_accounts!(result), do: result
74 # Checks for pending migrations.
76 def check_migrations_applied!(:ok) do
77 unless Pleroma.Config.get(
78 [:i_am_aware_this_may_cause_data_loss, :disable_migration_check],
82 Ecto.Migrator.with_repo(Pleroma.Repo, fn repo ->
84 Ecto.Migrator.migrations(repo)
87 {:down, _, _} -> false
90 if length(down_migrations) > 0 do
91 down_migrations_text =
92 Enum.map(down_migrations, fn {:down, id, name} -> "- #{name} (#{id})\n" end)
95 "The following migrations were not applied:\n#{down_migrations_text}" <>
96 "If you want to start Pleroma anyway, set\n" <>
97 "config :pleroma, :i_am_aware_this_may_cause_data_loss, disable_migration_check: true"
100 {:error, "Unapplied Migrations detected"}
112 def check_migrations_applied!(result), do: result
114 # Checks for settings of RUM indexes.
116 defp check_rum!(:ok) do
118 Ecto.Migrator.with_repo(Pleroma.Repo, fn repo ->
121 where: o.table_name == "objects",
122 where: o.column_name == "fts_content"
124 |> repo.exists?(prefix: "information_schema")
126 setting = Pleroma.Config.get([:database, :rum_enabled], false)
128 do_check_rum!(setting, migrate)
134 defp check_rum!(result), do: result
136 defp do_check_rum!(setting, migrate) do
137 case {setting, migrate} do
140 "Use `RUM` index is enabled, but were not applied migrations for it.\n" <>
141 "If you want to start Pleroma anyway, set\n" <>
142 "config :pleroma, :database, rum_enabled: false\n" <>
143 "Otherwise apply the following migrations:\n" <>
144 "`mix ecto.migrate --migrations-path priv/repo/optional_migrations/rum_indexing/`"
147 {:error, "Unapplied RUM Migrations detected"}
151 "Detected applied migrations to use `RUM` index, but `RUM` isn't enable in settings.\n" <>
152 "If you want to use `RUM`, set\n" <>
153 "config :pleroma, :database, rum_enabled: true\n" <>
154 "Otherwise roll `RUM` migrations back.\n" <>
155 "`mix ecto.rollback --migrations-path priv/repo/optional_migrations/rum_indexing/`"
158 {:error, "RUM Migrations detected"}
165 defp check_system_commands!(:ok) do
166 filter_commands_statuses = [
167 check_filter(Pleroma.Upload.Filter.Exiftool, "exiftool"),
168 check_filter(Pleroma.Upload.Filter.Mogrify, "mogrify"),
169 check_filter(Pleroma.Upload.Filter.Mogrifun, "mogrify"),
170 check_filter(Pleroma.Upload.Filter.AnalyzeMetadata, "mogrify"),
171 check_filter(Pleroma.Upload.Filter.AnalyzeMetadata, "convert")
174 preview_proxy_commands_status =
175 if !Config.get([:media_preview_proxy, :enabled]) or
176 MediaHelper.missing_dependencies() == [] do
180 "The following dependencies required by Media preview proxy " <>
181 "(which is currently enabled) are not installed: " <>
182 inspect(MediaHelper.missing_dependencies())
188 if Enum.all?([preview_proxy_commands_status | filter_commands_statuses], & &1) do
192 "System commands missing. Check logs and see `docs/installation` for more details."}
196 defp check_system_commands!(result), do: result
198 defp check_repo_pool_size!(:ok) do
199 if Pleroma.Config.get([Pleroma.Repo, :pool_size], 10) != 10 and
200 not Pleroma.Config.get([:dangerzone, :override_repo_pool_size], false) do
204 The database pool size has been altered from the recommended value of 10.
206 Please revert or ensure your database is tuned appropriately and then set
207 `config :pleroma, :dangerzone, override_repo_pool_size: true`.
209 If you are experiencing database timeouts, please check the "Optimizing
210 your PostgreSQL performance" section in the documentation. If you still
211 encounter issues after that, please open an issue on the tracker.
214 {:error, "Repo.pool_size different than recommended value."}
220 defp check_repo_pool_size!(result), do: result
222 defp check_filter(filter, command_required) do
223 filters = Config.get([Pleroma.Upload, :filters])
225 if filter in filters and not Pleroma.Utils.command_available?(command_required) do
227 "#{filter} is specified in list of Pleroma.Upload filters, but the " <>
228 "#{command_required} command is not found"