systemd
Deploy Rocket.Chat to Linux that run on systemd

Prerequisite

You need to have docker installed.

How to run Rocket.Chat on systemd

  1. 1.
    Create a docker network docker network create rocketchat_default
  2. 2.
    Create two service files: mongo.service and rocketchat.service
  3. 3.
    Enable the service files
  4. 4.
    Run the mongo.service
  5. 5.
    Create the mongo-init-replica to enable opolog
  6. 6.
    Run the rocketchat.service
If you reboot the server, the services will start automatically in the right order.

Service Files

mongo.service:
1
[Unit]
2
Description=mongo
3
Requires=docker.service
4
After=docker.service
5
6
[Service]
7
EnvironmentFile=/etc/environment
8
User=dockeruser
9
Restart=always
10
TimeoutStartSec=0
11
ExecStartPre=-/usr/bin/docker kill mongo
12
ExecStartPre=-/usr/bin/docker rm mongo
13
ExecStartPre=-/usr/bin/docker pull mongo:3.2
14
15
16
ExecStart=/usr/bin/docker run \
17
--name mongo \
18
-v .../path/to/data/db:/data/db \
19
-v .../path/to/data/dump:/data/dump \ <--optional
20
--net=rocketchat_default \
21
mongo:3.2 \
22
mongod --smallfiles --oplogSize 128 --replSet rs0 --storageEngine=mmapv1
23
24
ExecStop=-/usr/bin/docker kill mongo
25
ExecStop=-/usr/bin/docker rm mongo
Copied!
rocketchat.service:
1
[Unit]
2
Description=rocketchat
3
Requires=docker.service
4
Requires=mongo.service
5
After=docker.service
6
After=mongo.service
7
8
[Service]
9
EnvironmentFile=/etc/environment
10
User=dockeruser
11
Restart=always
12
TimeoutStartSec=0
13
ExecStartPre=-/usr/bin/docker kill rocketchat
14
ExecStartPre=-/usr/bin/docker rm rocketchat
15
ExecStartPre=-/usr/bin/docker pull registry.rocket.chat/rocketchat/rocket.chat:latest
16
17
ExecStart=/usr/bin/docker run \
18
--name rocketchat \
19
-v .../path/to/uploads:/app/uploads \
20
-e MONGO_OPLOG_URL=mongodb://mongo:27017/local \
21
-e MONGO_URL=mongodb://mongo:27017/rocketchat \
22
-e ROOT_URL=https://sub.domain.xx \
23
--link mongo:mongo \
24
--net=rocketchat_default \
25
--expose 3000 \
26
registry.rocket.chat/rocketchat/rocket.chat:latest
27
28
ExecStop=-/usr/bin/docker kill rocketchat
29
ExecStop=-/usr/bin/docker rm rocketchat
Copied!

Build the mongo-init-replica container (only run once)

Execute:
1
docker run \
2
--name mongo-init-replica \
3
--link mongo:mongo \
4
--rm \
5
--net=rocketchat_default \
6
mongo:3.2 \
7
mongo mongo/rocketchat --eval "rs.initiate({ _id: 'rs0', members: [ { _id: 0, host: 'localhost:27017' } ]})"
Copied!

Reverse Proxy

If you are running a reverse proxy make sure it is joining the rocketchat_default network. Add ExecStartPre=-/usr/bin/docker network connect rocketchat_default Nginx to the rocketchat.service if you Proxy container is named Nginx and be sure to configure it correctly.
If you choose to use a non-dockerized nginx as a reverse proxy, please not that you then have to add -p your-host-port:3000 to the ExecStart command of rocketchat.service and then configure your vhost to pass to your-host-port.

Backup

All data will be hourly backed up to /data/domains/example.org/data folder. We advise to copy this folder to a remote location in case of hardware failure.

Questions

If you have any questions, don't hesitate to open issues.