Rocket.Chat

Rocket.Chat is an self hosted, open source chat software written in JavaScript.


Note

For this guide you should be familiar with the basic concepts of

License

All relevant legal information can be found here

Prerequisites

We’re using Node.js in the stable version 12:

[isabell@stardust ~]$ uberspace tools version show node
Using 'Node.js' version: '12'
[isabell@stardust ~]$

We’ll also need MongoDB, so follow the MongoDB guide and come back when it’s running.

Check your chat URL setup:

[isabell@stardust ~]$ uberspace web domain list
isabell.uber.space
[isabell@stardust ~]$

Installation

Download the latest Rocket.Chat release:

[isabell@stardust ~]$ curl -L https://releases.rocket.chat/latest/download -o ~/rocket.chat.tgz
curl -L https://releases.rocket.chat/latest/download -o rocket.chat.tgz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   223  100   223    0     0    333      0 --:--:-- --:--:-- --:--:--   333
100  146M  100  146M    0     0  13.0M      0  0:00:11  0:00:11 --:--:-- 14.0M
[isabell@stardust ~]$

And then extract the archive, use --strip-components=1 to remove the bundle prefix from the path:

[isabell@stardust ~]$ mkdir ~/rocket.chat
[isabell@stardust ~]$ tar -xzf ~/rocket.chat.tgz -C ~/rocket.chat --strip-components=1
[isabell@stardust ~]$

You can delete the archive now:

[isabell@stardust ~]$ rm ~/rocket.chat.tgz
[isabell@stardust ~]$

Now we install the required dependencies:

[isabell@stardust ~]$ cd ~/rocket.chat/programs/server
[isabell@stardust server]$ npm install
[...]
very long npm chatter
[...]
[isabell@stardust server]$ cd ~
[isabell@stardust ~]$

As long as this issue in Rocket.Chat is not fixed, we need a little modification to get file uploads to work.

Make ~/rocket.chat/programs/server/packages/jalik_ufs.js writable:

[isabell@stardust ~]$ chmod +w ~/rocket.chat/programs/server/packages/jalik_ufs.js
[isabell@stardust ~]$

Edit ~/rocket.chat/programs/server/packages/jalik_ufs.js and replace the line tmpDir: '/tmp/ufs', with tmpDir: process.env.HOME+'/tmp/ufs',.

Remove the write permission:

[isabell@stardust ~]$ chmod -w ~/rocket.chat/programs/server/packages/jalik_ufs.js
[isabell@stardust ~]$

Note

Alternatively you can do this in one step with sed:

[isabell@stardust ~]$ sed -i "s#tmpDir: '/tmp/ufs',#tmpDir: process\.env\.HOME+'/tmp/ufs',#g" ~/rocket.chat/programs/server/packages/jalik_ufs.js
[isabell@stardust ~]$

Configuration

Configure MongoDB

First stop MongoDB

[isabell@stardust ~]$ supervisorctl stop mongodb
mongodb: stopped
[isabell@stardust ~]$

Update the daemon configuration file ~/etc/services.d/mongodb.ini, add the option --replSet rs01:

[program:mongodb]
command=mongod
  --dbpath %(ENV_HOME)s/mongodb
  --bind_ip 127.0.0.1
  --auth
  --unixSocketPrefix %(ENV_HOME)s/mongodb
  --replSet rs01
startsecs=60
autostart=yes
autorestart=yes

This is required because Rocket.Chat uses Meteor Oplog Tailing for performance improvements (see the docs for further information).

Then tell supervisord to update and start the service:

[isabell@stardust ~]$ supervisorctl reread
mongodb: changed
[isabell@stardust ~]$ supervisorctl update
mongodb: stopped
mongodb: updated process group
[isabell@stardust ~]$

Now initiate the replica set:

[isabell@stardust ~]$ mongo --username ${USER}_mongoroot --eval "printjson(rs.initiate())"
MongoDB shell version v4.2.3
Enter password:
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("d0f22c61-382c-4178-9a6d-09b42674c14d") }
MongoDB server version: 4.2.3
{
       "info2" : "no configuration specified. Using a default configuration for the set",
       "me" : "127.0.0.1:27017",
       "ok" : 1
}
[isabell@stardust ~]$

Note

You don’t need to add --username if you have stored your credentials in the ~/.mongorc.js file.

