2

I'm using a Jelastic Node.js PM2 environment and I want my app to be started with something like the following:

pm2 start npm --name "app name" -- start

(my server is not a JS file).

The command runs fine if I use a Jelastic 'npm' environment, but I'd rather have the benefits of PM2. I tried setting various APP_FILE (start, npm start, a pm2 config file path), Entry Points and PROCESS_MANAGER_FILE, without success. I usually get this error:

Node ID : 53209
-----------------------
result 1 Failed to start 
Stopping nodejs server[  OK  ] Starting nodejs server [FAILED]
now
  • 4,772
  • 2
  • 24
  • 26
  • You may try achieving it through an ecosystem file as in the following manual: https://pm2.keymetrics.io/docs/usage/application-declaration/ . Based on the manual, it is required to create a file and specify the executable command in 'script'. After, you will need to specify the path to this configuration in the PROCESS_MANAGER_FILE variable. Please notice that this config should be readable by the Jelastic user. – Virtuozzo Jan 25 '21 at 07:54
  • Thank you @Jelastic, that was correct. I just used `APP_FILE` instead of `PROCESS_MANAGER_FILE` – now Feb 23 '21 at 13:04

1 Answers1

2

The comment from @Jelastic worked! Indeed using a PM2 'ecosystem file' works in Jelastic.

Set APP_FILE (or possibly PROCESS_MANAGER_FILE) to ecosystem.config.js (This is relative to ROOT_DIR)

The content of this file should look something like this:

module.exports = {
  apps: [
    {
      script: "yarn",
      args: "--cwd myserver1 start",
      name: "myserver1",
    },
    // You can use this setup to start multiple processes too.
    {
      script: "yarn",
      args: "--cwd myserver2 start",
      name: "myserver2",
    },
  ],
};

--cwd tells yarn to switch the Current Working Directory. If you use npm, you can use --prefix instead.

Read more about PM2 ecoystem files: https://pm2.keymetrics.io/docs/usage/application-declaration/

now
  • 4,772
  • 2
  • 24
  • 26