2020-06-22 14:27:49 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 20:38:50 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2020-06-22 14:27:49 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.ApplicationRequirements do
|
|
|
|
@moduledoc """
|
|
|
|
The module represents the collection of validations to runs before start server.
|
|
|
|
"""
|
|
|
|
|
|
|
|
defmodule VerifyError, do: defexception([:message])
|
|
|
|
|
2020-09-29 13:28:06 +00:00
|
|
|
alias Pleroma.Config
|
|
|
|
alias Pleroma.Helpers.MediaHelper
|
|
|
|
|
2020-06-22 14:27:49 +00:00
|
|
|
import Ecto.Query
|
|
|
|
|
|
|
|
require Logger
|
|
|
|
|
|
|
|
@spec verify!() :: :ok | VerifyError.t()
|
|
|
|
def verify! do
|
|
|
|
:ok
|
2020-09-29 13:28:06 +00:00
|
|
|
|> check_system_commands!()
|
|
|
|
|> check_confirmation_accounts!()
|
2020-06-22 14:27:49 +00:00
|
|
|
|> check_migrations_applied!()
|
2020-07-23 03:51:19 +00:00
|
|
|
|> check_welcome_message_config!()
|
2020-06-22 14:27:49 +00:00
|
|
|
|> check_rum!()
|
2020-12-07 22:36:44 +00:00
|
|
|
|> check_repo_pool_size!()
|
2020-06-22 14:27:49 +00:00
|
|
|
|> handle_result()
|
|
|
|
end
|
|
|
|
|
|
|
|
defp handle_result(:ok), do: :ok
|
|
|
|
defp handle_result({:error, message}), do: raise(VerifyError, message: message)
|
|
|
|
|
2020-07-23 03:51:19 +00:00
|
|
|
defp check_welcome_message_config!(:ok) do
|
|
|
|
if Pleroma.Config.get([:welcome, :email, :enabled], false) and
|
|
|
|
not Pleroma.Emails.Mailer.enabled?() do
|
2021-05-03 19:27:03 +00:00
|
|
|
Logger.warn("""
|
|
|
|
To send welcome emails, you need to enable the mailer.
|
|
|
|
Welcome emails will NOT be sent with the current config.
|
2020-07-23 03:51:19 +00:00
|
|
|
|
2021-05-03 19:27:03 +00:00
|
|
|
Enable the mailer:
|
|
|
|
config :pleroma, Pleroma.Emails.Mailer, enabled: true
|
|
|
|
""")
|
2020-07-23 03:51:19 +00:00
|
|
|
end
|
2021-05-03 19:27:03 +00:00
|
|
|
|
|
|
|
:ok
|
2020-07-23 03:51:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
defp check_welcome_message_config!(result), do: result
|
|
|
|
|
2020-07-11 04:20:35 +00:00
|
|
|
# Checks account confirmation email
|
|
|
|
#
|
|
|
|
def check_confirmation_accounts!(:ok) do
|
|
|
|
if Pleroma.Config.get([:instance, :account_activation_required]) &&
|
2021-05-03 19:27:03 +00:00
|
|
|
not Pleroma.Emails.Mailer.enabled?() do
|
|
|
|
Logger.warn("""
|
|
|
|
Account activation is required, but the mailer is disabled.
|
|
|
|
Users will NOT be able to confirm their accounts with this config.
|
|
|
|
Either disable account activation or enable the mailer.
|
|
|
|
|
|
|
|
Disable account activation:
|
|
|
|
config :pleroma, :instance, account_activation_required: false
|
|
|
|
|
|
|
|
Enable the mailer:
|
|
|
|
config :pleroma, Pleroma.Emails.Mailer, enabled: true
|
|
|
|
""")
|
2020-07-11 04:20:35 +00:00
|
|
|
end
|
2021-05-03 19:27:03 +00:00
|
|
|
|
|
|
|
:ok
|
2020-07-11 04:20:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def check_confirmation_accounts!(result), do: result
|
|
|
|
|
2020-06-23 03:56:17 +00:00
|
|
|
# Checks for pending migrations.
|
|
|
|
#
|
|
|
|
def check_migrations_applied!(:ok) do
|
2020-06-22 14:27:49 +00:00
|
|
|
unless Pleroma.Config.get(
|
|
|
|
[:i_am_aware_this_may_cause_data_loss, :disable_migration_check],
|
|
|
|
false
|
|
|
|
) do
|
|
|
|
{_, res, _} =
|
|
|
|
Ecto.Migrator.with_repo(Pleroma.Repo, fn repo ->
|
|
|
|
down_migrations =
|
|
|
|
Ecto.Migrator.migrations(repo)
|
|
|
|
|> Enum.reject(fn
|
|
|
|
{:up, _, _} -> true
|
|
|
|
{:down, _, _} -> false
|
|
|
|
end)
|
|
|
|
|
|
|
|
if length(down_migrations) > 0 do
|
|
|
|
down_migrations_text =
|
|
|
|
Enum.map(down_migrations, fn {:down, id, name} -> "- #{name} (#{id})\n" end)
|
|
|
|
|
|
|
|
Logger.error(
|
2020-09-29 13:28:06 +00:00
|
|
|
"The following migrations were not applied:\n#{down_migrations_text}" <>
|
|
|
|
"If you want to start Pleroma anyway, set\n" <>
|
|
|
|
"config :pleroma, :i_am_aware_this_may_cause_data_loss, disable_migration_check: true"
|
2020-06-22 14:27:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
{:error, "Unapplied Migrations detected"}
|
|
|
|
else
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
res
|
|
|
|
else
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-23 03:56:17 +00:00
|
|
|
def check_migrations_applied!(result), do: result
|
2020-06-22 14:27:49 +00:00
|
|
|
|
2020-06-23 03:56:17 +00:00
|
|
|
# Checks for settings of RUM indexes.
|
|
|
|
#
|
2020-06-22 14:27:49 +00:00
|
|
|
defp check_rum!(:ok) do
|
|
|
|
{_, res, _} =
|
|
|
|
Ecto.Migrator.with_repo(Pleroma.Repo, fn repo ->
|
|
|
|
migrate =
|
|
|
|
from(o in "columns",
|
|
|
|
where: o.table_name == "objects",
|
|
|
|
where: o.column_name == "fts_content"
|
|
|
|
)
|
|
|
|
|> repo.exists?(prefix: "information_schema")
|
|
|
|
|
|
|
|
setting = Pleroma.Config.get([:database, :rum_enabled], false)
|
|
|
|
|
|
|
|
do_check_rum!(setting, migrate)
|
|
|
|
end)
|
|
|
|
|
|
|
|
res
|
|
|
|
end
|
|
|
|
|
|
|
|
defp check_rum!(result), do: result
|
|
|
|
|
|
|
|
defp do_check_rum!(setting, migrate) do
|
|
|
|
case {setting, migrate} do
|
|
|
|
{true, false} ->
|
|
|
|
Logger.error(
|
2020-09-29 13:28:06 +00:00
|
|
|
"Use `RUM` index is enabled, but were not applied migrations for it.\n" <>
|
|
|
|
"If you want to start Pleroma anyway, set\n" <>
|
|
|
|
"config :pleroma, :database, rum_enabled: false\n" <>
|
|
|
|
"Otherwise apply the following migrations:\n" <>
|
|
|
|
"`mix ecto.migrate --migrations-path priv/repo/optional_migrations/rum_indexing/`"
|
2020-06-22 14:27:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
{:error, "Unapplied RUM Migrations detected"}
|
|
|
|
|
|
|
|
{false, true} ->
|
|
|
|
Logger.error(
|
2020-09-29 13:28:06 +00:00
|
|
|
"Detected applied migrations to use `RUM` index, but `RUM` isn't enable in settings.\n" <>
|
|
|
|
"If you want to use `RUM`, set\n" <>
|
|
|
|
"config :pleroma, :database, rum_enabled: true\n" <>
|
|
|
|
"Otherwise roll `RUM` migrations back.\n" <>
|
|
|
|
"`mix ecto.rollback --migrations-path priv/repo/optional_migrations/rum_indexing/`"
|
2020-06-22 14:27:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
{:error, "RUM Migrations detected"}
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
end
|
2020-09-29 13:28:06 +00:00
|
|
|
|
|
|
|
defp check_system_commands!(:ok) do
|
|
|
|
filter_commands_statuses = [
|
2022-02-20 12:46:29 +00:00
|
|
|
check_filter(Pleroma.Upload.Filter.Exiftool.StripLocation, "exiftool"),
|
2022-02-20 11:59:42 +00:00
|
|
|
check_filter(Pleroma.Upload.Filter.Exiftool.ReadDescription, "exiftool"),
|
2021-05-18 21:28:21 +00:00
|
|
|
check_filter(Pleroma.Upload.Filter.Mogrify, "mogrify"),
|
|
|
|
check_filter(Pleroma.Upload.Filter.Mogrifun, "mogrify"),
|
|
|
|
check_filter(Pleroma.Upload.Filter.AnalyzeMetadata, "mogrify"),
|
2021-06-03 21:58:18 +00:00
|
|
|
check_filter(Pleroma.Upload.Filter.AnalyzeMetadata, "convert"),
|
|
|
|
check_filter(Pleroma.Upload.Filter.AnalyzeMetadata, "ffprobe")
|
2020-09-29 13:28:06 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
preview_proxy_commands_status =
|
|
|
|
if !Config.get([:media_preview_proxy, :enabled]) or
|
|
|
|
MediaHelper.missing_dependencies() == [] do
|
|
|
|
true
|
|
|
|
else
|
|
|
|
Logger.error(
|
|
|
|
"The following dependencies required by Media preview proxy " <>
|
|
|
|
"(which is currently enabled) are not installed: " <>
|
|
|
|
inspect(MediaHelper.missing_dependencies())
|
|
|
|
)
|
|
|
|
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
if Enum.all?([preview_proxy_commands_status | filter_commands_statuses], & &1) do
|
|
|
|
:ok
|
|
|
|
else
|
|
|
|
{:error,
|
|
|
|
"System commands missing. Check logs and see `docs/installation` for more details."}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defp check_system_commands!(result), do: result
|
|
|
|
|
2020-12-07 22:36:44 +00:00
|
|
|
defp check_repo_pool_size!(:ok) do
|
|
|
|
if Pleroma.Config.get([Pleroma.Repo, :pool_size], 10) != 10 and
|
|
|
|
not Pleroma.Config.get([:dangerzone, :override_repo_pool_size], false) do
|
|
|
|
Logger.error("""
|
|
|
|
!!!CONFIG WARNING!!!
|
2020-12-08 16:30:10 +00:00
|
|
|
|
|
|
|
The database pool size has been altered from the recommended value of 10.
|
|
|
|
|
|
|
|
Please revert or ensure your database is tuned appropriately and then set
|
2020-12-07 22:36:44 +00:00
|
|
|
`config :pleroma, :dangerzone, override_repo_pool_size: true`.
|
2020-12-08 16:30:10 +00:00
|
|
|
|
|
|
|
If you are experiencing database timeouts, please check the "Optimizing
|
|
|
|
your PostgreSQL performance" section in the documentation. If you still
|
|
|
|
encounter issues after that, please open an issue on the tracker.
|
2020-12-07 22:36:44 +00:00
|
|
|
""")
|
|
|
|
|
2020-12-08 16:16:43 +00:00
|
|
|
{:error, "Repo.pool_size different than recommended value."}
|
2020-12-07 22:36:44 +00:00
|
|
|
else
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defp check_repo_pool_size!(result), do: result
|
|
|
|
|
2020-09-29 13:28:06 +00:00
|
|
|
defp check_filter(filter, command_required) do
|
|
|
|
filters = Config.get([Pleroma.Upload, :filters])
|
|
|
|
|
|
|
|
if filter in filters and not Pleroma.Utils.command_available?(command_required) do
|
|
|
|
Logger.error(
|
|
|
|
"#{filter} is specified in list of Pleroma.Upload filters, but the " <>
|
|
|
|
"#{command_required} command is not found"
|
|
|
|
)
|
|
|
|
|
|
|
|
false
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
2020-06-22 14:27:49 +00:00
|
|
|
end
|