Setting up Process Managers and Init Systems

PM2

Systemd

Deploy Rocket.Chat to Linux that run on systemd (RedHat, Centos, Ubuntu, CoreOS and so on).

How to run Rocket.Chat on systemd.

First we need to create the unit file.
vi /etc/systemd/system/rocketchat.service
With the contents:
1
[Unit]
2
Description=RocketChat Server
3
After=network.target remote-fs.target nss-lookup.target mongod.target nginx.target # Remove or Replace nginx with your proxy
4
5
[Service]
6
ExecStart=/usr/local/bin/node /var/www/rocketchat/main.js # Specify the location of node and location of main.js
7
Restart=always # If set to always, the service will be restarted regardless of whether it exited cleanly or not, got terminated abnormally by a signal, or hit a timeout.
8
RestartSec=10 # Restart service after 10 seconds if node service crashes
9
StandardOutput=syslog # Output to syslog
10
StandardError=syslog # Output to syslog
11
SyslogIdentifier=nodejs-example
12
#User=<alternate user>
13
#Group=<alternate group>
14
Environment=NODE_ENV=production PORT=3000 ROOT_URL=https://rocketchat.domain.com MONGO_URL=mongodb://localhost:27017/rocketchat
15
16
[Install]
17
WantedBy=multi-user.target
Copied!
Then you need to enable the service systemctl enable rocketchat.service
To start the service systemctl start rocketchat.service
To verify it is running systemctl status rocketchat.service

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.

Upstart - Ubuntu

Note: Upstart is no longer supported. We no longer support Ubuntu 14.04. If upgrading please see systemd or Ubuntu 16.04
The following examples are upstart jobs which control automatic start-up and, if necessary, respawning of your Rocket.Chat app, as well as management of an optional hubot chat-bot.
In order to use the examples, simply copy each example and save into a file, paying attention to the fact that the filenames should be preserved unless you edit the examples to reflect any filename changes you make. Be sure to edit the environment variables, and possibly paths, according to your particular installation. Once you've saved the files to the proper directory (/etc/init) usage is as simple as rebooting.
Which upstart management jobs that you use depend on what type of Rocket.Chat deployment you are using (Docker-compose, non-docker, etc). A race-condition exists with docker-compose which requires that mongo and the Rocket.Chat application be started independently, thus a slightly modified upstart job is required compared to non-docker instances.

Non-Docker-Compose

Save as: /etc/init/rocketchat.conf
1
description "rocketchat application server"
2
3
# Wait for mongod before starting rocketchat app
4
start on (started mongod)
5
stop on runlevel [!2345]
6
7
# Automatically attempt to restart with finite limits
8
respawn
9
respawn limit 99 5
10
11
# Export necessary variables and start the Applications / Services
12
script
13
export MONGO_URL=mongodb://localhost:27017/rocketchat
14
export ROOT_URL=https://host.yourdomain.tld
15
export PORT=3000
16
exec /usr/local/bin/node /home/administrator/Rocket.Chat/main.js
17
end script
Copied!
Save as: /etc/init/rocketchat_hubot.conf
1
description "hubot launcher"
2
3
# Wait for the rocketchat upstart job before starting hubot
4
start on started rocketchat
5
stop on runlevel [!2345]
6
7
# Automatically Respawn with finite limits
8
respawn
9
respawn limit 99 5
10
11
script
12
# Wait until Rocket.Chat is up and listening to port tcp 3000
13
until nc -z localhost 3000; do
14
sleep 1
15
done
16
17
# Export necessary variables
18
export ROCKETCHAT_ROOM=GENERAL
19
export ROCKETCHAT_USER=bot_username
20
export ROCKETCHAT_PASSWORD=bot_password
21
22
# Change to the hubot directory
23
cd /home/administrator/myhubot
24
25
# Launch Hubot
26
exec bin/hubot -a rocketchat
27
end script
Copied!

Docker-Compose

Save as: /etc/init/rocketchat_mongo.conf
1
description "MongoDB service manager for rocketchat"
2
3
# Start MongoDB after docker is running
4
start on (started docker)
5
stop on runlevel [!2345]
6
7
# Automatically Respawn with finite limits
8
respawn
9
respawn limit 99 5
10
11
# Path to our app
12
chdir /var/www/rocket.chat
13
14
script
15
# start mongoDB
16
exec /usr/local/bin/docker-compose up db
17
end script
Copied!
Save as: /etc/init/rocketchat_app.conf
1
description "Rocketchat service manager"
2
3
# Start Rocketchat after mongo upstart job is running
4
start on (started rocketchat_mongo)
5
stop on runlevel [!2345]
6
7
# Automatically Respawn with finite limits
8
respawn
9
respawn limit 99 5
10
11
# Path to our app
12
chdir /var/www/rocket.chat
13
14
script
15
# Bring up rocketchat app and hubot
16
exec /usr/local/bin/docker-compose up rocketchat hubot
17
end script
Copied!
Last modified 1yr ago