Skip to content

Running VerneMQ as a systemd service

ioolkos edited this page Nov 16, 2017 · 2 revisions

Using VerneMQ with systemd

VerneMQ can be automatically restarted with the Erlang heart command. This might not be for the faint of heart (the usual joke here), and if you're used to configure services with systemd, you can do the same thing for VerneMQ. You'll go through the following steps to setup and start VerneMQ:

1. Create a systemd Unit file:

On my system (Ubuntu) the Unit files go under: /etc/systemd/system/

Create a file called vernemq.service with the following contents:

[Unit]
Description=Runner for VerneMQ
After=network.target

[Service]
WorkingDirectory=/usr/lib/vernemq
ExecStart=/usr/sbin/vernemq start
ExecStop=/usr/sbin/vernemq stop
User=vernemq
Type=forking
Restart=always
RestartSec=45
LimitNOFILE=300000

[Install]
WantedBy=multi-user.target

If you want to understand those configs a little better or adapt them, here's your starting point: https://github.com/systemd/systemd

2. Daemon-Reload systemd

sudo systemctl daemon-reload to let systemd know about the new VerneMQ service.

3. Enable and start the VerneMQ service

sudo systemctl enable vernemq.service (or sudo systemctl enable vernemq)

sudo systemctl start vernemq.service (or sudo systemctl start vernemq)

Check the VerneMQ service status with: sudo systemctl status vernemq

Now go find the VerneMQ process and kill it on your command line. Verify that systemd will restart VerneMQ within the time frame you have given with RestartSec.

4. How to configure OS limits:

An important note: systemd does not respect your OS settings configured with sysctl (not systemctl ;). This is why I added the LimitNOFILE=300000 line to my vernemq.service file. Apparently this is not the recommended way to go though. It's recommended that you create an override.conf file in a vernemq.service.d subdirectory and add the additional configs there. This did not work on my system on first try. You can create the subdirectory and edit file automatically by the following command:

sudo systemctl edit vernemq.service

This will create the /etc/systemd/system/vernemq.service.d directory and an override.conf file in it.

I am no expert on systemd and I welcome any improvements and additional information!

You can’t perform that action at this time.