Rocket.Chat

Updated 4 August 2020

Rocket.Chat

Introduction

Rocket.Chat is an open source messenger that provides support for group chats, data exchange, videoconferencing, bot and much more.

Creating LXC container

We recommend that you install Rocket.Chat in a separate container, to be configured according to the manual.

Installing and configuring MongoDB

Install MongoDB:

emerge -a dev-db/mongodb

Configure MongoDB for it to handle Rocket.Chat:

/etc/mongodb.conf
storage:
  dbPath: "/var/lib/mongodb"
  engine: mmapv1

replication:
  replSetName: rs01

Now start MongoDB:

/etc/init.d/mongodb start

And add it to autostart:

rc-update add mongodb

Initialize the database

mongo --eval "printjson(rs.initiate())"

Getting Let's Encrypt certificate

Get the Nginx domain certificate for rocketchat.example.org, as described in the manual.

Installing and configuring Nginx

Install and configure the Nginx Web server as a reverse proxy, as described in the manual. Add the following setting for rocketchat.example.org:

/etc/nginx/sites-enabled/rocketchat.conf
server {
    listen 443 ssl;
    server_name rocketchat.example.org;

    include ssl.conf;
    ssl_certificate /etc/nginx/ssl/rocketchat.example.org/fullchain.pem;
    ssl_certificate_key /etc/nginx/ssl/rocketchat.example.org/privkey.pem;
    client_max_body_size 200M;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $http_host;

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Nginx-Proxy true;

        proxy_redirect off;
    }
}

Installing and configuring Rocket.Chat

First install accessory software:

emerge -a dev-python/nodeenv media-gfx/graphicsmagick

Create a system user called rocketchat:

useradd -m -d /var/calculate/www/rocketchat -s /bin/bash rocketchat

Install Node.js to the user directory:

su - rocketchat

nodeenv --node=12.18.0 .node-12

ln -sfT .node-12 .node-live

source .node-live/bin/activate

echo 'source ~/.node-live/bin/activate' >> ~/.bash_profile

Install the server

Using the release server

Download and unpack Rocket.Chat:

curl -L https://releases.rocket.chat/latest/download -o Rocket.Chat.tar.gz

tar xf Rocket.Chat.tar.gz

Install all necessary libraries for NodeJS and quit as rocketchat:

cd ~/bundle/programs/server

npm install && exit

Building a server from source code

Install the Meteor framework for the 'web' user:

curl https://install.meteor.com/ | sh

echo 'PATH="${PATH}:${HOME}/.meteor"' >>.bash_profile

PATH="${PATH}:${HOME}/.meteor"

Fetch the source for your future Rocket.Chat server:

git clone https://github.com/RocketChat/Rocket.Chat.git Rocket.Chat.Source

Go to the source directory and build the archive:

cd Rocket.Chat.Source

meteor npm install

meteor build --directory ~

Install all necessary libraries for NodeJS and quit as rocketchat:

cd ~/bundle/programs/server

npm install && exit

Running Rocket.Chat

Make the previously obtained Rocket.Chat directory the current one:

mv /var/calculate/www/rocketchat/{bundle,Rocket.Chat}

Create an OpenRC script to control Rocket.Chat by specifying https://rocketchat.example.org as ROOT_URL:

/etc/init.d/rocketchat
#!/sbin/openrc-run
# Copyright 2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

name="Rocketchat daemon"
description=""
pidfile=/run/rocketchat.pid
command_user=rocketchat
output_log=/var/log/rocketchat.log
error_log=/var/log/rocketchat.log
directory=/var/calculate/www/rocketchat/Rocket.Chat
ROOT_URL="https://rocketchat.example.org"
start_stop_daemon_args="-e ROOT_URL=$ROOT_URL -e MONGO_OPLOG_URL=mongodb://localhost:27017/local?replicaSet=rs01 -e PORT=3000 -e MONGO_URL=mongodb://localhost:27017/rocketchat?replicaSet=rs01 -e PATH=/var/calculate/www/rocketchat/.node-live/lib/node_modules/.bin:/var/calculate/www/rocketchat/.node-live/bin:\"$PATH\""
command="/var/calculate/www/rocketchat/.node-live/bin/node"
command_args="main.js"
command_background=true

depend() {
        need nginx mongodb
}

start_pre() {
    checkpath -f -o rocketchat -m 0600 /var/log/rocketchat.log
}

Set the privileges:

chmod 755 /etc/init.d/rocketchat

Launch the Rocket.Chat daemon:

/etc/init.d/rocketchat start

Add Rocket.Chat to autostart:

rc-update add rocketchat

Go to page https://rocketchat.example.org in your Internet browser to complete your Rocket.Chat configuration.

Rocket.Chat update

Log in as rocketchat:

su - rocketchat

Get the bundle directory for Rocket.Chat. Several ways to do this are described above in the Server installation section.

Stop the old Rocket.Chat server:

/etc/init.d/rocketchat stop

Replace the old server with the later one:

mv /var/calculate/www/rocketchat/Rocket.Chat{,.$(date +%Y%m%d%H%M)}

mv /var/calculate/www/rocketchat/{bundle,Rocket.Chat}

Start the new Rocket.Chat server:

/etc/init.d/rocketchat start