diff --git a/README.md b/README.md index 192fd69d..a551a245 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -Index -===== +# Mastodon documentation **Mastodon** is a free, open-source GNU social-compatible social network server. A decentralized alternative to commercial platforms, it avoids the risks of a single company monopolizing your communication. Anyone can run Mastodon and participate in the social network seamlessly. @@ -23,6 +22,7 @@ Index - [Development guide](Running-Mastodon/Development-guide.md) - [Alternative: Development with Vagrant](Running-Mastodon/Vagrant-guide.md) - [Administration guide](Running-Mastodon/Administration-guide.md) +- [Maintenance Tasks](Running-Mastodon/Maintenance-Tasks.md) - [Tuning Mastodon](Running-Mastodon/Tuning.md) - [System Configuration Alternatives](Running-Mastodon/Alternatives.md) diff --git a/Running-Mastodon/Docker-Guide.md b/Running-Mastodon/Docker-Guide.md new file mode 100644 index 00000000..e61e8665 --- /dev/null +++ b/Running-Mastodon/Docker-Guide.md @@ -0,0 +1,76 @@ +## Docker + +[![](https://images.microbadger.com/badges/version/gargron/mastodon.svg)](https://microbadger.com/images/gargron/mastodon "Get your own version badge on microbadger.com") [![](https://images.microbadger.com/badges/image/gargron/mastodon.svg)](https://microbadger.com/images/gargron/mastodon "Get your own image badge on microbadger.com") + +The project now includes a `Dockerfile` and a `docker-compose.yml` file (which requires at least docker-compose version `1.10.0`). + +## Setting up + +Review the settings in `docker-compose.yml`. Note that it is not default to store the postgresql database and redis databases in a persistent storage location, +so you may need or want to adjust the settings there. + +Then, you need to fill in the `.env.production` file: + + cp .env.production.sample .env.production + nano .env.production + +Do NOT change the `REDIS_*` or `DB_*` settings when running with the default docker configurations. + +You will need to fill in, at least: `LOCAL_DOMAIN`, `LOCAL_HTTPS`, `PAPERCLIP_SECRET`, `SECRET_KEY_BASE`, `OTP_SECRET`, and the `SMTP_*` settings. To generate the `PAPERCLIP_SECRET`, `SECRET_KEY_BASE`, and `OTP_SECRET`, you may use: + + rake secret + +## Building the app + +Before running the first time, you need to build the images: + + docker-compose build + + docker-compose run --rm web rake secret + +Do this once for each of those keys, and copy the result into the `.env.production` file in the appropriate field. + +Then you should run the `db:migrate` command to create the database, or migrate it from an older release: + + docker-compose run --rm web rails db:migrate + +Then, you will also need to precompile the assets: + + docker-compose run --rm web rails assets:precompile + +before you can launch the docker image with: + + docker-compose up + +If you wish to run this as a daemon process instead of monitoring it on console, use instead: + + docker-compose up -d + +## Configuration + +Then you may login to your new Mastodon instance by browsing to http://localhost:3000/ + +Following that, make sure that you read the [production guide](docs/Running-Mastodon/Production-guide.md). You are probably going to want to understand how +to configure Nginx to make your Mastodon instance available to the rest of the world. + +The container has two volumes, for the assets and for user uploads, and optionally two more, for the postgresql and redis databases. + +The default docker-compose.yml maps them to the repository's `public/assets` and `public/system` directories, you may wish to put them somewhere else. Likewise, the PostgreSQL and Redis images have data containers that you may wish to map somewhere where you know how to find them and back them up. + +**Note**: The `--rm` option for docker-compose will remove the container that is created to run a one-off command after it completes. As data is stored in volumes it is not affected by that container clean-up. + +## Running tasks + +Running any of these tasks via docker-compose would look like this: + + docker-compose run --rm web rake mastodon:media:clear + +## Updating + +This approach makes updating to the latest version a real breeze. + +1. `git pull` to download updates from the repository +2. `docker-compose build` to compile the Docker image out of the changed source files +3. (optional) `docker-compose run --rm web rails db:migrate` to perform database migrations. Does nothing if your database is up to date +4. (optional) `docker-compose run --rm web rails assets:precompile` to compile new JS and CSS assets +5. `docker-compose up -d` to re-create (restart) containers and pick up the changes diff --git a/Running-Mastodon/Maintenance-Tasks.md b/Running-Mastodon/Maintenance-Tasks.md new file mode 100644 index 00000000..03503895 --- /dev/null +++ b/Running-Mastodon/Maintenance-Tasks.md @@ -0,0 +1,9 @@ +# Maintenance tasks + +These tasks are available to instance operators: + +- `rake mastodon:media:clear` removes uploads that have not been attached to any status after a while, you would want to run this from a periodic cronjob +- `rake mastodon:push:clear` unsubscribes from PuSH notifications for remote users that have no local followers. You may not want to actually do that, to keep a fuller footprint of the fediverse or in case your users will soon re-follow +- `rake mastodon:push:refresh` re-subscribes PuSH for expiring remote users, this should be run periodically from a cronjob and quite often as the expiration time depends on the particular hub of the remote user +- `rake mastodon:feeds:clear_all` removes all timelines, which forces them to be re-built on the fly next time a user tries to fetch their home/mentions timeline. Only for troubleshooting +- `rake mastodon:feeds:clear` removes timelines of users who haven't signed in lately, which allows to save RAM and improve message distribution. This is required to be run periodically so that when they login again the regeneration process will trigger diff --git a/Running-Mastodon/Production-guide.md b/Running-Mastodon/Production-guide.md index 550fc873..3d478031 100644 --- a/Running-Mastodon/Production-guide.md +++ b/Running-Mastodon/Production-guide.md @@ -134,7 +134,9 @@ In the prompt: Under Ubuntu 16.04, you will need to explicitly enable ident authentication so that local users can connect to the database without a password: +```sh sudo sed -i '/^local.*postgres.*peer$/a host all all 127.0.0.1/32 ident' /etc/postgresql/9.?/main/pg_hba.conf +``` and install an ident daemon, which does not come installed by default: @@ -181,6 +183,11 @@ Fill in the important data, like host/port of the redis database, host/port/user To get a random string. If you are setting up on one single server (most likely), then `REDIS_HOST` is localhost and `DB_HOST` is `/var/run/postgresql`, `DB_USER` is `mastodon` and `DB_NAME` is `mastodon_production` while `DB_PASS` is empty because this setup will use the ident authentication method (system user "mastodon" maps to postgres user "mastodon"). +Configuring the instance hostname: + +- `LOCAL_DOMAIN` should be the domain/hostname of your instance. This is **absolutely required** as it is used for generating unique IDs for everything federation-related. +- `LOCAL_HTTPS` set it to `true` if HTTPS works on your website. This is used to generate canonical URLs, which is also important when generating and parsing federation-related IDs. + ## Setup And set up the database for the first time, this will create the tables and basic data: @@ -263,19 +270,28 @@ This allows you to `sudo systemctl enable /etc/systemd/system/mastodon-*.service There are several tasks that should be run once a day to ensure that mastodon is running smoothly. As your mastodon user run `crontab -e` and enter the following -``` -RAILS_ENV=production -@daily cd /home/mastodon/live && /home/mastodon/.rbenv/shims/bundle exec rake mastodon:daily > /dev/null - +```sh + RAILS_ENV=production + @daily cd /home/mastodon/live && /home/mastodon/.rbenv/shims/bundle exec rake mastodon:daily > /dev/null ``` ## Things to look out for when upgrading Mastodon -You can upgrade Mastodon with a `git fetch; git checkout $(git tag | tail -n 1)` from the repository directory. You may need to run: +If you want a stable release for production use, you should use tagged releases. To checkout the latest available tagged version: + +```sh + git clone https://github.com/tootsuite/mastodon.git + cd mastodon + git checkout $(git tag | tail -n 1) +``` + +As part of your deploy, you may need to run: - `RAILS_ENV=production bundle exec rails db:migrate` - `RAILS_ENV=production bundle exec rails assets:precompile` Depending on which files changed, e.g. if anything in the `/db/` or `/app/assets` directory changed, respectively. Also, Mastodon runs in memory, so you need to restart it before you see any changes. If you're using systemd, that would be: +```sh sudo systemctl restart mastodon-*.service +```