Rocket Chat startup script

Posted on 12-01-2017 by Nadir Latif


The following script can be used to run an instance of Rocket Chat:


if [ $(ps -e -o uid,cmd | grep $USER | grep rocketchat | grep -v grep | wc -l | tr -s "\n") -eq 0 ]
        export PATH=/usr/local/bin:$PATH
        export MONGO_OPLOG_URL=mongodb://localhost:27017/local
        export ROOT_URL=http://your-domain/
        export MONGO_URL=mongodb://localhost:27017/your-database
        export PORT=1000
        export MAIL_URL=smtp://
        /root/.nvm/versions/node/v4.5.0/bin/forever start --minUptime 1000 --spinSleepTime 10000 --sourceDir path-to-rocket-chat main.js -l /var/log/forever.log -o /var/log/forever-out.log -e /var/log/forever-err.log

The above command checks if an instance of Rocket Chat is already running. If it is not running, then the Rocket Chat is run using the forever command. The forever command ensures that the Rocket Chat keeps running. It restarts the Rocket Chat automatically in case it stops. The forever script can be installed with the command: npm install forever. The above script may be run when the system boots up using the following cron job command: @reboot /root/scripts/ > /dev/null 2>&1