PM2 is a process manager for nodejs applications. Documentation can be found here.

StageR provides a default pm2.json file to run StageR in clusterMode (2 REST API processes, 2 replication processes and 4 reprocessing processes).

Install PM2

Install PM2
npm install pm2 -g

Configure StageR for PM2

PM2 will manage all processes for StageR (instead of starting them using the server.js script). PM2 will register the processes for clusterMode without explicitly setting them up in the config files.

Note: Make sure your configuration has clusterMode: false before launching StageR with PM2.

pm2.json

{
    "apps": [
        {
            "name": "reprocess-app",
            "script": "./app/jobs/reprocess.server.job.js",
            "watch": false,
            "instances": 4,
            "kill_timeout": 60000,
            "env": {
                "NODE_ENV": "development"
            }
        },
        {
            "name": "replication-app",
            "script": "./app/jobs/replication.server.job.js",
            "watch": false,
            "instances": 2,
            "kill_timeout": 60000,
            "env": {
                "NODE_ENV": "development"
            }
        },
        {
            "name": "restapi-app",
            "script": "./app/jobs/restapi.server.job.js",
            "instances": 2,
            "watch": false,
            "kill_timeout": 60000,
            "env": {
                "NODE_ENV": "development"
            }
        }
    ]
}

The default pm2.json file defines a section for each type of process that StageR runs: reprocess, replication and restapi. 

  • name: The name of the process in pm2.
  • script: The script to execute.
  • instances: the number of processes to execute for this script (launches the scripts in cluster mode).
  • watch: boolean, if true, automatically restarts the service if a file changes
  • kill_timeout: ms to wait if the application is not responding.
  • env: list of environment variables to use with this script.

Start StageR with PM2

cd stager-home
npm install --production
pm2 start pm2.json





  • No labels