1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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!()
30 defp handle_result(:ok), do: :ok
31 defp handle_result({:error, message}), do: raise(VerifyError, message: message)
33 defp check_welcome_message_config!(:ok) do
34 if Pleroma.Config.get([:welcome, :email, :enabled], false) and
35 not Pleroma.Emails.Mailer.enabled?() do
37 To send welcome email do you need to enable mail.
38 \nconfig :pleroma, Pleroma.Emails.Mailer, enabled: true
41 {:error, "The mail disabled."}
47 defp check_welcome_message_config!(result), do: result
49 # Checks account confirmation email
51 def check_confirmation_accounts!(:ok) do
52 if Pleroma.Config.get([:instance, :account_activation_required]) &&
53 not Pleroma.Config.get([Pleroma.Emails.Mailer, :enabled]) do
55 "Account activation enabled, but no Mailer settings enabled.\n" <>
56 "Please set config :pleroma, :instance, account_activation_required: false\n" <>
57 "Otherwise setup and enable Mailer."
61 "Account activation enabled, but Mailer is disabled. Cannot send confirmation emails."}
67 def check_confirmation_accounts!(result), do: result
69 # Checks for pending migrations.
71 def check_migrations_applied!(:ok) do
72 unless Pleroma.Config.get(
73 [:i_am_aware_this_may_cause_data_loss, :disable_migration_check],
77 Ecto.Migrator.with_repo(Pleroma.Repo, fn repo ->
79 Ecto.Migrator.migrations(repo)
82 {:down, _, _} -> false
85 if length(down_migrations) > 0 do
86 down_migrations_text =
87 Enum.map(down_migrations, fn {:down, id, name} -> "- #{name} (#{id})\n" end)
90 "The following migrations were not applied:\n#{down_migrations_text}" <>
91 "If you want to start Pleroma anyway, set\n" <>
92 "config :pleroma, :i_am_aware_this_may_cause_data_loss, disable_migration_check: true"
95 {:error, "Unapplied Migrations detected"}
107 def check_migrations_applied!(result), do: result
109 # Checks for settings of RUM indexes.
111 defp check_rum!(:ok) do
113 Ecto.Migrator.with_repo(Pleroma.Repo, fn repo ->
116 where: o.table_name == "objects",
117 where: o.column_name == "fts_content"
119 |> repo.exists?(prefix: "information_schema")
121 setting = Pleroma.Config.get([:database, :rum_enabled], false)
123 do_check_rum!(setting, migrate)
129 defp check_rum!(result), do: result
131 defp do_check_rum!(setting, migrate) do
132 case {setting, migrate} do
135 "Use `RUM` index is enabled, but were not applied migrations for it.\n" <>
136 "If you want to start Pleroma anyway, set\n" <>
137 "config :pleroma, :database, rum_enabled: false\n" <>
138 "Otherwise apply the following migrations:\n" <>
139 "`mix ecto.migrate --migrations-path priv/repo/optional_migrations/rum_indexing/`"
142 {:error, "Unapplied RUM Migrations detected"}
146 "Detected applied migrations to use `RUM` index, but `RUM` isn't enable in settings.\n" <>
147 "If you want to use `RUM`, set\n" <>
148 "config :pleroma, :database, rum_enabled: true\n" <>
149 "Otherwise roll `RUM` migrations back.\n" <>
150 "`mix ecto.rollback --migrations-path priv/repo/optional_migrations/rum_indexing/`"
153 {:error, "RUM Migrations detected"}
160 defp check_system_commands!(:ok) do
161 filter_commands_statuses = [
162 check_filter(Pleroma.Upload.Filters.Exiftool, "exiftool"),
163 check_filter(Pleroma.Upload.Filters.Mogrify, "mogrify"),
164 check_filter(Pleroma.Upload.Filters.Mogrifun, "mogrify")
167 preview_proxy_commands_status =
168 if !Config.get([:media_preview_proxy, :enabled]) or
169 MediaHelper.missing_dependencies() == [] do
173 "The following dependencies required by Media preview proxy " <>
174 "(which is currently enabled) are not installed: " <>
175 inspect(MediaHelper.missing_dependencies())
181 if Enum.all?([preview_proxy_commands_status | filter_commands_statuses], & &1) do
185 "System commands missing. Check logs and see `docs/installation` for more details."}
189 defp check_system_commands!(result), do: result
191 defp check_filter(filter, command_required) do
192 filters = Config.get([Pleroma.Upload, :filters])
194 if filter in filters and not Pleroma.Utils.command_available?(command_required) do
196 "#{filter} is specified in list of Pleroma.Upload filters, but the " <>
197 "#{command_required} command is not found"