[HOW TO] RocketChat on boot with systemctl

I installed RocketChat with manual instalation on Ubuntu Server.
It works fine few days and than RocketChat stopped to boot in autorun.

During installation I created System init
/etc/systemd/system/rocketchat.service

[Unit]
Description=Rocket.Chat server
After=network.target nss-lookup.target mongod.target

[Service]
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=rocketchat
User=rocket
Environment=MONGO_URL=mongodb://localhost:27017/rocketchat ROOT_URL=https://xxxDOMAINxxx PORT=3000
ExecStart=/usr/local/bin/node /opt/rocket/Rocket.Chat/main.js

[Install]
WantedBy=multi-user.target

and added to systemctl as a service to boot on autostart

sudo systemctl daemon-reload
sudo systemctl start rocketchat
sudo systemctl status rocketchat
sudo systemctl enable rocketchat

So, for some reason it worked few days and than something happened and systemctl did not run rocketchat.
System init was active, but did’t start on boot.
Also it started manually with:
sudo systemctl start rocketchat

So I danced with systemctl 2 days and finally found out a solution!
I added one line to /etc/systemd/system/rocketchat.service
ExecStartPre=/bin/sleep 20

And now this System init succesfully boot rocketchat on autostart!

[Unit]
Description=Rocket.Chat server
After=network.target nss-lookup.target mongod.target

[Service]
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=rocketchat
User=rocket
Environment=MONGO_URL=mongodb://localhost:27017/rocketchat ROOT_URL=https://xxxDOMAINxxx PORT=3000
ExecStartPre=/bin/sleep 20
ExecStart=/usr/local/bin/node /opt/rocket/Rocket.Chat/main.js

[Install]
WantedBy=multi-user.target
1 Like

Thank you! This help me a lot!