How to use systemd to run the mattermost chat platform.

mattermost-slack
Standard

A lot of us have waited for a alternative to slack which respects our privacy. This is an important topic for privates as well as corporate entities.

Finally the Mattermost Team have released their first stable release and that means that they are comfortable enough with the project to market it for production.

screenshot mattermost blog

If you would like to have a look at mattermost without having to set up all the production environment, have a look at their dockerized solution. It’s perfect for just spinning it up and tweaking it a little.

Setup with systemd

If you are like me and love cutting edge or just systemd per se, you’ll find that systems running on systemd are not officially supported yet.

When looking at why it is not supported yet, we’ll find out that that the devs might not have had time yet to test it or do not have experience in systemd.
In my tests, I could not find any problems running mattermost on systemd and because of that, here is a little guide:

All we need is to write a systemd.unit file.

  1. Install Mattermost and try making it run with command line only.
  2. Create a mattermost.service file in /etc/systemd/system.
  3. Fill in the following and adjust to your needs.
[Unit]
Description=mattermost
After=multi-user.target

[Service]
User=mattermost
WorkingDirectory=/var/www
ExecStart=/var/www/bin/platform
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

As you can see we have 3 segments.

First one is [Unit], where we tell systemd how the service is named and when it should be executed.
It will execute right after multi-user.target (which is quite “the equivalent” to runlevel 6).

Then we have the [Service] block, where we define everything that is directly related to the service itself.

  • User=”the user this service/daemon will run on/from”
  • WorkingDirectory=”the directory from where the execution will take place”
  • ExecStart=”the executable that will run”
  • Restart=”whatever happens, systemd will restart this service automatically”
  • RestartSec=”wait 10 seconds before restart”

The last piece is [Install], which is necessary for letting this unit be recognized as a service.