pm2 script execution path is incorrect, doesn't match the one in ecosystem.config.js
Asked Answered
S

2

8

My ecosystem.config.js looks like this:

module.exports = {
apps: [{
    name: 'production',
    script: '/home/username/sites/Website/source/server.js',
    env: { NODE_ENV: 'PRODUCTION' },
    args: '--run-server'
}, {
    name: 'staging',
    script: '/home/username/sites/WebsiteStaging/source/server.js',
    env: { NODE_ENV: 'STAGING' },
    args: '--run-server'
}],
deploy: {
    production: {
        user: 'username',
        host: ['XXX.XXX.XX.XXX'],
        ref: 'origin/production',
        repo: '[email protected]:ghuser/Website.git',
        path: '/home/username/sites/Website',
        'post-deploy': 'npm install && pm2 reload ecosystem.config.js --only production',
        env: { NODE_ENV: 'PRODUCTION' }
    },
    staging: {
        user: 'username',
        host: ['XXX.XXX.XX.XXX'],
        ref: 'origin/staging',
        repo: '[email protected]:ghuser/Website.git',
        path: '/home/username/sites/WebsiteStaging',
        'post-deploy': 'npm install && pm2 reload ecosystem.config.js --only staging',
        env: { NODE_ENV: 'STAGING' }
    }
}
};

When I deploy the application, I expect to see two processes - one called 'production' and one called 'staging'. These run code from the same repo, but from different branches.

I do see two processes, however, when I run pm2 desc production I can see that the script path is /home/username/sites/WebsiteStaging/source/server.js. This path should be /home/username/sites/Website/source/server.js as per the config file.

I've tried setting the script to ./server.js and using the cwd parameter but the result has been the same.

The deploy commands I am using are pm2 deploy production and pm2 deploy staging and I have verified that both the Website and the WebsiteStaging folders are present on my server.

Is there something I'm missing here? Why would it be defaulting to the staging folder like this?

Sennight answered 23/11, 2018 at 6:32 Comment(1)
On the staging server when you do pm2 desc staging what do you get?Henhouse
J
2

What worked for me was to delete the pm2 application and start it.

  1. pm2 delete production
  2. pm2 start production

When I ran pm2 desc production, I saw that the script path was incorrect, and nothing I did seemed to correct that path, short of the above.

Jotun answered 10/12, 2020 at 19:12 Comment(0)
C
0

I had the same issue. Seems it happend due to old dump.pm2 that was not updated after changes to ecosystem.config.js were made.

Updating the startup script solved the issue

pm2 save
pm2 unstartup
pm2 startup

Cleres answered 17/1, 2021 at 8:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.