As last part of the MongoDB configuration we need a user for Rocket.Chat. Generate a random password:

[isabell@stardust ~]$ < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-15};echo;
randompassword
[isabell@stardust ~]$

Create ~/rocket.chat-user-setup.js with the following content:

db.createUser(
   {
     user: "<username>_rocketchat",
     pwd: "<password>",
     roles: [
       {role:"dbOwner", db:"rocketchat"},
       {role:"readWrite", db:"local"},
       {role:"clusterMonitor", db:"admin"}
     ]
   }
)

Replace <username> with your username and <password> with the generated password.

Use mongo to add the user:

[isabell@stardust ~]$ mongo admin --username ${USER}_mongoroot ~/rocket.chat-user-setup.js
MongoDB shell version v4.2.3
Enter password:
connecting to: mongodb://127.0.0.1:27017/admin?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("de28d438-1b38-4c59-964b-8a2f7f88d2d9") }
MongoDB server version: 4.2.3
Successfully added user: {
        "user" : "isabell_rocketchat",
        "roles" : [
               {
                       "role" : "dbOwner",
                       "db" : "rocketchat"
               },
               {
                       "role" : "readWrite",
                       "db" : "local"
               },
               {
                       "role" : "clusterMonitor",
                       "db" : "admin"
               }
       ]
}
[isabell@stardust ~]$

Note

You don’t need to add --username if you have stored your credentials in the ~/.mongorc.js file.

Remove the ~/rocket.chat-user-setup.js file:

[isabell@stardust ~]$ rm ~/rocket.chat-user-setup.js
[isabell@stardust ~]$

Configure Webserver

Note

Rocket.Chat is running on port 3000 by default. You’ll set this in the daemon setup.

To make the application accessible from the outside, configure a web backend:

[isabell@stardust ~]$ uberspace web backend set / --http --port <port>
Set backend for / to port <port>; please make sure something is listening!
You can always check the status of your backend using "uberspace web backend list".
[isabell@stardust ~]$

Setup daemon

Create ~/etc/services.d/rocket.chat.ini with the following content:

[program:rocket.chat]
command=node %(ENV_HOME)s/rocket.chat/main.js
environment=
       MONGO_URL="mongodb://%(ENV_USER)s_rocketchat:<password>@localhost:27017/rocketchat?replicaSet=rs01&authSource=admin",
       MONGO_OPLOG_URL="mongodb://%(ENV_USER)s_rocketchat:<password>@localhost:27017/local?replicaSet=rs01&authSource=admin",
       ROOT_URL="https://%(ENV_USER)s.uber.space/",
       PORT=3000
autostart=yes
autorestart=yes

Note

Don’t forget to replace all occurrences of <password> and to set your ROOT_URL if you don’t use your default uberspace domain!

Now let’s start the service:

After creating the configuration, tell supervisord to refresh its configuration and start the service:

[isabell@stardust ~]$ supervisorctl reread
SERVICE: available
[isabell@stardust ~]$ supervisorctl update
SERVICE: added process group
[isabell@stardust ~]$ supervisorctl status
SERVICE                            RUNNING   pid 26020, uptime 0:03:14
[isabell@stardust ~]$

Finishing installation

Point your browser to the domain you’ve configured in the daemon ini file (ROOT_URL) and follow the setup assistant.

See the Administrator Guides for further configuration options.

Note

it may take a minute or so until Rocket.Chat is fully loaded, so don’t worry if you see a 502 bad gateway for a while after starting Rocket.Chat

Updates

Stop Rocket.Chat:

[isabell@stardust ~]$ supervisorctl stop rocket.chat
rocket.chat: stopped
[isabell@stardust ~]$

Remove the old installation:

[isabell@stardust ~]$ rm -rf ~/rocket.chat
[isabell@stardust ~]$

Follow the Installation procedure to install the new release.

Start Rocket.Chat again after the installation is finished:

[isabell@stardust ~]$ supervisorctl start rocket.chat
rocket.chat: started
[isabell@stardust ~]$

Note

it may take a minute or so until Rocket.Chat is fully loaded, so don’t worry if you see a 502 bad gateway for a while after starting Rocket.Chat

Note

Check the Rocket.Chat releases page regularly to stay informed about the newest version.


Tested with Rocket.Chat 3.0.4, Uberspace 7.4.4.0

Written by: Dustin Skoracki <https://github.com/d-sko>