比格犬劳动饮酒叹息

为 Mastodon 添加邮件服务及日常管理命令

note 搬运自以前的wordpress博客,原始发布日期2020/05/09,2021/03/11后未更新。


踩坑经验,中间具体服务信息打码。几乎都来自bgme大佬的手把手教学。

################## 如何改配置文件 .env.production ##########

su - mastodon
cd live
vim .env.production



######### 添加邮箱服务 #############
SMTP_SERVER=smtp.mailgun.org
SMTP_PORT=587
SMTP_LOGIN=postmaster@xxxxxx.xxx
SMTP_PASSWORD=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SMTP_FROM_ADDRESS=notifications@xxxxxx.xxx #这里不使用默认的设置!保持和上面SMTP_LOGIN一致,否则会报错:501 mail from address must be same as authorization user
#SMTP_REPLY_TO=
#SMTP_DOMAIN= # defaults to LOCAL_DOMAIN
SMTP_DELIVERY_METHOD=smtp # delivery method can also be sendmail
SMTP_AUTH_METHOD=plain
#SMTP_CA_FILE=/etc/ssl/certs/ca-certificates.crt
#SMTP_OPENSSL_VERIFY_MODE=none # 不要用peer 改成none
#SMTP_ENABLE_STARTTLS_AUTO=true
#SMTP_TLS=true # 不要用加密,注释掉!
# 复杂的加密都会报错,比如版本不对。直接注释掉。


# 测试邮箱配置是否生效
// 如果已经切换了mastodon,则不需要这条
sudo su - mastodon
cd ~/live
// 进入Rails控制台
RAILS_ENV=production bundle exec rails c
// 注意中间的邮件地址换成你的
m = UserMailer.new.mail to:'mailtotest@xxxx.xx', subject: 'test', body: 'awoo'
m.deliver
// 测试结束之后 exit





######### 解决命令通配符不生效的问题
sudo systemctl restart mastodon-*

有时重新启动cmd在启动服务时不起作用,我在更新过程中遇到此问题,因此您可以一一完成它们,我在下面添加了cmd
systemctl stop mastodon-web && systemctl stop mastodon-streaming && systemctl stop mastodon-sidekiq
systemctl start mastodon-web && systemctl start mastodon-streaming && systemctl start mastodon-sidekiq


################################ 管理站点账号
mastodon@ubuntu-xxxxxxxxx:~/live$ RAILS_ENV=production bin/tootctl help
Commands:
  tootctl accounts SUBCOMMAND ...ARGS       # Manage accounts
  tootctl cache SUBCOMMAND ...ARGS          # Manage cache
  tootctl domains SUBCOMMAND ...ARGS        # Manage account domains
  tootctl emoji SUBCOMMAND ...ARGS          # Manage custom emoji
  tootctl feeds SUBCOMMAND ...ARGS          # Manage feeds
  tootctl help [COMMAND]                    # Describe available commands or one specific command
  tootctl media SUBCOMMAND ...ARGS          # Manage media files
  tootctl preview_cards SUBCOMMAND ...ARGS  # Manage preview cards
  tootctl search SUBCOMMAND ...ARGS         # Manage the search engine
  tootctl self-destruct                     # Erase the server from the federation
  tootctl settings SUBCOMMAND ...ARGS       # Manage dynamic settings
  tootctl statuses SUBCOMMAND ...ARGS       # Manage statuses
  tootctl version                           # Show version

# 如果机器上还打算装别的软件,不仅用来装长毛象,那么每次执行管理命令是都要先
su mastodon # 切换到mastodon用户
cd /home/mastodon/live # 切换到live文件夹
RAILS_ENV=production bin/tootctl help #再执行命令,help是帮助命令,具体执行时替换为别的

# 例如:
mastodon@ubuntu-xxxxxxxxx:~/live$ RAILS_ENV=production bin/tootctl accounts delete tootit
Deleting user with 0 statuses, this might take a while...
OK

记一笔,mastodon用户的密码和mastodon数据库(postgresql)不是一回事,后者官方教程里建议密码设置为空,前者没有提到,直接用adduser创建了用户。现在root用户和mastodon用户的密码都设置为了mast,而数据库依然留空。


自建实例的同学,请务必添加如下两个定时任务,推荐在每天早晨低峰时段运行 RAILS_ENV=production /home/mastodon/live/bin/tootctl media remove –days=14 清理缓存的外站媒体文件,和 RAILS_ENV=production /home/mastodon/live/bin/tootctl media remove-orphans 清理未关联任何 toot 的“无主”媒体文件

另外推荐配合以下任务食用 RAILS_ENV=production /home/mastodon/live/bin/tootctl statuses remove 清理没有同本站任何用户产生关联的 toot 本身(比如跨站轴上收到的、没有本站用户转发/评论/收藏过的消息


每次清理硬盘的固定操作: su – mastodon cd live RAILS_ENV=production bin/tootctl media remove

可设定crontab mastodon用户下, 15 4 /3 * RAILS_ENV=production /home/mastodon/live/bin/tootctl media remove

#mastodon