2018-08-25 21:25:39 +10:00
# frozen_string_literal: true
2023-05-24 19:55:40 +10:00
require_relative 'base'
2023-05-24 00:08:26 +10:00
require_relative 'accounts'
2023-05-24 19:55:40 +10:00
require_relative 'cache'
require_relative 'canonical_email_blocks'
require_relative 'domains'
require_relative 'email_domain_blocks'
require_relative 'emoji'
2023-05-24 00:08:26 +10:00
require_relative 'feeds'
2023-05-24 19:55:40 +10:00
require_relative 'ip_blocks'
require_relative 'maintenance'
require_relative 'media'
require_relative 'preview_cards'
2023-05-24 00:08:26 +10:00
require_relative 'search'
require_relative 'settings'
require_relative 'statuses'
require_relative 'upgrade'
module Mastodon::CLI
2023-05-24 19:55:40 +10:00
class Main < Base
2018-08-27 04:21:03 +10:00
desc 'media SUBCOMMAND ...ARGS' , 'Manage media files'
2023-05-24 00:08:26 +10:00
subcommand 'media' , Media
2018-08-27 00:53:06 +10:00
2018-08-27 04:21:03 +10:00
desc 'emoji SUBCOMMAND ...ARGS' , 'Manage custom emoji'
2023-05-24 00:08:26 +10:00
subcommand 'emoji' , Emoji
2018-08-27 04:21:03 +10:00
desc 'accounts SUBCOMMAND ...ARGS' , 'Manage accounts'
2023-05-24 00:08:26 +10:00
subcommand 'accounts' , Accounts
2018-09-15 01:42:22 +10:00
desc 'feeds SUBCOMMAND ...ARGS' , 'Manage feeds'
2023-05-24 00:08:26 +10:00
subcommand 'feeds' , Feeds
2018-10-05 00:05:54 +10:00
2019-03-28 12:16:11 +11:00
desc 'search SUBCOMMAND ...ARGS' , 'Manage the search engine'
2023-05-24 00:08:26 +10:00
subcommand 'search' , Search
2019-03-28 12:16:11 +11:00
2018-10-05 00:05:54 +10:00
desc 'settings SUBCOMMAND ...ARGS' , 'Manage dynamic settings'
2023-05-24 00:08:26 +10:00
subcommand 'settings' , Settings
2018-10-28 07:56:16 +11:00
2019-03-11 23:45:17 +11:00
desc 'statuses SUBCOMMAND ...ARGS' , 'Manage statuses'
2023-05-24 00:08:26 +10:00
subcommand 'statuses' , Statuses
2019-03-11 23:45:17 +11:00
2018-10-28 07:56:16 +11:00
desc 'domains SUBCOMMAND ...ARGS' , 'Manage account domains'
2023-05-24 00:08:26 +10:00
subcommand 'domains' , Domains
2019-01-18 07:32:55 +11:00
2019-07-28 21:48:19 +10:00
desc 'preview_cards SUBCOMMAND ...ARGS' , 'Manage preview cards'
2023-05-24 00:08:26 +10:00
subcommand 'preview_cards' , PreviewCards
2019-07-28 21:48:19 +10:00
2019-05-04 09:02:57 +10:00
desc 'cache SUBCOMMAND ...ARGS' , 'Manage cache'
2023-05-24 00:08:26 +10:00
subcommand 'cache' , Cache
2019-05-04 09:02:57 +10:00
2020-04-27 07:29:08 +10:00
desc 'upgrade SUBCOMMAND ...ARGS' , 'Various version upgrade utilities'
2023-05-24 00:08:26 +10:00
subcommand 'upgrade' , Upgrade
2020-04-27 07:29:08 +10:00
2020-06-27 05:28:40 +10:00
desc 'email_domain_blocks SUBCOMMAND ...ARGS' , 'Manage e-mail domain blocks'
2023-05-24 00:08:26 +10:00
subcommand 'email_domain_blocks' , EmailDomainBlocks
2020-06-25 20:17:10 +10:00
2020-10-13 01:33:49 +11:00
desc 'ip_blocks SUBCOMMAND ...ARGS' , 'Manage IP blocks'
2023-05-24 00:08:26 +10:00
subcommand 'ip_blocks' , IpBlocks
2020-10-13 01:33:49 +11:00
2021-12-18 09:02:14 +11:00
desc 'canonical_email_blocks SUBCOMMAND ...ARGS' , 'Manage canonical e-mail blocks'
2023-05-24 00:08:26 +10:00
subcommand 'canonical_email_blocks' , CanonicalEmailBlocks
2021-12-18 09:02:14 +11:00
2020-11-20 03:37:49 +11:00
desc 'maintenance SUBCOMMAND ...ARGS' , 'Various maintenance utilities'
2023-05-24 00:08:26 +10:00
subcommand 'maintenance' , Maintenance
2020-11-20 03:37:49 +11:00
2019-03-29 03:56:25 +11:00
desc 'self-destruct' , 'Erase the server from the federation'
long_desc << ~ LONG_DESC
Erase the server from the federation by broadcasting account delete
activities to all known other servers . This allows a " clean exit " from
running a Mastodon server , as it leaves next to no cache behind on
other servers .
This command is always interactive and requires confirmation twice .
No local data is actually deleted , because emptying the
database or removing files is much faster through other , external
means , such as e . g . deleting the entire VPS . However , because other
servers will delete data about local users , but no local data will be
updated ( such as e . g . followers ) , there will be a state mismatch
that will lead to glitches and issues if you then continue to run and use
the server .
So either you know exactly what you are doing , or you are starting
from a blank slate afterwards by manually clearing out all the local
data!
LONG_DESC
def self_destruct
require 'tty-prompt'
prompt = TTY :: Prompt . new
2023-10-24 02:46:21 +11:00
if SelfDestructHelper . self_destruct?
prompt . ok ( 'Self-destruct mode is already enabled for this Mastodon server' )
2019-03-29 03:56:25 +11:00
2023-10-24 02:46:21 +11:00
pending_accounts = Account . local . without_suspended . count + Account . local . suspended . joins ( :deletion_request ) . count
sidekiq_stats = Sidekiq :: Stats . new
2019-03-29 03:56:25 +11:00
2023-10-24 02:46:21 +11:00
if pending_accounts . positive?
prompt . warn ( " #{ pending_accounts } accounts are still pending deletion. " )
elsif sidekiq_stats . enqueued . positive?
prompt . warn ( 'Deletion notices are still being processed' )
elsif sidekiq_stats . retry_size . positive?
prompt . warn ( 'At least one delivery attempt for each deletion notice has been made, but some have failed and are scheduled for retry' )
else
prompt . ok ( 'Every deletion notice has been sent! You can safely delete all data and decomission your servers!' )
end
2021-10-15 04:59:28 +11:00
2023-10-24 02:46:21 +11:00
exit ( 0 )
2019-03-29 03:56:25 +11:00
end
2023-10-24 02:46:21 +11:00
exit ( 1 ) unless prompt . ask ( 'Type in the domain of the server to confirm:' , required : true ) == Rails . configuration . x . local_domain
2019-03-29 03:56:25 +11:00
2023-10-24 02:46:21 +11:00
prompt . warn ( 'This operation WILL NOT be reversible.' )
prompt . warn ( 'While the data won\'t be erased locally, the server will be in a BROKEN STATE afterwards.' )
prompt . warn ( 'The deletion process itself may take a long time, and will be handled by Sidekiq, so do not shut it down until it has finished (you will be able to re-run this command to see the state of the self-destruct process).' )
2019-03-29 03:56:25 +11:00
2023-10-24 02:46:21 +11:00
exit ( 1 ) if prompt . no? ( 'Are you sure you want to proceed?' )
2021-10-15 04:59:28 +11:00
2023-10-24 02:46:21 +11:00
self_destruct_value = Rails . application . message_verifier ( 'self-destruct' ) . generate ( Rails . configuration . x . local_domain )
prompt . ok ( 'To switch Mastodon to self-destruct mode, add the following variable to your evironment (e.g. by adding a line to your `.env.production`) and restart all Mastodon processes:' )
prompt . ok ( " SELF_DESTRUCT= #{ self_destruct_value } " )
prompt . ok ( " \n You can re-run this command to see the state of the self-destruct process. " )
2019-03-29 03:56:25 +11:00
rescue TTY :: Reader :: InputInterrupt
exit ( 1 )
end
2019-01-18 07:32:55 +11:00
map %w( --version -v ) = > :version
desc 'version' , 'Show version'
def version
say ( Mastodon :: Version . to_s )
end
2018-08-25 21:25:39 +10:00
end
end