Setting up a Systemd-Free Mastodon Instance Using Supervisor

5 min

language: ja bn en es hi pt ru zh-cn zh-tw

Hello, this is Munou.

I have just set up a Mastodon instance.

https://eyes4you.org/
(Currently, no one can register yet because Vultr support has not yet responded regarding SMTP port opening, so emails are not being delivered. Registration should be possible within a few days. As of 9:30 PM, August 20, 2023)

Initial Problem

Mastodon is designed with Systemd as a prerequisite, so the daemon files for running Mastodon are only provided for Systemd.

Environment: Devuan SysVinit
Prerequisite: Mastodon setup wizard has been completed

These are mastodon-web, mastodon-sidekiq, and mastodon-streaming.

Therefore, by using Supervisor, it's a convenient software that allows daemon files to run with Supervisor. It was probably originally developed as a process monitoring tool, and with the spread of Systemd, a different kind of availability was born.

http://supervisord.org/

First, let's install Supervisor.

sudo apt install supervisor

Since a config file will be created in /etc/supervisor, we will create a file named mastodon.conf this time and write the following syntax.

[group:mastodon]
programs=web,sidekiq,streaming

[program:web]
command=/usr/local/bin/bundle exec puma -C config/puma.rb
user=mastodon
directory=/home/sns/mastodon
stdout_logfile=/home/sns/mastodon/log/puma.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
redirect_stderr=true
environment=RAILS_ENV=production,PORT=3000,LD_PRELOAD=libjemalloc.so
stopasgroup=true

[program:sidekiq]
command=/usr/local/bin/bundle exec sidekiq -c 25
user=mastodon
directory=/home/sns/mastodon
stdout_logfile=/home/sns/mastodon/log/sidekiq.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
redirect_stderr=true
environment=RAILS_ENV=production,DB_POOL=25,MALLOC_ARENA_MAX=2,LD_PRELOAD=libjemalloc.so
stopasgroup=true

[program:streaming]
command=/usr/bin/node ./streaming
user=mastodon
directory=/home/sns/mastodon
stdout_logfile=/home/sns/mastodon/log/streaming.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
redirect_stderr=true
environment=NODE_ENV=production,PORT=4000,STREAMING_CLUSTER_NUM=1
stopasgroup=true

Sections that may require changes are highlighted.

Please change each daemon to the appropriate directory, etc.

After that, everything should start with `supervisorctl start all`.
Don't forget to `restart all` if you make changes to Mastodon files.

Finally, configure Apache or Nginx to refer to the Mastodon directory.

End.

References

These are easy-to-understand guides for Mastodon installation:
https://zenn.dev/hashito/articles/caa579a9aa8b4f
https://vpslife.server-memo.net/mastodon_install/

The Supervisor syntax written here didn't work as-is, so I tried changing it to a more modern (2023...) version.

Alternative Server Components

Finally

I was trying to change these daemon files for SysVinit, but I gave up.
Then, when I looked into the daemon files of Systemd-Free Artix, I found the string "Supervisor," which led me to this solution.

Considering that Supervisor can essentially replace any daemon file, how convenient it is...
Moreover, as in this case, all three daemon files can be managed by just one, making it incredibly easy and convenient to start and stop multiple processes with Supervisor when creating software or services that manage many processes.

That's all!

Related Posts