Usage and configuration of PM2

If your want to control your services, you will learn here how to configure them using PM2 (a process manager which can be utilized to run and manage nodes.js applications) and how to check the service status of your PM2-managed services.


Configure services managed by PM2

To manage your services with PM2 on the root360 platform, you must create an ecosystem file and specify exec_mode: ‘cluster’. See below for a sample adapted from the PM2 documentation:

1 2 3 4 5 6 7 8 9 module.exports = { apps : [{ exec_mode: 'cluster', name: "app", script: "./app.js", env: { NODE_ENV: "development" }, env_production: { NODE_ENV: "production" } }] }

Please tell us the name of that file in your deployment directory (the destination in the file system of the instance where you as the customer place your application).

We will then create configuration to start PM2 with that ecosystem file. You are free to change the content of the ecosystem file and redeploy as long as you keep exec_mode: ‘cluster’ included.

If exec_mode: 'cluster' is not included in your ecosystem file and you deploy a new version of your service our configuration management would not be able to find the processes of the previous version of PM2 and its services and your new services would fail to run.

Check status of services using PM2 list

The linux user www-data with which we are running your PM2 services does not have a home directory (for more information see ).

To still be able to use pm2 list you need to explicitly set PM2_HOME and call PM2 using www-data. See the example below using the example role web, executed on an application instance where your PM2 services are running:

1 2 3 4 5 6 7 role=web sudo -u www-data -H PM2_HOME="/srv/home_${role}/.pm2/" pm2 list ┌─────┬─────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐ │ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │ ├─────┼─────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤ │ 0 │ web │ default │ 1.37.0 │ cluster │ 23570 │ 5D │ 0 │ online │ 1.2% │ 87.0mb │ www-data │ disabled │ └─────┴─────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘


Related tutorials

Related components