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 email do you need to enable mail.
39 \nconfig :pleroma, Pleroma.Emails.Mailer, enabled: true
42 {:error, "The mail disabled."}
48 defp check_welcome_message_config!(result), do: result
50 # Checks account confirmation email
52 def check_confirmation_accounts!(:ok) do
53 if Pleroma.Config.get([:instance, :account_activation_required]) &&
54 not Pleroma.Config.get([Pleroma.Emails.Mailer, :enabled]) do
56 "Account activation enabled, but no Mailer settings enabled.\n" <>
57 "Please set config :pleroma, :instance, account_activation_required: false\n" <>
58 "Otherwise setup and enable Mailer."
62 "Account activation enabled, but Mailer is disabled. Cannot send confirmation emails."}
68 def check_confirmation_accounts!(result), do: result
70 # Checks for pending migrations.
72 def check_migrations_applied!(:ok) do
73 unless Pleroma.Config.get(
74 [:i_am_aware_this_may_cause_data_loss, :disable_migration_check],
78 Ecto.Migrator.with_repo(Pleroma.Repo, fn repo ->
80 Ecto.Migrator.migrations(repo)
83 {:down, _, _} -> false
86 if length(down_migrations) > 0 do
87 down_migrations_text =
88 Enum.map(down_migrations, fn {:down, id, name} -> "- #{name} (#{id})\n" end)
91 "The following migrations were not applied:\n#{down_migrations_text}" <>
92 "If you want to start Pleroma anyway, set\n" <>
93 "config :pleroma, :i_am_aware_this_may_cause_data_loss, disable_migration_check: true"
96 {:error, "Unapplied Migrations detected"}
108 def check_migrations_applied!(result), do: result
110 # Checks for settings of RUM indexes.
112 defp check_rum!(:ok) do
114 Ecto.Migrator.with_repo(Pleroma.Repo, fn repo ->
117 where: o.table_name == "objects",
118 where: o.column_name == "fts_content"
120 |> repo.exists?(prefix: "information_schema")
122 setting = Pleroma.Config.get([:database, :rum_enabled], false)
124 do_check_rum!(setting, migrate)
130 defp check_rum!(result), do: result
132 defp do_check_rum!(setting, migrate) do
133 case {setting, migrate} do
136 "Use `RUM` index is enabled, but were not applied migrations for it.\n" <>
137 "If you want to start Pleroma anyway, set\n" <>
138 "config :pleroma, :database, rum_enabled: false\n" <>
139 "Otherwise apply the following migrations:\n" <>
140 "`mix ecto.migrate --migrations-path priv/repo/optional_migrations/rum_indexing/`"
143 {:error, "Unapplied RUM Migrations detected"}
147 "Detected applied migrations to use `RUM` index, but `RUM` isn't enable in settings.\n" <>
148 "If you want to use `RUM`, set\n" <>
149 "config :pleroma, :database, rum_enabled: true\n" <>
150 "Otherwise roll `RUM` migrations back.\n" <>
151 "`mix ecto.rollback --migrations-path priv/repo/optional_migrations/rum_indexing/`"
154 {:error, "RUM Migrations detected"}
161 defp check_system_commands!(:ok) do
162 filter_commands_statuses = [
163 check_filter(Pleroma.Upload.Filters.Exiftool, "exiftool"),
164 check_filter(Pleroma.Upload.Filters.Mogrify, "mogrify"),
165 check_filter(Pleroma.Upload.Filters.Mogrifun, "mogrify")
168 preview_proxy_commands_status =
169 if !Config.get([:media_preview_proxy, :enabled]) or
170 MediaHelper.missing_dependencies() == [] do
174 "The following dependencies required by Media preview proxy " <>
175 "(which is currently enabled) are not installed: " <>
176 inspect(MediaHelper.missing_dependencies())
182 if Enum.all?([preview_proxy_commands_status | filter_commands_statuses], & &1) do
186 "System commands missing. Check logs and see `docs/installation` for more details."}
190 defp check_system_commands!(result), do: result
192 defp check_repo_pool_size!(:ok) do
193 if Pleroma.Config.get([Pleroma.Repo, :pool_size], 10) != 10 and
194 not Pleroma.Config.get([:dangerzone, :override_repo_pool_size], false) do
198 The database pool size has been altered from the recommended value of 10.
200 Please revert or ensure your database is tuned appropriately and then set
201 `config :pleroma, :dangerzone, override_repo_pool_size: true`.
203 If you are experiencing database timeouts, please check the "Optimizing
204 your PostgreSQL performance" section in the documentation. If you still
205 encounter issues after that, please open an issue on the tracker.
208 {:error, "Repo.pool_size different than recommended value."}
214 defp check_repo_pool_size!(result), do: result
216 defp check_filter(filter, command_required) do
217 filters = Config.get([Pleroma.Upload, :filters])
219 if filter in filters and not Pleroma.Utils.command_available?(command_required) do
221 "#{filter} is specified in list of Pleroma.Upload filters, but the " <>
222 "#{command_required} command is not found"