From 3cfacecb6ce4070cb4feab1af9f8d9856eadc4bc Mon Sep 17 00:00:00 2001 From: James Moore Date: Fri, 14 Apr 2017 15:53:38 -0700 Subject: [PATCH] moved things into alternatives.md --- Running-Mastodon/Alternatives.md | 218 +++++++++++++++++++++++++++ Running-Mastodon/Misc.md | 114 -------------- Running-Mastodon/Production-guide.md | 43 ------ 3 files changed, 218 insertions(+), 157 deletions(-) create mode 100644 Running-Mastodon/Alternatives.md delete mode 100644 Running-Mastodon/Misc.md diff --git a/Running-Mastodon/Alternatives.md b/Running-Mastodon/Alternatives.md new file mode 100644 index 00000000..68f6b5bb --- /dev/null +++ b/Running-Mastodon/Alternatives.md @@ -0,0 +1,218 @@ +Alternative Server Components +============================= + +This file provides some configurations for systems that will not be using +the "stock" server components. + +## Supervisord + +An alternative to using systemd for controlling your mastodon processes is +[Supervisord](http://supervisord.org/). The following file can be placed in +`/etc/supervisor/conf.d/mastodon.conf`. + +``` +[group:mastodon] +programs=web,sidekiq,streaming + +[program:web] +command=/home/mastodon/live/ruby_wrapper bundle exec puma -C config/puma.rb +user=mastodon +directory=/home/mastodon/live +stdout_logfile=/home/mastodon/live/log/puma.log +stdout_logfile_maxbytes=1MB +stdout_logfile_backups=10 +redirect_stderr=true +environment=PORT=3000 +stopasgroup=true + +[program:sidekiq] +command=/home/mastodon/live/ruby_wrapper bundle exec sidekiq -c 5 -q default -q mailers -q pull -q push +user=mastodon +directory=/home/mastodon/live +stdout_logfile=/home/mastodon/live/log/sidekiq.log +stdout_logfile_maxbytes=1MB +stdout_logfile_backups=10 +redirect_stderr=true +environment=DB_POOL=5 +stopasgroup=true + +[program:streaming] +command=/home/mastodon/live/ruby_wrapper /usr/bin/npm run start +user=mastodon +directory=/home/mastodon/live +stdout_logfile=/home/mastodon/live/log/streaming.log +stdout_logfile_maxbytes=1MB +stdout_logfile_backups=10 +redirect_stderr=true +environment=PORT=4000 +stopasgroup=true +``` + +This configuration makes use of a wrapper script to ensure the correct +environment. + +```shell +#!/usr/bin/env bash + +cd /home/mastodon/live +export RBENV_ROOT=/home/mastodon/.rbenv +export PATH=/home/mastodon/.rbenv/bin:/home/mastodon/.rbenv/shims:$PATH +export $(cat ".env.production" | xargs) + +$@ +``` + +## Running with init scripts + +Example init script for the web workers, to be placed in `/etc/init.d/mastodon-web`: + +``` +#!/sbin/openrc-run + +name="Mastodon Web Service" +root="/home/mastodon/live" +pidfile="${root}/web.pid" + +depend() { + use net +} + +start() { + ebegin "Starting Mastodon web workers" + + cd $root + + start-stop-daemon --start \ + --chdir "${root}" \ + --user="mastodon" \ + --pidfile="${pidfile}" \ + --exec /usr/bin/env -- RAILS_ENV=production PORT=3000 bundle exec puma -C config/puma.rb -d --pidfile ${pidfile} + + eend $? +} + +stop() { + ebegin "Stopping Mastodon web workers" + start-stop-daemon --stop \ + --pidfile=${pidfile} \ + eend $? +} + +``` + +Example init script for the background workers, to be placed in `/etc/init.d/mastodon-sidekiq`: + +``` + +#!/sbin/openrc-run + +name="Mastodon background workers Service" +root="/home/mastodon/live" +pidfile="${root}/worker.pid" +logfile="${root}/sidekiq.conf" + +depend() { + use net + need redis +} + +start() { + ebegin "Starting Mastodon background workers" + + cd $root + + start-stop-daemon --start \ + --chdir "${root}" \ + --user="mastodon" \ + --pidfile="${pidfile}" \ + --exec /usr/bin/env -- RAILS_ENV=production DB_POOL=5 bundle exec sidekiq -d -P ${pidfile} -L ${logfile} -c 5 -q default -q mailers -q pull -q push + eend $? +} + +stop() { + ebegin "Stopping Mastodon background workers" + start-stop-daemon --stop \ + --pidfile=${pidfile} \ + eend $? +} + +``` + +Example init script file for the streaming API, to be placed in `/etc/init.d/mastodon-streaming`: + +``` +#!/sbin/openrc-run + +name="Mastodon streaming API service" +root="/home/mastodon/live" + +depend() { + use net +} + +start() { + ebegin "Starting Mastodon streaming API" + + cd $root + + start-stop-daemon --start \ + --background --quiet \ + --chdir "${root}" \ + --user="mastodon" \ + --make-pidfile --pidfile=${root}/streaming.pid \ + --exec /usr/bin/env -- NODE_ENV=production PORT=4000 /usr/bin/npm run start + eend $? +} + +stop() { + ebegin "Stopping Mastodon streaming API" + start-stop-daemon --stop \ + --pidfile=${root}/streaming.pid \ + eend $? +} +``` + +This allows you to `rc-update add mastodon-web && rc-update add mastodon-sidekiq && rc-update add mastodon-streaming` and `service mastodon-web start && service mastodon-sidekiq start && service mastodon-streaming start` to get things going. + +## Apache + +Setting up Mastodon behind Apache is possible as well, although you will need to enable [mod_proxy_wstunnel](https://httpd.apache.org/docs/trunk/mod/mod_proxy_wstunnel.html) beforehand. The configuration is then pretty straightforward. + +``` + + ServerAdmin contact@example.com + ServerName example.com + Redirect Permanent / https://example.com/ + + + + ServerAdmin contact@example.com + ServerName example.com + + DocumentRoot /home/mastodon/live/public/ + + Header add Strict-Transport-Security "max-age=31536000" + SSLEngine on + SSLProtocol -all +TLSv1.2 + SSLHonorCipherOrder on + SSLCipherSuite EECDH+AESGCM:AES256+EECDH:AES128+EECDH + + SSLCertificateFile example.pem + SSLCertificateKeyFile example.key + + ProxyPreserveHost On + RequestHeader set X-Forwarded-Proto "https" + ProxyPass /500.html ! + ProxyPass /oops.png ! + ProxyPass /api/v1/streaming/ ws://localhost:4000/ + ProxyPassReverse /api/v1/streaming/ ws://localhost:4000/ + ProxyPass / http://localhost:3000/ + ProxyPassReverse / http://localhost:3000/ + + ErrorDocument 500 /500.html + ErrorDocument 501 /500.html + ErrorDocument 502 /500.html + ErrorDocument 503 /500.html + ErrorDocument 504 /500.html + +``` diff --git a/Running-Mastodon/Misc.md b/Running-Mastodon/Misc.md deleted file mode 100644 index f934e07a..00000000 --- a/Running-Mastodon/Misc.md +++ /dev/null @@ -1,114 +0,0 @@ -Miscellaneous -============= - -## Running with init scripts - -Example init script for the web workers, to be placed in `/etc/init.d/mastodon-web`: - -``` -#!/sbin/openrc-run - -name="Mastodon Web Service" -root="/home/mastodon/live" -pidfile="${root}/web.pid" - -depend() { - use net -} - -start() { - ebegin "Starting Mastodon web workers" - - cd $root - - start-stop-daemon --start \ - --chdir "${root}" \ - --user="mastodon" \ - --pidfile="${pidfile}" \ - --exec /usr/bin/env -- RAILS_ENV=production PORT=3000 bundle exec puma -C config/puma.rb -d --pidfile ${pidfile} - - eend $? -} - -stop() { - ebegin "Stopping Mastodon web workers" - start-stop-daemon --stop \ - --pidfile=${pidfile} \ - eend $? -} - -``` - -Example init script for the background workers, to be placed in `/etc/init.d/mastodon-sidekiq`: - -``` - -#!/sbin/openrc-run - -name="Mastodon background workers Service" -root="/home/mastodon/live" -pidfile="${root}/worker.pid" -logfile="${root}/sidekiq.conf" - -depend() { - use net - need redis -} - -start() { - ebegin "Starting Mastodon background workers" - - cd $root - - start-stop-daemon --start \ - --chdir "${root}" \ - --user="mastodon" \ - --pidfile="${pidfile}" \ - --exec /usr/bin/env -- RAILS_ENV=production DB_POOL=5 bundle exec sidekiq -d -P ${pidfile} -L ${logfile} -c 5 -q default -q mailers -q pull -q push - eend $? -} - -stop() { - ebegin "Stopping Mastodon background workers" - start-stop-daemon --stop \ - --pidfile=${pidfile} \ - eend $? -} - -``` - -Example init script file for the streaming API, to be placed in `/etc/init.d/mastodon-streaming`: - -``` -#!/sbin/openrc-run - -name="Mastodon streaming API service" -root="/home/mastodon/live" - -depend() { - use net -} - -start() { - ebegin "Starting Mastodon streaming API" - - cd $root - - start-stop-daemon --start \ - --background --quiet \ - --chdir "${root}" \ - --user="mastodon" \ - --make-pidfile --pidfile=${root}/streaming.pid \ - --exec /usr/bin/env -- NODE_ENV=production PORT=4000 /usr/bin/npm run start - eend $? -} - -stop() { - ebegin "Stopping Mastodon streaming API" - start-stop-daemon --stop \ - --pidfile=${root}/streaming.pid \ - eend $? -} -``` - -This allows you to `rc-update add mastodon-web && rc-update add mastodon-sidekiq && rc-update add mastodon-streaming` and `service mastodon-web start && service mastodon-sidekiq start && service mastodon-streaming start` to get things going. diff --git a/Running-Mastodon/Production-guide.md b/Running-Mastodon/Production-guide.md index 3e60123e..cd57796a 100644 --- a/Running-Mastodon/Production-guide.md +++ b/Running-Mastodon/Production-guide.md @@ -101,49 +101,6 @@ server { } ``` -## Apache - -Setting up Mastodon behind Apache is possible as well, although you will need to enable [mod_proxy_wstunnel](https://httpd.apache.org/docs/trunk/mod/mod_proxy_wstunnel.html) beforehand. The configuration is then pretty straightforward. - -``` - - ServerAdmin contact@example.com - ServerName example.com - Redirect Permanent / https://example.com/ - - - - ServerAdmin contact@example.com - ServerName example.com - - DocumentRoot /home/mastodon/live/public/ - - Header add Strict-Transport-Security "max-age=31536000" - SSLEngine on - SSLProtocol -all +TLSv1.2 - SSLHonorCipherOrder on - SSLCipherSuite EECDH+AESGCM:AES256+EECDH:AES128+EECDH - - SSLCertificateFile example.pem - SSLCertificateKeyFile example.key - - ProxyPreserveHost On - RequestHeader set X-Forwarded-Proto "https" - ProxyPass /500.html ! - ProxyPass /oops.png ! - ProxyPass /api/v1/streaming/ ws://localhost:4000/ - ProxyPassReverse /api/v1/streaming/ ws://localhost:4000/ - ProxyPass / http://localhost:3000/ - ProxyPassReverse / http://localhost:3000/ - - ErrorDocument 500 /500.html - ErrorDocument 501 /500.html - ErrorDocument 502 /500.html - ErrorDocument 503 /500.html - ErrorDocument 504 /500.html - -``` - ## Running in production without Docker It is recommended to create a special user for mastodon on the server (you could call the user `mastodon`), though remember to disable outside login for it. You should only be able to get into that user through `sudo su - mastodon`.