-
hareware: GCE g1-small instance (1 vCPU, 1.7 GB memory), about $15/mo
-
software (Archlinux):
sudo pacman -Sy nginx certbot docker docker-compose
# optional tools
sudo pacman -Sy glances htop w3m
It is suggested to add some swap space for Mastodon
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
- add to swap
/etc/fstab
/swapfile none swap defaults 0 0
(Oprional) adjust swappiness to a higher value
sudo sysctl vm.swappiness=85
/etc/sysctl.d/99-sysctl.conf
vm.swappiness=85
It is suggested to move docker storage to another path (dockerd -g $PATH
) instead of /var/lib/docker
by default. This can prevent the server from accidentally running out of disk space.
/etc/systemd/system/docker.service.d/docker-storage.conf
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -g /path/to/new/location/docker -H fd://
sudo systemctl (re)start docker
Apply a mailgun account, setup DNS records with mailgun (MX, SPF, DKIM, CNAME).
- clone repo and copy the env file.
git clone [email protected]:tootsuite/mastodon.git
cd mastodon
cp .env.production.sample .env.production
vim .env.production
LOCAL_DOMAIN=example.com
LOCAL_HTTPS=true
SMTP_SERVER=smtp.mailgun.org
SMTP_PORT=2525
[email protected]
SMTP_PASSWORD=<<API key>>
[email protected]>
- build docker image (slow!)
docker-compose build
- run
rake secret
onweb
3 times forPAPERCLIP_SECRET
,SECRET_KEY_BASE
, andOTP_SECRET
.
docker-compose run --rm web rake secret
- create database
docker-compose run --rm web rails db:migrate
- precompile the assets (slow!)
docker-compose run --rm web rails assets:precompile
-
run / stop service (Mastodon is running on
http://localhost:3000
)- hint:
docker-compose down
will STOP and REMOVE containers.
- hint:
docker-compose up -d
docker-compose stop
-
create https certificates:
certbot certonly --manual
-
become admin
docker-compose run --rm web rake mastodon:make_admin USERNAME=xatierlike
or, via an interactive shell:
docker exec -it mastodon_web_1 /bin/sh
RAILS_ENV=production bundle exec rails mastodon:make_admin USERNAME=xatierlike
(Risky!)
git pull
docker-compose build
docker-compose run --rm web rails assets:precompile
docker-compose stop
docker-compose run --rm web rails db:migrate
docker-compose up -d
docker rmi $(docker images -f "dangling=true" -q)
docker rm -v $(docker ps -a -q -f status=exited)
- please refere the details defined in
lib/tasks/mastodon.rake
#!/bin/bash -x
set -ueo pipefail
docker-compose run --rm web rake mastodon:daily
docker-compose run --rm web rake mastodon:media:remove_remote
My persoanl patches to the site
- show NSFW iamges by default
diff --git a/app/assets/javascripts/components/components/media_gallery.jsx b/app/assets/javascripts/components/components/media_gallery.jsx
index ebc6e709..f54f216b 100644
--- a/app/assets/javascripts/components/components/media_gallery.jsx
+++ b/app/assets/javascripts/components/components/media_gallery.jsx
@@ -194,7 +194,7 @@ class MediaGallery extends React.PureComponent {
constructor (props, context) {
super(props, context);
this.state = {
- visible: !props.sensitive
+ visible: 1
};
this.handleOpen = this.handleOpen.bind(this);
this.handleClick = this.handleClick.bind(this);
- set remote media cache to 1 day only
diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake
index 7dd7b5cd..fd5ccfd6 100644
--- a/lib/tasks/mastodon.rake
+++ b/lib/tasks/mastodon.rake
@@ -44,9 +44,9 @@ namespace :mastodon do
MediaAttachment.where(account: Account.silenced).find_each(&:destroy)
end
- desc 'Remove cached remote media attachments that are older than a week'
+ desc 'Remove cached remote media attachments that are older than a day'
task remove_remote: :environment do
- MediaAttachment.where.not(remote_url: '').where('created_at < ?', 1.week.ago).find_each do |media|
+ MediaAttachment.where.not(remote_url: '').where('created_at < ?', 1.day.ago).find_each do |media|
media.file.destroy
end
end